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