|
9 | 9 | import unittest
|
10 | 10 | import subprocess
|
11 | 11 | import textwrap
|
| 12 | +import linecache |
12 | 13 |
|
13 | 14 | from contextlib import ExitStack
|
14 | 15 | from io import StringIO
|
@@ -1295,6 +1296,9 @@ def test_pdb_issue_20766():
|
1295 | 1296 |
|
1296 | 1297 |
|
1297 | 1298 | class PdbTestCase(unittest.TestCase):
|
| 1299 | + def setUp(self): |
| 1300 | + linecache.clearcache() # Pdb.checkline() uses linecache.getline() |
| 1301 | + |
1298 | 1302 | def tearDown(self):
|
1299 | 1303 | os_helper.unlink(os_helper.TESTFN)
|
1300 | 1304 |
|
@@ -1806,14 +1810,34 @@ def test_issue42383(self):
|
1806 | 1810 | expected = '(Pdb) The correct file was executed'
|
1807 | 1811 | self.assertEqual(stdout.split('\n')[6].rstrip('\r'), expected)
|
1808 | 1812 |
|
1809 |
| - def test_issue28528(self): |
| 1813 | + def test_checkline_before_debugging(self): |
1810 | 1814 | with open(os_helper.TESTFN, "w") as f:
|
1811 | 1815 | f.write("print(123)")
|
1812 | 1816 | db = pdb.Pdb()
|
1813 | 1817 | 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() |
1814 | 1823 | db.reset()
|
1815 | 1824 | self.assertEqual(db.checkline(os_helper.TESTFN, 1), 1)
|
1816 | 1825 |
|
| 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 | + |
1817 | 1841 |
|
1818 | 1842 | def load_tests(*args):
|
1819 | 1843 | from test import test_pdb
|
|
0 commit comments