Changeset 391 for python/trunk/Lib/test/test_linecache.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/test/test_linecache.py
r2 r391 10 10 INVALID_NAME = '!@$)(!@#_1' 11 11 EMPTY = '' 12 TESTS = ' cjkencodings_testinspect_fodder inspect_fodder2 mapping_tests'12 TESTS = 'inspect_fodder inspect_fodder2 mapping_tests' 13 13 TESTS = TESTS.split() 14 14 TEST_PATH = os.path.dirname(support.__file__) 15 MODULES = "linecache unittest".split()15 MODULES = "linecache abc".split() 16 16 MODULE_PATH = os.path.dirname(FILENAME) 17 17 … … 32 32 ''' 33 33 34 SOURCE_3 = ''' 35 def f(): 36 return 3''' # No ending newline 37 38 34 39 class LineCacheTests(unittest.TestCase): 35 40 … … 38 43 39 44 # Bad values for line number should return an empty string 40 self.assertEqual s(getline(FILENAME, 2**15), EMPTY)41 self.assertEqual s(getline(FILENAME, -1), EMPTY)45 self.assertEqual(getline(FILENAME, 2**15), EMPTY) 46 self.assertEqual(getline(FILENAME, -1), EMPTY) 42 47 43 48 # Float values currently raise TypeError, should it? … … 45 50 46 51 # Bad filenames should return an empty string 47 self.assertEqual s(getline(EMPTY, 1), EMPTY)48 self.assertEqual s(getline(INVALID_NAME, 1), EMPTY)52 self.assertEqual(getline(EMPTY, 1), EMPTY) 53 self.assertEqual(getline(INVALID_NAME, 1), EMPTY) 49 54 50 55 # Check whether lines correspond to those from file iteration … … 52 57 filename = os.path.join(TEST_PATH, entry) + '.py' 53 58 for index, line in enumerate(open(filename)): 54 self.assertEqual s(line, getline(filename, index + 1))59 self.assertEqual(line, getline(filename, index + 1)) 55 60 56 61 # Check module loading … … 58 63 filename = os.path.join(MODULE_PATH, entry) + '.py' 59 64 for index, line in enumerate(open(filename)): 60 self.assertEqual s(line, getline(filename, index + 1))65 self.assertEqual(line, getline(filename, index + 1)) 61 66 62 67 # Check that bogus data isn't returned (issue #1309567) 63 68 empty = linecache.getlines('a/b/c/__init__.py') 64 self.assertEquals(empty, []) 69 self.assertEqual(empty, []) 70 71 def test_no_ending_newline(self): 72 self.addCleanup(support.unlink, support.TESTFN) 73 with open(support.TESTFN, "w") as fp: 74 fp.write(SOURCE_3) 75 lines = linecache.getlines(support.TESTFN) 76 self.assertEqual(lines, ["\n", "def f():\n", " return 3\n"]) 65 77 66 78 def test_clearcache(self): … … 73 85 # Are all files cached? 74 86 cached_empty = [fn for fn in cached if fn not in linecache.cache] 75 self.assertEqual s(cached_empty, [])87 self.assertEqual(cached_empty, []) 76 88 77 89 # Can we clear the cache? 78 90 linecache.clearcache() 79 91 cached_empty = [fn for fn in cached if fn in linecache.cache] 80 self.assertEqual s(cached_empty, [])92 self.assertEqual(cached_empty, []) 81 93 82 94 def test_checkcache(self): 83 95 getline = linecache.getline 84 try: 85 # Create a source file and cache its contents 86 source_name = support.TESTFN + '.py' 87 with open(source_name, 'w') as source: 88 source.write(SOURCE_1) 89 source.close() 90 getline(source_name, 1) 96 # Create a source file and cache its contents 97 source_name = support.TESTFN + '.py' 98 self.addCleanup(support.unlink, source_name) 99 with open(source_name, 'w') as source: 100 source.write(SOURCE_1) 101 getline(source_name, 1) 91 102 92 # Keep a copy of the old contents 93 source_list = [] 94 source = open(source_name) 95 for index, line in enumerate(source): 96 self.assertEquals(line, getline(source_name, index + 1)) 97 source_list.append(line) 98 source.close() 103 # Keep a copy of the old contents 104 source_list = [] 105 with open(source_name) as source: 106 for index, line in enumerate(source): 107 self.assertEqual(line, getline(source_name, index + 1)) 108 source_list.append(line) 99 109 100 source = open(source_name, 'w') 101 source.write(SOURCE_2) 102 source.close() 110 with open(source_name, 'w') as source: 111 source.write(SOURCE_2) 103 112 104 105 113 # Try to update a bogus cache entry 114 linecache.checkcache('dummy') 106 115 107 108 109 self.assertEquals(line, getline(source_name, index + 1))116 # Check that the cache matches the old contents 117 for index, line in enumerate(source_list): 118 self.assertEqual(line, getline(source_name, index + 1)) 110 119 111 # Update the cache and check whether it matches the new source file 112 linecache.checkcache(source_name) 113 source = open(source_name) 114 for index, line in enumerate(source): 115 self.assertEquals(line, getline(source_name, index + 1)) 116 source_list.append(line) 117 118 finally: 119 support.unlink(source_name) 120 # Update the cache and check whether it matches the new source file 121 linecache.checkcache(source_name) 122 with open(source_name) as source: 123 for index, line in enumerate(source): 124 self.assertEqual(line, getline(source_name, index + 1)) 125 source_list.append(line) 120 126 121 127 def test_main():
Note:
See TracChangeset
for help on using the changeset viewer.