diff options
author | James Gerity <snoopjedi@gmail.com> | 2022-10-25 13:22:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-25 13:22:53 (GMT) |
commit | d91de288e73c67805e4c838b5f770ab7ec3661f9 (patch) | |
tree | b35272b46a434fb805ce28b4bbea0345e218a644 /Lib/test/test_pdb.py | |
parent | dd13b23e49b8c49bc751fe5ed470773a2d60b7d1 (diff) | |
download | cpython-d91de288e73c67805e4c838b5f770ab7ec3661f9.zip cpython-d91de288e73c67805e4c838b5f770ab7ec3661f9.tar.gz cpython-d91de288e73c67805e4c838b5f770ab7ec3661f9.tar.bz2 |
gh-93696: Locate frozen module source with __file__ (#93697)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Diffstat (limited to 'Lib/test/test_pdb.py')
-rw-r--r-- | Lib/test/test_pdb.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 55c3283..48f419e 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -2104,6 +2104,52 @@ def bœr(): stdout, stderr = self.run_pdb_script(script, commands) self.assertFalse(stderr) + def test_gh_93696_frozen_list(self): + frozen_src = """ + def func(): + x = "Sentinel string for gh-93696" + print(x) + """ + host_program = """ + import os + import sys + + def _create_fake_frozen_module(): + with open('gh93696.py') as f: + src = f.read() + + # this function has a co_filename as if it were in a frozen module + dummy_mod = compile(src, "<frozen gh93696>", "exec") + func_code = dummy_mod.co_consts[0] + + mod = type(sys)("gh93696") + mod.func = type(lambda: None)(func_code, mod.__dict__) + mod.__file__ = 'gh93696.py' + + return mod + + mod = _create_fake_frozen_module() + mod.func() + """ + commands = """ + break 20 + continue + step + list + quit + """ + with open('gh93696.py', 'w') as f: + f.write(textwrap.dedent(frozen_src)) + + with open('gh93696_host.py', 'w') as f: + f.write(textwrap.dedent(host_program)) + + self.addCleanup(os_helper.unlink, 'gh93696.py') + self.addCleanup(os_helper.unlink, 'gh93696_host.py') + stdout, stderr = self._run_pdb(["gh93696_host.py"], commands) + # verify that pdb found the source of the "frozen" function + self.assertIn('x = "Sentinel string for gh-93696"', stdout, "Sentinel statement not found") + class ChecklineTests(unittest.TestCase): def setUp(self): linecache.clearcache() # Pdb.checkline() uses linecache.getline() |