Skip to content

Commit a08b65f

Browse files
gh-102980: Add tests for pdf's display, alias and where commands (GH-102981)
(cherry picked from commit ded9a7f) Co-authored-by: gaogaotiantian <gaogaotiantian@hotmail.com>
1 parent c834a4c commit a08b65f

File tree

2 files changed

+151
-0
lines changed

2 files changed

+151
-0
lines changed

Lib/test/test_pdb.py

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,156 @@ def test_pdb_whatis_command():
574574
(Pdb) continue
575575
"""
576576

577+
def test_pdb_display_command():
578+
"""Test display command
579+
580+
>>> def test_function():
581+
... a = 0
582+
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
583+
... a = 1
584+
... a = 2
585+
... a = 3
586+
... a = 4
587+
588+
>>> with PdbTestInput([ # doctest: +ELLIPSIS
589+
... 'display a',
590+
... 'n',
591+
... 'display',
592+
... 'undisplay a',
593+
... 'n',
594+
... 'display a',
595+
... 'undisplay',
596+
... 'display a < 1',
597+
... 'n',
598+
... 'continue',
599+
... ]):
600+
... test_function()
601+
> <doctest test.test_pdb.test_pdb_display_command[0]>(4)test_function()
602+
-> a = 1
603+
(Pdb) display a
604+
display a: 0
605+
(Pdb) n
606+
> <doctest test.test_pdb.test_pdb_display_command[0]>(5)test_function()
607+
-> a = 2
608+
display a: 1 [old: 0]
609+
(Pdb) display
610+
Currently displaying:
611+
a: 1
612+
(Pdb) undisplay a
613+
(Pdb) n
614+
> <doctest test.test_pdb.test_pdb_display_command[0]>(6)test_function()
615+
-> a = 3
616+
(Pdb) display a
617+
display a: 2
618+
(Pdb) undisplay
619+
(Pdb) display a < 1
620+
display a < 1: False
621+
(Pdb) n
622+
> <doctest test.test_pdb.test_pdb_display_command[0]>(7)test_function()
623+
-> a = 4
624+
(Pdb) continue
625+
"""
626+
627+
def test_pdb_alias_command():
628+
"""Test alias command
629+
630+
>>> class A:
631+
... def __init__(self):
632+
... self.attr1 = 10
633+
... self.attr2 = 'str'
634+
... def method(self):
635+
... pass
636+
637+
>>> def test_function():
638+
... o = A()
639+
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
640+
... o.method()
641+
642+
>>> with PdbTestInput([ # doctest: +ELLIPSIS
643+
... 'alias pi for k in %1.__dict__.keys(): print(f"%1.{k} = {%1.__dict__[k]}")',
644+
... 'alias ps pi self',
645+
... 'pi o',
646+
... 's',
647+
... 'ps',
648+
... 'continue',
649+
... ]):
650+
... test_function()
651+
> <doctest test.test_pdb.test_pdb_alias_command[1]>(4)test_function()
652+
-> o.method()
653+
(Pdb) alias pi for k in %1.__dict__.keys(): print(f"%1.{k} = {%1.__dict__[k]}")
654+
(Pdb) alias ps pi self
655+
(Pdb) pi o
656+
o.attr1 = 10
657+
o.attr2 = str
658+
(Pdb) s
659+
--Call--
660+
> <doctest test.test_pdb.test_pdb_alias_command[0]>(5)method()
661+
-> def method(self):
662+
(Pdb) ps
663+
self.attr1 = 10
664+
self.attr2 = str
665+
(Pdb) continue
666+
"""
667+
668+
def test_pdb_where_command():
669+
"""Test where command
670+
671+
>>> def g():
672+
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
673+
674+
>>> def f():
675+
... g();
676+
677+
>>> def test_function():
678+
... f()
679+
680+
>>> with PdbTestInput([ # doctest: +ELLIPSIS
681+
... 'w',
682+
... 'where',
683+
... 'u',
684+
... 'w',
685+
... 'continue',
686+
... ]):
687+
... test_function()
688+
--Return--
689+
> <doctest test.test_pdb.test_pdb_where_command[0]>(2)g()->None
690+
-> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
691+
(Pdb) w
692+
...
693+
<doctest test.test_pdb.test_pdb_where_command[3]>(8)<module>()
694+
-> test_function()
695+
<doctest test.test_pdb.test_pdb_where_command[2]>(2)test_function()
696+
-> f()
697+
<doctest test.test_pdb.test_pdb_where_command[1]>(2)f()
698+
-> g();
699+
> <doctest test.test_pdb.test_pdb_where_command[0]>(2)g()->None
700+
-> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
701+
(Pdb) where
702+
...
703+
<doctest test.test_pdb.test_pdb_where_command[3]>(8)<module>()
704+
-> test_function()
705+
<doctest test.test_pdb.test_pdb_where_command[2]>(2)test_function()
706+
-> f()
707+
<doctest test.test_pdb.test_pdb_where_command[1]>(2)f()
708+
-> g();
709+
> <doctest test.test_pdb.test_pdb_where_command[0]>(2)g()->None
710+
-> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
711+
(Pdb) u
712+
> <doctest test.test_pdb.test_pdb_where_command[1]>(2)f()
713+
-> g();
714+
(Pdb) w
715+
...
716+
<doctest test.test_pdb.test_pdb_where_command[3]>(8)<module>()
717+
-> test_function()
718+
<doctest test.test_pdb.test_pdb_where_command[2]>(2)test_function()
719+
-> f()
720+
> <doctest test.test_pdb.test_pdb_where_command[1]>(2)f()
721+
-> g();
722+
<doctest test.test_pdb.test_pdb_where_command[0]>(2)g()->None
723+
-> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
724+
(Pdb) continue
725+
"""
726+
577727
def test_post_mortem():
578728
"""Test post mortem traceback debugging.
579729
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve test coverage on :mod:`pdb`.

0 commit comments

Comments
 (0)