diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-01 13:56:13 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-01 13:56:13 (GMT) |
commit | 05ddbf0875b449f69616c31fbbe49dd5f3d5e329 (patch) | |
tree | e7cbf07a3fad26c69006f38e2216d5c56d1c786b /Lib/test/test_linecache.py | |
parent | ef2a397a65bf5f321a04aa429efa76f910849e31 (diff) | |
parent | c512adc90d49b1dae3ae14c81826e03c9ea46ba5 (diff) | |
download | cpython-05ddbf0875b449f69616c31fbbe49dd5f3d5e329.zip cpython-05ddbf0875b449f69616c31fbbe49dd5f3d5e329.tar.gz cpython-05ddbf0875b449f69616c31fbbe49dd5f3d5e329.tar.bz2 |
Issue #23838: linecache now clears the cache and returns an empty result on
MemoryError.
Diffstat (limited to 'Lib/test/test_linecache.py')
-rw-r--r-- | Lib/test/test_linecache.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/Lib/test/test_linecache.py b/Lib/test/test_linecache.py index 2fb8662..21ef738 100644 --- a/Lib/test/test_linecache.py +++ b/Lib/test/test_linecache.py @@ -169,9 +169,21 @@ class LineCacheTests(unittest.TestCase): linecache.lazycache(NONEXISTENT_FILENAME, globals())) self.assertEqual(4, len(linecache.cache[NONEXISTENT_FILENAME])) + def test_memoryerror(self): + lines = linecache.getlines(FILENAME) + self.assertTrue(lines) + def raise_memoryerror(*args, **kwargs): + raise MemoryError + with support.swap_attr(linecache, 'updatecache', raise_memoryerror): + lines2 = linecache.getlines(FILENAME) + self.assertEqual(lines2, lines) + + linecache.clearcache() + with support.swap_attr(linecache, 'updatecache', raise_memoryerror): + lines3 = linecache.getlines(FILENAME) + self.assertEqual(lines3, []) + self.assertEqual(linecache.getlines(FILENAME), lines) -def test_main(): - support.run_unittest(LineCacheTests) if __name__ == "__main__": - test_main() + unittest.main() |