summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_linecache.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_linecache.py')
-rw-r--r--Lib/test/test_linecache.py19
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()