MCPcopy Index your code
hub / github.com/python/cpython / test_getline

Method test_getline

Lib/test/test_linecache.py:120–143  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

118class LineCacheTests(unittest.TestCase):
119
120 def test_getline(self):
121 getline = linecache.getline
122
123 # Bad values for line number should return an empty string
124 self.assertEqual(getline(FILENAME, 2**15), EMPTY)
125 self.assertEqual(getline(FILENAME, -1), EMPTY)
126
127 # Float values currently raise TypeError, should it?
128 self.assertRaises(TypeError, getline, FILENAME, 1.1)
129
130 # Bad filenames should return an empty string
131 self.assertEqual(getline(EMPTY, 1), EMPTY)
132 self.assertEqual(getline(INVALID_NAME, 1), EMPTY)
133
134 # Check module loading
135 for entry in MODULES:
136 filename = os.path.join(MODULE_PATH, entry) + '.py'
137 with open(filename, encoding='utf-8') as file:
138 for index, line in enumerate(file):
139 self.assertEqual(line, getline(filename, index + 1))
140
141 # Check that bogus data isn't returned (issue #1309567)
142 empty = linecache.getlines('a/b/c/__init__.py')
143 self.assertEqual(empty, [])
144
145 def test_no_ending_newline(self):
146 self.addCleanup(os_helper.unlink, os_helper.TESTFN)

Callers

nothing calls this directly

Calls 6

getlineFunction · 0.85
enumerateFunction · 0.85
openFunction · 0.50
assertEqualMethod · 0.45
assertRaisesMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected