diff options
author | Erlend Egeberg Aasland <erlend.aasland@innova.no> | 2021-05-11 23:26:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-11 23:26:30 (GMT) |
commit | 8563a7052ccd98e6a381d361664ce567afd5eb6e (patch) | |
tree | 6a48de437ce5a5d2df98b62d1408c89226dbebfe /Lib/test | |
parent | c1df8808e054bbe4fe66f35ccc0f88d8b292778a (diff) | |
download | cpython-8563a7052ccd98e6a381d361664ce567afd5eb6e.zip cpython-8563a7052ccd98e6a381d361664ce567afd5eb6e.tar.gz cpython-8563a7052ccd98e6a381d361664ce567afd5eb6e.tar.bz2 |
bpo-28528: Fix pdb.checkline() attribute error when 'curframe' is None. (#25438)
Co-authored-by: Thomas Kluyver <takowl@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_pdb.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 870eab4..cd096e7 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -9,6 +9,7 @@ import codecs import unittest import subprocess import textwrap +import linecache from contextlib import ExitStack from io import StringIO @@ -1807,10 +1808,47 @@ def bœr(): self.assertEqual(stdout.split('\n')[6].rstrip('\r'), expected) +class ChecklineTests(unittest.TestCase): + def setUp(self): + linecache.clearcache() # Pdb.checkline() uses linecache.getline() + + def tearDown(self): + os_helper.unlink(os_helper.TESTFN) + + def test_checkline_before_debugging(self): + with open(os_helper.TESTFN, "w") as f: + f.write("print(123)") + db = pdb.Pdb() + self.assertEqual(db.checkline(os_helper.TESTFN, 1), 1) + + def test_checkline_after_reset(self): + with open(os_helper.TESTFN, "w") as f: + f.write("print(123)") + db = pdb.Pdb() + db.reset() + self.assertEqual(db.checkline(os_helper.TESTFN, 1), 1) + + def test_checkline_is_not_executable(self): + with open(os_helper.TESTFN, "w") as f: + # Test for comments, docstrings and empty lines + s = textwrap.dedent(""" + # Comment + \"\"\" docstring \"\"\" + ''' docstring ''' + + """) + f.write(s) + db = pdb.Pdb() + num_lines = len(s.splitlines()) + 2 # Test for EOF + for lineno in range(num_lines): + self.assertFalse(db.checkline(os_helper.TESTFN, lineno)) + + def load_tests(*args): from test import test_pdb suites = [ unittest.makeSuite(PdbTestCase), + unittest.makeSuite(ChecklineTests), doctest.DocTestSuite(test_pdb) ] return unittest.TestSuite(suites) |