summaryrefslogtreecommitdiff
path: root/Lib/test/test_property.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_property.py')
-rw-r--r--Lib/test/test_property.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/Lib/test/test_property.py b/Lib/test/test_property.py
index 172737ade1..7f3813fc8c 100644
--- a/Lib/test/test_property.py
+++ b/Lib/test/test_property.py
@@ -204,6 +204,16 @@ class PropertyTests(unittest.TestCase):
return 'Second'
self.assertEqual(A.__doc__, 'Second')
+ def test_property_set_name_incorrect_args(self):
+ p = property()
+
+ for i in (0, 1, 3):
+ with self.assertRaisesRegex(
+ TypeError,
+ fr'^__set_name__\(\) takes 2 positional arguments but {i} were given$'
+ ):
+ p.__set_name__(*([0] * i))
+
# Issue 5890: subclasses of property do not preserve method __doc__ strings
class PropertySub(property):
@@ -299,6 +309,46 @@ class PropertySubclassTests(unittest.TestCase):
self.assertEqual(Foo.spam.__doc__, "a new docstring")
+class _PropertyUnreachableAttribute:
+ msg_format = None
+ obj = None
+ cls = None
+
+ def _format_exc_msg(self, msg):
+ return self.msg_format.format(msg)
+
+ @classmethod
+ def setUpClass(cls):
+ cls.obj = cls.cls()
+
+ def test_get_property(self):
+ with self.assertRaisesRegex(AttributeError, self._format_exc_msg("unreadable attribute")):
+ self.obj.foo
+
+ def test_set_property(self):
+ with self.assertRaisesRegex(AttributeError, self._format_exc_msg("can't set attribute")):
+ self.obj.foo = None
+
+ def test_del_property(self):
+ with self.assertRaisesRegex(AttributeError, self._format_exc_msg("can't delete attribute")):
+ del self.obj.foo
+
+
+class PropertyUnreachableAttributeWithName(_PropertyUnreachableAttribute, unittest.TestCase):
+ msg_format = "^{} 'foo'$"
+
+ class cls:
+ foo = property()
+
+
+class PropertyUnreachableAttributeNoName(_PropertyUnreachableAttribute, unittest.TestCase):
+ msg_format = "^{}$"
+
+ class cls:
+ pass
+
+ cls.foo = property()
+
if __name__ == '__main__':
unittest.main()