Skip to content

Commit 77c88bb

Browse files
Improvements in test
1 parent d965529 commit 77c88bb

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

Lib/test/test_stackrefs.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
@cpython_only
1010
class TestDefinition(unittest.TestCase):
1111

12+
BIG_REFCOUNT = 1000
13+
1214
def test_equivalence(self):
1315
def run_with_refcount_check(self, func, obj):
1416
refcount = sys.getrefcount(obj)
@@ -34,23 +36,30 @@ def run_with_refcount_check(self, func, obj):
3436
for obj in immortal_objs:
3537
results = set()
3638
for func in funcs_with_incref + funcs_with_borrow:
37-
res = run_with_refcount_check(self, func, obj)
38-
results.add(res)
39+
refcount, flags = run_with_refcount_check(self, func, obj)
40+
self.assertGreater(refcount, self.BIG_REFCOUNT)
41+
self.assertIn(flags, (1, -1))
42+
results.add((refcount, flags))
43+
3944
self.assertEqual(len(results), 1)
4045

41-
mortal_objs = (5000, 3+2j, range(10), object())
46+
mortal_objs = (object(), range(10), iter([1, 2, 3]))
4247

4348
for obj in mortal_objs:
4449
results = set()
4550
for func in funcs_with_incref:
46-
res = run_with_refcount_check(self, func, obj)
47-
results.add(res)
51+
refcount, flags = run_with_refcount_check(self, func, obj)
52+
self.assertLess(refcount, self.BIG_REFCOUNT)
53+
self.assertEqual(flags, 0)
54+
results.add((refcount, flags))
4855
self.assertEqual(len(results), 1)
4956

5057
results = set()
5158
for func in funcs_with_borrow:
52-
res = run_with_refcount_check(self, func, obj)
53-
results.add(res)
59+
refcount, flags = run_with_refcount_check(self, func, obj)
60+
self.assertLess(refcount, self.BIG_REFCOUNT)
61+
self.assertEqual(flags, 1)
62+
results.add((refcount, flags))
5463
self.assertEqual(len(results), 1)
5564

5665

0 commit comments

Comments
 (0)