summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_dataclasses.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_dataclasses.py')
-rw-r--r--Lib/test/test_dataclasses.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/Lib/test/test_dataclasses.py b/Lib/test/test_dataclasses.py
index 9af4377..3a24777 100644
--- a/Lib/test/test_dataclasses.py
+++ b/Lib/test/test_dataclasses.py
@@ -3076,6 +3076,8 @@ class TestSlots(unittest.TestCase):
with self.assertRaisesRegex(TypeError,
"cannot create weak reference"):
weakref.ref(a)
+ with self.assertRaises(AttributeError):
+ a.__weakref__
def test_slots_weakref(self):
@dataclass(slots=True, weakref_slot=True)
@@ -3084,7 +3086,9 @@ class TestSlots(unittest.TestCase):
self.assertIn("__weakref__", A.__slots__)
a = A(1)
- weakref.ref(a)
+ a_ref = weakref.ref(a)
+
+ self.assertIs(a.__weakref__, a_ref)
def test_slots_weakref_base_str(self):
class Base:
@@ -3150,7 +3154,8 @@ class TestSlots(unittest.TestCase):
self.assertIn("__weakref__", Base.__slots__)
self.assertNotIn("__weakref__", A.__slots__)
a = A(1)
- weakref.ref(a)
+ a_ref = weakref.ref(a)
+ self.assertIs(a.__weakref__, a_ref)
def test_weakref_slot_subclass_no_weakref_slot(self):
@dataclass(slots=True, weakref_slot=True)
@@ -3166,7 +3171,8 @@ class TestSlots(unittest.TestCase):
self.assertIn("__weakref__", Base.__slots__)
self.assertNotIn("__weakref__", A.__slots__)
a = A(1)
- weakref.ref(a)
+ a_ref = weakref.ref(a)
+ self.assertIs(a.__weakref__, a_ref)
def test_weakref_slot_normal_base_weakref_slot(self):
class Base:
@@ -3181,7 +3187,8 @@ class TestSlots(unittest.TestCase):
self.assertIn("__weakref__", Base.__slots__)
self.assertNotIn("__weakref__", A.__slots__)
a = A(1)
- weakref.ref(a)
+ a_ref = weakref.ref(a)
+ self.assertIs(a.__weakref__, a_ref)
class TestDescriptors(unittest.TestCase):