diff options
author | Eddie Elizondo <eelizondo@fb.com> | 2019-09-19 16:29:05 (GMT) |
---|---|---|
committer | Dino Viehland <dinoviehland@gmail.com> | 2019-09-19 16:29:05 (GMT) |
commit | 3368f3c6ae4140a0883e19350e672fd09c9db616 (patch) | |
tree | 0b4477fdd89aefa2b9d17e6a16c3f172f32a5660 /Lib/test | |
parent | 079931d12223ec98cbf53185b90db48efa61f93f (diff) | |
download | cpython-3368f3c6ae4140a0883e19350e672fd09c9db616.zip cpython-3368f3c6ae4140a0883e19350e672fd09c9db616.tar.gz cpython-3368f3c6ae4140a0883e19350e672fd09c9db616.tar.bz2 |
bpo-38140: Make dict and weakref offsets opaque for C heap types (#16076)
* Make dict and weakref offsets opaque for C heap types
* Add news
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_capi.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index b1d045c..79059bc 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -12,6 +12,7 @@ import textwrap import threading import time import unittest +import weakref from test import support from test.support import MISSING_C_DOCSTRINGS from test.support.script_helper import assert_python_failure, assert_python_ok @@ -437,6 +438,32 @@ class CAPITest(unittest.TestCase): # Test that subtype_dealloc decref the newly assigned __class__ only once self.assertEqual(new_type_refcnt, sys.getrefcount(A)) + def test_heaptype_with_dict(self): + inst = _testcapi.HeapCTypeWithDict() + inst.foo = 42 + self.assertEqual(inst.foo, 42) + self.assertEqual(inst.dictobj, inst.__dict__) + self.assertEqual(inst.dictobj, {"foo": 42}) + + inst = _testcapi.HeapCTypeWithDict() + self.assertEqual({}, inst.__dict__) + + def test_heaptype_with_negative_dict(self): + inst = _testcapi.HeapCTypeWithNegativeDict() + inst.foo = 42 + self.assertEqual(inst.foo, 42) + self.assertEqual(inst.dictobj, inst.__dict__) + self.assertEqual(inst.dictobj, {"foo": 42}) + + inst = _testcapi.HeapCTypeWithNegativeDict() + self.assertEqual({}, inst.__dict__) + + def test_heaptype_with_weakref(self): + inst = _testcapi.HeapCTypeWithWeakref() + ref = weakref.ref(inst) + self.assertEqual(ref(), inst) + self.assertEqual(inst.weakreflist, ref) + def test_c_subclass_of_heap_ctype_with_tpdealloc_decrefs_once(self): subclass_instance = _testcapi.HeapCTypeSubclass() type_refcnt = sys.getrefcount(_testcapi.HeapCTypeSubclass) |