diff options
Diffstat (limited to 'Lib/test/test_linecache.py')
-rw-r--r-- | Lib/test/test_linecache.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/Lib/test/test_linecache.py b/Lib/test/test_linecache.py index 56e09dc..7d14534 100644 --- a/Lib/test/test_linecache.py +++ b/Lib/test/test_linecache.py @@ -12,7 +12,7 @@ EMPTY = '' TESTS = 'inspect_fodder inspect_fodder2 mapping_tests' TESTS = TESTS.split() TEST_PATH = os.path.dirname(support.__file__) -MODULES = "linecache unittest".split() +MODULES = "linecache abc".split() MODULE_PATH = os.path.dirname(FILENAME) SOURCE_1 = ''' @@ -55,14 +55,16 @@ class LineCacheTests(unittest.TestCase): # Check whether lines correspond to those from file iteration for entry in TESTS: filename = os.path.join(TEST_PATH, entry) + '.py' - for index, line in enumerate(open(filename)): - self.assertEqual(line, getline(filename, index + 1)) + with open(filename) as file: + for index, line in enumerate(file): + self.assertEqual(line, getline(filename, index + 1)) # Check module loading for entry in MODULES: filename = os.path.join(MODULE_PATH, entry) + '.py' - for index, line in enumerate(open(filename)): - self.assertEqual(line, getline(filename, index + 1)) + with open(filename) as file: + for index, line in enumerate(file): + self.assertEqual(line, getline(filename, index + 1)) # Check that bogus data isn't returned (issue #1309567) empty = linecache.getlines('a/b/c/__init__.py') @@ -99,6 +101,7 @@ class LineCacheTests(unittest.TestCase): with open(source_name, 'w') as source: source.write(SOURCE_1) getline(source_name, 1) + # Keep a copy of the old contents source_list = [] with open(source_name) as source: @@ -123,7 +126,6 @@ class LineCacheTests(unittest.TestCase): self.assertEqual(line, getline(source_name, index + 1)) source_list.append(line) - def test_main(): support.run_unittest(LineCacheTests) |