(self)
| 167 | self.assertEqual(cached_empty, []) |
| 168 | |
| 169 | def test_checkcache(self): |
| 170 | getline = linecache.getline |
| 171 | # Create a source file and cache its contents |
| 172 | source_name = os_helper.TESTFN + '.py' |
| 173 | self.addCleanup(os_helper.unlink, source_name) |
| 174 | with open(source_name, 'w', encoding='utf-8') as source: |
| 175 | source.write(SOURCE_1) |
| 176 | getline(source_name, 1) |
| 177 | |
| 178 | # Keep a copy of the old contents |
| 179 | source_list = [] |
| 180 | with open(source_name, encoding='utf-8') as source: |
| 181 | for index, line in enumerate(source): |
| 182 | self.assertEqual(line, getline(source_name, index + 1)) |
| 183 | source_list.append(line) |
| 184 | |
| 185 | with open(source_name, 'w', encoding='utf-8') as source: |
| 186 | source.write(SOURCE_2) |
| 187 | |
| 188 | # Try to update a bogus cache entry |
| 189 | linecache.checkcache('dummy') |
| 190 | |
| 191 | # Check that the cache matches the old contents |
| 192 | for index, line in enumerate(source_list): |
| 193 | self.assertEqual(line, getline(source_name, index + 1)) |
| 194 | |
| 195 | # Update the cache and check whether it matches the new source file |
| 196 | linecache.checkcache(source_name) |
| 197 | with open(source_name, encoding='utf-8') as source: |
| 198 | for index, line in enumerate(source): |
| 199 | self.assertEqual(line, getline(source_name, index + 1)) |
| 200 | source_list.append(line) |
| 201 | |
| 202 | def test_lazycache_no_globals(self): |
| 203 | lines = linecache.getlines(FILENAME) |
nothing calls this directly
no test coverage detected