Skip to content

Commit 5e39e74

Browse files
author
Erlend E. Aasland
committed
Address review: increase checkline() coverage
1 parent 4010b04 commit 5e39e74

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

Lib/test/test_pdb.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import unittest
1010
import subprocess
1111
import textwrap
12+
import linecache
1213

1314
from contextlib import ExitStack
1415
from io import StringIO
@@ -1295,6 +1296,9 @@ def test_pdb_issue_20766():
12951296

12961297

12971298
class PdbTestCase(unittest.TestCase):
1299+
def setUp(self):
1300+
linecache.clearcache() # Pdb.checkline() uses linecache.getline()
1301+
12981302
def tearDown(self):
12991303
os_helper.unlink(os_helper.TESTFN)
13001304

@@ -1806,14 +1810,34 @@ def test_issue42383(self):
18061810
expected = '(Pdb) The correct file was executed'
18071811
self.assertEqual(stdout.split('\n')[6].rstrip('\r'), expected)
18081812

1809-
def test_issue28528(self):
1813+
def test_checkline_before_debugging(self):
18101814
with open(os_helper.TESTFN, "w") as f:
18111815
f.write("print(123)")
18121816
db = pdb.Pdb()
18131817
self.assertEqual(db.checkline(os_helper.TESTFN, 1), 1)
1818+
1819+
def test_checkline_after_reset(self):
1820+
with open(os_helper.TESTFN, "w") as f:
1821+
f.write("print(123)")
1822+
db = pdb.Pdb()
18141823
db.reset()
18151824
self.assertEqual(db.checkline(os_helper.TESTFN, 1), 1)
18161825

1826+
def test_checkline_is_not_executable(self):
1827+
with open(os_helper.TESTFN, "w") as f:
1828+
# Test for comments, docstrings and empty lines
1829+
s = textwrap.dedent("""
1830+
# Comment
1831+
\"\"\" docstring \"\"\"
1832+
''' docstring '''
1833+
1834+
""")
1835+
f.write(s)
1836+
db = pdb.Pdb()
1837+
num_lines = len(s.splitlines()) + 2 # Test for EOF
1838+
for lineno in range(num_lines):
1839+
self.assertFalse(db.checkline(os_helper.TESTFN, lineno))
1840+
18171841

18181842
def load_tests(*args):
18191843
from test import test_pdb

0 commit comments

Comments
 (0)