|
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 |
@@ -1807,10 +1808,47 @@ def test_issue42383(self): |
1807 | 1808 | self.assertEqual(stdout.split('\n')[6].rstrip('\r'), expected) |
1808 | 1809 |
|
1809 | 1810 |
|
| 1811 | +class ChecklineTests(unittest.TestCase): |
| 1812 | + def setUp(self): |
| 1813 | + linecache.clearcache() # Pdb.checkline() uses linecache.getline() |
| 1814 | + |
| 1815 | + def tearDown(self): |
| 1816 | + os_helper.unlink(os_helper.TESTFN) |
| 1817 | + |
| 1818 | + def test_checkline_before_debugging(self): |
| 1819 | + with open(os_helper.TESTFN, "w") as f: |
| 1820 | + f.write("print(123)") |
| 1821 | + db = pdb.Pdb() |
| 1822 | + self.assertEqual(db.checkline(os_helper.TESTFN, 1), 1) |
| 1823 | + |
| 1824 | + def test_checkline_after_reset(self): |
| 1825 | + with open(os_helper.TESTFN, "w") as f: |
| 1826 | + f.write("print(123)") |
| 1827 | + db = pdb.Pdb() |
| 1828 | + db.reset() |
| 1829 | + self.assertEqual(db.checkline(os_helper.TESTFN, 1), 1) |
| 1830 | + |
| 1831 | + def test_checkline_is_not_executable(self): |
| 1832 | + with open(os_helper.TESTFN, "w") as f: |
| 1833 | + # Test for comments, docstrings and empty lines |
| 1834 | + s = textwrap.dedent(""" |
| 1835 | + # Comment |
| 1836 | + \"\"\" docstring \"\"\" |
| 1837 | + ''' docstring ''' |
| 1838 | +
|
| 1839 | + """) |
| 1840 | + f.write(s) |
| 1841 | + db = pdb.Pdb() |
| 1842 | + num_lines = len(s.splitlines()) + 2 # Test for EOF |
| 1843 | + for lineno in range(num_lines): |
| 1844 | + self.assertFalse(db.checkline(os_helper.TESTFN, lineno)) |
| 1845 | + |
| 1846 | + |
1810 | 1847 | def load_tests(*args): |
1811 | 1848 | from test import test_pdb |
1812 | 1849 | suites = [ |
1813 | 1850 | unittest.makeSuite(PdbTestCase), |
| 1851 | + unittest.makeSuite(ChecklineTests), |
1814 | 1852 | doctest.DocTestSuite(test_pdb) |
1815 | 1853 | ] |
1816 | 1854 | return unittest.TestSuite(suites) |
|
0 commit comments