Back to index

python3.2  3.2.2
Public Member Functions
test.test_linecache.LineCacheTests Class Reference

List of all members.

Public Member Functions

def test_getline
def test_no_ending_newline
def test_clearcache
def test_checkcache

Detailed Description

Definition at line 39 of file test_linecache.py.


Member Function Documentation

Definition at line 96 of file test_linecache.py.

00096 
00097     def test_checkcache(self):
00098         getline = linecache.getline
00099         # Create a source file and cache its contents
00100         source_name = support.TESTFN + '.py'
00101         self.addCleanup(support.unlink, source_name)
00102         with open(source_name, 'w') as source:
00103             source.write(SOURCE_1)
00104         getline(source_name, 1)
00105 
00106         # Keep a copy of the old contents
00107         source_list = []
00108         with open(source_name) as source:
00109             for index, line in enumerate(source):
00110                 self.assertEqual(line, getline(source_name, index + 1))
00111                 source_list.append(line)
00112 
00113         with open(source_name, 'w') as source:
00114             source.write(SOURCE_2)
00115 
00116         # Try to update a bogus cache entry
00117         linecache.checkcache('dummy')
00118 
00119         # Check that the cache matches the old contents
00120         for index, line in enumerate(source_list):
00121             self.assertEqual(line, getline(source_name, index + 1))
00122 
00123         # Update the cache and check whether it matches the new source file
00124         linecache.checkcache(source_name)
00125         with open(source_name) as source:
00126             for index, line in enumerate(source):
00127                 self.assertEqual(line, getline(source_name, index + 1))
00128                 source_list.append(line)

Here is the call graph for this function:

Definition at line 80 of file test_linecache.py.

00080 
00081     def test_clearcache(self):
00082         cached = []
00083         for entry in TESTS:
00084             filename = os.path.join(TEST_PATH, entry) + '.py'
00085             cached.append(filename)
00086             linecache.getline(filename, 1)
00087 
00088         # Are all files cached?
00089         cached_empty = [fn for fn in cached if fn not in linecache.cache]
00090         self.assertEqual(cached_empty, [])
00091 
00092         # Can we clear the cache?
00093         linecache.clearcache()
00094         cached_empty = [fn for fn in cached if fn in linecache.cache]
00095         self.assertEqual(cached_empty, [])

Here is the call graph for this function:

Definition at line 41 of file test_linecache.py.

00041 
00042     def test_getline(self):
00043         getline = linecache.getline
00044 
00045         # Bad values for line number should return an empty string
00046         self.assertEqual(getline(FILENAME, 2**15), EMPTY)
00047         self.assertEqual(getline(FILENAME, -1), EMPTY)
00048 
00049         # Float values currently raise TypeError, should it?
00050         self.assertRaises(TypeError, getline, FILENAME, 1.1)
00051 
00052         # Bad filenames should return an empty string
00053         self.assertEqual(getline(EMPTY, 1), EMPTY)
00054         self.assertEqual(getline(INVALID_NAME, 1), EMPTY)
00055 
00056         # Check whether lines correspond to those from file iteration
00057         for entry in TESTS:
00058             filename = os.path.join(TEST_PATH, entry) + '.py'
00059             with open(filename) as file:
00060                 for index, line in enumerate(file):
00061                     self.assertEqual(line, getline(filename, index + 1))
00062 
00063         # Check module loading
00064         for entry in MODULES:
00065             filename = os.path.join(MODULE_PATH, entry) + '.py'
00066             with open(filename) as file:
00067                 for index, line in enumerate(file):
00068                     self.assertEqual(line, getline(filename, index + 1))
00069 
00070         # Check that bogus data isn't returned (issue #1309567)
00071         empty = linecache.getlines('a/b/c/__init__.py')
00072         self.assertEqual(empty, [])

Here is the call graph for this function:

Definition at line 73 of file test_linecache.py.

00073 
00074     def test_no_ending_newline(self):
00075         self.addCleanup(support.unlink, support.TESTFN)
00076         with open(support.TESTFN, "w") as fp:
00077             fp.write(SOURCE_3)
00078         lines = linecache.getlines(support.TESTFN)
00079         self.assertEqual(lines, ["\n", "def f():\n", "    return 3\n"])

Here is the call graph for this function:


The documentation for this class was generated from the following file: