diff options
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_functools.py | 20 | ||||
-rw-r--r-- | Lib/test/test_resource.py | 17 |
2 files changed, 37 insertions, 0 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index 35e39b528f..b3803da4a3 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -179,6 +179,25 @@ class TestPartial(unittest.TestCase): f_copy = pickle.loads(pickle.dumps(f)) self.assertEqual(signature(f), signature(f_copy)) + # Issue 6083: Reference counting bug + def test_setstate_refcount(self): + class BadSequence: + def __len__(self): + return 4 + def __getitem__(self, key): + if key == 0: + return max + elif key == 1: + return tuple(range(1000000)) + elif key in (2, 3): + return {} + raise IndexError + + f = self.thetype(object) + self.assertRaisesRegex(SystemError, + "new style getargs format but argument is not a tuple", + f.__setstate__, BadSequence()) + class PartialSubclass(functools.partial): pass @@ -195,6 +214,7 @@ class TestPythonPartial(TestPartial): # the python version isn't picklable def test_pickle(self): pass + def test_setstate_refcount(self): pass class TestUpdateWrapper(unittest.TestCase): diff --git a/Lib/test/test_resource.py b/Lib/test/test_resource.py index 3c9b620702..f3416b7b43 100644 --- a/Lib/test/test_resource.py +++ b/Lib/test/test_resource.py @@ -107,6 +107,23 @@ class ResourceTest(unittest.TestCase): except (ValueError, AttributeError): pass + # Issue 6083: Reference counting bug + def test_setrusage_refcount(self): + try: + limits = resource.getrlimit(resource.RLIMIT_CPU) + except AttributeError: + pass + else: + class BadSequence: + def __len__(self): + return 2 + def __getitem__(self, key): + if key in (0, 1): + return len(tuple(range(1000000))) + raise IndexError + + resource.setrlimit(resource.RLIMIT_CPU, BadSequence()) + def test_main(verbose=None): support.run_unittest(ResourceTest) |