From 975b423a720c69afd85ccd1f3384a5d2be3310d4 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Thu, 23 Mar 2023 16:22:39 -0700 Subject: [PATCH 1/4] Add tests for display, alias and where --- Lib/test/test_pdb.py | 147 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index d91bd0b2f03a0f..f5e6cbc6e23102 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -574,6 +574,153 @@ def test_pdb_whatis_command(): (Pdb) continue """ +def test_pdb_display_command(): + """Test display command + + >>> def test_function(): + ... a = 0 + ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + ... a = 1 + ... a = 2 + ... a = 3 + ... a = 4 + + >>> with PdbTestInput([ # doctest: +ELLIPSIS + ... 'display a', + ... 'n', + ... 'display', + ... 'undisplay a', + ... 'n', + ... 'display a', + ... 'undisplay', + ... 'n', + ... 'continue', + ... ]): + ... test_function() + > (4)test_function() + -> a = 1 + (Pdb) display a + display a: 0 + (Pdb) n + > (5)test_function() + -> a = 2 + display a: 1 [old: 0] + (Pdb) display + Currently displaying: + a: 1 + (Pdb) undisplay a + (Pdb) n + > (6)test_function() + -> a = 3 + (Pdb) display a + display a: 2 + (Pdb) undisplay + (Pdb) n + > (7)test_function() + -> a = 4 + (Pdb) continue + """ + +def test_pdb_alias_command(): + """Test alias command + + >>> class A: + ... def __init__(self): + ... self.attr1 = 10 + ... self.attr2 = 'str' + ... def method(self): + ... pass + + >>> def test_function(): + ... o = A() + ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + ... o.method() + + >>> with PdbTestInput([ # doctest: +ELLIPSIS + ... 'alias pi for k in %1.__dict__.keys(): print(f"%1.{k} = {%1.__dict__[k]}")', + ... 'alias ps pi self', + ... 'pi o', + ... 's', + ... 'ps', + ... 'continue', + ... ]): + ... test_function() + > (4)test_function() + -> o.method() + (Pdb) alias pi for k in %1.__dict__.keys(): print(f"%1.{k} = {%1.__dict__[k]}") + (Pdb) alias ps pi self + (Pdb) pi o + o.attr1 = 10 + o.attr2 = str + (Pdb) s + --Call-- + > (5)method() + -> def method(self): + (Pdb) ps + self.attr1 = 10 + self.attr2 = str + (Pdb) continue + """ + +def test_pdb_where_command(): + """Test where command + + >>> def g(): + ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + + >>> def f(): + ... g(); + + >>> def test_function(): + ... f() + + >>> with PdbTestInput([ # doctest: +ELLIPSIS + ... 'w', + ... 'where', + ... 'u', + ... 'w', + ... 'continue', + ... ]): + ... test_function() + --Return-- + > (2)g()->None + -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + (Pdb) w + ... + (8)() + -> test_function() + (2)test_function() + -> f() + (2)f() + -> g(); + > (2)g()->None + -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + (Pdb) where + ... + (8)() + -> test_function() + (2)test_function() + -> f() + (2)f() + -> g(); + > (2)g()->None + -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + (Pdb) u + > (2)f() + -> g(); + (Pdb) w + ... + (8)() + -> test_function() + (2)test_function() + -> f() + > (2)f() + -> g(); + (2)g()->None + -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + (Pdb) continue + """ + def test_post_mortem(): """Test post mortem traceback debugging. From 27e6f79e0e79908345f8955ac9a012a185968535 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 23 Mar 2023 23:25:19 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Tests/2023-03-23-23-25-18.gh-issue-102980.Zps4QF.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Tests/2023-03-23-23-25-18.gh-issue-102980.Zps4QF.rst diff --git a/Misc/NEWS.d/next/Tests/2023-03-23-23-25-18.gh-issue-102980.Zps4QF.rst b/Misc/NEWS.d/next/Tests/2023-03-23-23-25-18.gh-issue-102980.Zps4QF.rst new file mode 100644 index 00000000000000..84713958964c23 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2023-03-23-23-25-18.gh-issue-102980.Zps4QF.rst @@ -0,0 +1 @@ +Improve test coverage on pdb From c5bcfb4447b3610ca1ab5ce51cf703ba74510fa6 Mon Sep 17 00:00:00 2001 From: gaogaotiantian Date: Fri, 24 Mar 2023 13:03:56 -0700 Subject: [PATCH 3/4] Update Misc/NEWS.d/next/Tests/2023-03-23-23-25-18.gh-issue-102980.Zps4QF.rst Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> --- .../next/Tests/2023-03-23-23-25-18.gh-issue-102980.Zps4QF.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Tests/2023-03-23-23-25-18.gh-issue-102980.Zps4QF.rst b/Misc/NEWS.d/next/Tests/2023-03-23-23-25-18.gh-issue-102980.Zps4QF.rst index 84713958964c23..48277367fc8755 100644 --- a/Misc/NEWS.d/next/Tests/2023-03-23-23-25-18.gh-issue-102980.Zps4QF.rst +++ b/Misc/NEWS.d/next/Tests/2023-03-23-23-25-18.gh-issue-102980.Zps4QF.rst @@ -1 +1 @@ -Improve test coverage on pdb +Improve test coverage on :mod:`pdb`. From 48351064f1fe590b81245448c35b56ad81538846 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Fri, 24 Mar 2023 13:08:52 -0700 Subject: [PATCH 4/4] Add an expression that does not change for extra coverage --- Lib/test/test_pdb.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index f5e6cbc6e23102..e96dc7fa1cf6e7 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -593,6 +593,7 @@ def test_pdb_display_command(): ... 'n', ... 'display a', ... 'undisplay', + ... 'display a < 1', ... 'n', ... 'continue', ... ]): @@ -615,6 +616,8 @@ def test_pdb_display_command(): (Pdb) display a display a: 2 (Pdb) undisplay + (Pdb) display a < 1 + display a < 1: False (Pdb) n > (7)test_function() -> a = 4