diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-01 13:54:05 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-01 13:54:05 (GMT) |
commit | c512adc90d49b1dae3ae14c81826e03c9ea46ba5 (patch) | |
tree | 0707548efd8968ee36a3ccd5e52ad54780c420ff /Lib/test/test_linecache.py | |
parent | 263dcd20a374d540c8f0bc07332f1657adf6da83 (diff) | |
download | cpython-c512adc90d49b1dae3ae14c81826e03c9ea46ba5.zip cpython-c512adc90d49b1dae3ae14c81826e03c9ea46ba5.tar.gz cpython-c512adc90d49b1dae3ae14c81826e03c9ea46ba5.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 | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/Lib/test/test_linecache.py b/Lib/test/test_linecache.py index 5fe0554..79157de 100644 --- a/Lib/test/test_linecache.py +++ b/Lib/test/test_linecache.py @@ -126,8 +126,21 @@ class LineCacheTests(unittest.TestCase): self.assertEqual(line, getline(source_name, index + 1)) source_list.append(line) -def test_main(): - support.run_unittest(LineCacheTests) + 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) + if __name__ == "__main__": - test_main() + unittest.main() |