11# A test suite for pdb; not very comprehensive at the moment.
22
33import doctest
4+ import os
45import pdb
56import sys
7+ import tempfile
68import types
79import unittest
810import subprocess
@@ -34,7 +36,7 @@ def test_pdb_displayhook():
3436 """This tests the custom displayhook for pdb.
3537
3638 >>> def test_function(foo, bar):
37- ... import pdb; pdb.Pdb(nosigint=True).set_trace()
39+ ... import pdb; pdb.Pdb(nosigint=True, readrc=False ).set_trace()
3840 ... pass
3941
4042 >>> with PdbTestInput([
@@ -74,7 +76,7 @@ def test_pdb_basic_commands():
7476 ... return foo.upper()
7577
7678 >>> def test_function():
77- ... import pdb; pdb.Pdb(nosigint=True).set_trace()
79+ ... import pdb; pdb.Pdb(nosigint=True, readrc=False ).set_trace()
7880 ... ret = test_function_2('baz')
7981 ... print(ret)
8082
@@ -173,7 +175,7 @@ def test_pdb_breakpoint_commands():
173175 """Test basic commands related to breakpoints.
174176
175177 >>> def test_function():
176- ... import pdb; pdb.Pdb(nosigint=True).set_trace()
178+ ... import pdb; pdb.Pdb(nosigint=True, readrc=False ).set_trace()
177179 ... print(1)
178180 ... print(2)
179181 ... print(3)
@@ -305,7 +307,7 @@ def test_list_commands():
305307 ... return foo
306308
307309 >>> def test_function():
308- ... import pdb; pdb.Pdb(nosigint=True).set_trace()
310+ ... import pdb; pdb.Pdb(nosigint=True, readrc=False ).set_trace()
309311 ... ret = test_function_2('baz')
310312
311313 >>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
@@ -328,7 +330,7 @@ def test_list_commands():
328330 -> ret = test_function_2('baz')
329331 (Pdb) list
330332 1 def test_function():
331- 2 import pdb; pdb.Pdb(nosigint=True).set_trace()
333+ 2 import pdb; pdb.Pdb(nosigint=True, readrc=False ).set_trace()
332334 3 -> ret = test_function_2('baz')
333335 [EOF]
334336 (Pdb) step
@@ -391,7 +393,7 @@ def test_post_mortem():
391393 ... print('Exception!')
392394
393395 >>> def test_function():
394- ... import pdb; pdb.Pdb(nosigint=True).set_trace()
396+ ... import pdb; pdb.Pdb(nosigint=True, readrc=False ).set_trace()
395397 ... test_function_2()
396398 ... print('Not reached.')
397399
@@ -424,7 +426,7 @@ def test_post_mortem():
424426 -> 1/0
425427 (Pdb) list
426428 1 def test_function():
427- 2 import pdb; pdb.Pdb(nosigint=True).set_trace()
429+ 2 import pdb; pdb.Pdb(nosigint=True, readrc=False ).set_trace()
428430 3 -> test_function_2()
429431 4 print('Not reached.')
430432 [EOF]
@@ -448,7 +450,7 @@ def test_pdb_skip_modules():
448450
449451 >>> def skip_module():
450452 ... import string
451- ... import pdb; pdb.Pdb(skip=['stri*'], nosigint=True).set_trace()
453+ ... import pdb; pdb.Pdb(skip=['stri*'], nosigint=True, readrc=False ).set_trace()
452454 ... string.capwords('FOO')
453455
454456 >>> with PdbTestInput([
@@ -477,7 +479,7 @@ def test_pdb_skip_modules_with_callback():
477479 >>> def skip_module():
478480 ... def callback():
479481 ... return None
480- ... import pdb; pdb.Pdb(skip=['module_to_skip*'], nosigint=True).set_trace()
482+ ... import pdb; pdb.Pdb(skip=['module_to_skip*'], nosigint=True, readrc=False ).set_trace()
481483 ... mod.foo_pony(callback)
482484
483485 >>> with PdbTestInput([
@@ -518,7 +520,7 @@ def test_pdb_continue_in_bottomframe():
518520 """Test that "continue" and "next" work properly in bottom frame (issue #5294).
519521
520522 >>> def test_function():
521- ... import pdb, sys; inst = pdb.Pdb(nosigint=True)
523+ ... import pdb, sys; inst = pdb.Pdb(nosigint=True, readrc=False )
522524 ... inst.set_trace()
523525 ... inst.botframe = sys._getframe() # hackery to get the right botframe
524526 ... print(1)
@@ -558,7 +560,7 @@ def test_pdb_continue_in_bottomframe():
558560
559561def pdb_invoke (method , arg ):
560562 """Run pdb.method(arg)."""
561- getattr (pdb .Pdb (nosigint = True ), method )(arg )
563+ getattr (pdb .Pdb (nosigint = True , readrc = False ), method )(arg )
562564
563565
564566def test_pdb_run_with_incorrect_argument ():
@@ -607,7 +609,7 @@ def test_next_until_return_at_return_event():
607609 ... x = 2
608610
609611 >>> def test_function():
610- ... import pdb; pdb.Pdb(nosigint=True).set_trace()
612+ ... import pdb; pdb.Pdb(nosigint=True, readrc=False ).set_trace()
611613 ... test_function_2()
612614 ... test_function_2()
613615 ... test_function_2()
@@ -673,7 +675,7 @@ def test_pdb_next_command_for_generator():
673675 ... yield 2
674676
675677 >>> def test_function():
676- ... import pdb; pdb.Pdb(nosigint=True).set_trace()
678+ ... import pdb; pdb.Pdb(nosigint=True, readrc=False ).set_trace()
677679 ... it = test_gen()
678680 ... try:
679681 ... if next(it) != 0:
@@ -733,7 +735,7 @@ def test_pdb_return_command_for_generator():
733735 ... yield 2
734736
735737 >>> def test_function():
736- ... import pdb; pdb.Pdb(nosigint=True).set_trace()
738+ ... import pdb; pdb.Pdb(nosigint=True, readrc=False ).set_trace()
737739 ... it = test_gen()
738740 ... try:
739741 ... if next(it) != 0:
@@ -788,7 +790,7 @@ def test_pdb_until_command_for_generator():
788790 ... yield 2
789791
790792 >>> def test_function():
791- ... import pdb; pdb.Pdb(nosigint=True).set_trace()
793+ ... import pdb; pdb.Pdb(nosigint=True, readrc=False ).set_trace()
792794 ... for i in test_gen():
793795 ... print(i)
794796 ... print("finished")
@@ -830,7 +832,7 @@ def test_pdb_next_command_in_generator_for_loop():
830832 ... return 1
831833
832834 >>> def test_function():
833- ... import pdb; pdb.Pdb(nosigint=True).set_trace()
835+ ... import pdb; pdb.Pdb(nosigint=True, readrc=False ).set_trace()
834836 ... for i in test_gen():
835837 ... print('value', i)
836838 ... x = 123
@@ -875,7 +877,7 @@ def test_pdb_next_command_subiterator():
875877 ... return x
876878
877879 >>> def test_function():
878- ... import pdb; pdb.Pdb(nosigint=True).set_trace()
880+ ... import pdb; pdb.Pdb(nosigint=True, readrc=False ).set_trace()
879881 ... for i in test_gen():
880882 ... print('value', i)
881883 ... x = 123
@@ -1025,7 +1027,7 @@ def test_issue13210(self):
10251027 import pdb
10261028
10271029 def start_pdb():
1028- pdb.Pdb().set_trace()
1030+ pdb.Pdb(readrc=False ).set_trace()
10291031 x = 1
10301032 y = 1
10311033
@@ -1054,13 +1056,47 @@ def test_issue16180(self):
10541056 .format (expected , stdout ))
10551057
10561058
1059+ def test_readrc_kwarg (self ):
1060+ save_home = os .environ ['HOME' ]
1061+ save_dir = os .getcwd ()
1062+ script = """import pdb; pdb.Pdb(readrc=False).set_trace()
1063+
1064+ print('hello')
1065+ """
1066+ del os .environ ['HOME' ]
1067+ try :
1068+ with tempfile .TemporaryDirectory () as dirname :
1069+ os .chdir (dirname )
1070+ with open ('.pdbrc' , 'w' ) as f :
1071+ f .write ("invalid\n " )
1072+
1073+ with open ('main.py' , 'w' ) as f :
1074+ f .write (script )
1075+
1076+ cmd = [sys .executable , 'main.py' ]
1077+ proc = subprocess .Popen (
1078+ cmd ,
1079+ stdout = subprocess .PIPE ,
1080+ stdin = subprocess .PIPE ,
1081+ stderr = subprocess .PIPE ,
1082+ )
1083+ self .addCleanup (proc .stdout .close )
1084+ self .addCleanup (proc .stderr .close )
1085+ stdout , stderr = proc .communicate (b'q\n ' )
1086+ self .assertNotIn ("NameError: name 'invalid' is not defined" ,
1087+ stdout .decode ())
1088+
1089+ finally :
1090+ os .environ ['HOME' ] = save_home
1091+ os .chdir (save_dir )
1092+
10571093 def tearDown (self ):
10581094 support .unlink (support .TESTFN )
10591095
10601096
10611097def load_tests (* args ):
10621098 from test import test_pdb
1063- suites = [unittest .makeSuite (PdbTestCase ), doctest . DocTestSuite ( test_pdb ) ]
1099+ suites = [unittest .makeSuite (PdbTestCase )]
10641100 return unittest .TestSuite (suites )
10651101
10661102
0 commit comments