Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(15)

Side by Side Diff: Lib/test/test_pdb.py

Issue 13183: pdb skips frames after hitting a breakpoint and running step
Patch Set: Created 8 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/bdb.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # A test suite for pdb; not very comprehensive at the moment. 1 # A test suite for pdb; not very comprehensive at the moment.
2 2
3 import imp 3 import imp
4 import pdb 4 import pdb
5 import sys 5 import sys
6 import unittest 6 import unittest
7 import subprocess 7 import subprocess
8 import textwrap
8 9
9 from test import support 10 from test import support
10 # This little helper class is essential for testing pdb under doctest. 11 # This little helper class is essential for testing pdb under doctest.
11 from test.test_doctest import _FakeInput 12 from test.test_doctest import _FakeInput
12 13
13 14
14 class PdbTestInput(object): 15 class PdbTestInput(object):
15 """Context manager that makes testing Pdb in doctests easier.""" 16 """Context manager that makes testing Pdb in doctests easier."""
16 17
17 def __init__(self, input): 18 def __init__(self, input):
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 ... x=0 591 ... x=0
591 ... pdb_invoke('runeval', compile('x+1', '<string>', 'eval')) 592 ... pdb_invoke('runeval', compile('x+1', '<string>', 'eval'))
592 > <string>(1)<module>()->None 593 > <string>(1)<module>()->None
593 (Pdb) x 594 (Pdb) x
594 1 595 1
595 (Pdb) continue 596 (Pdb) continue
596 """ 597 """
597 598
598 599
599 class PdbTestCase(unittest.TestCase): 600 class PdbTestCase(unittest.TestCase):
601
602 def run_pdb(self, script, commands):
603 """Run 'script' lines with pdb and the pdb 'commands'."""
604 filename = 'main.py'
605 with open(filename, 'w') as f:
606 f.write(textwrap.dedent(script))
607 cmd = [sys.executable, '-m', 'pdb', filename]
608 stdout = stderr = None
609 with subprocess.Popen(cmd, stdout=subprocess.PIPE,
610 stdin=subprocess.PIPE,
611 stderr=subprocess.STDOUT,
612 ) as proc:
613 stdout, stderr = proc.communicate(str.encode(commands))
614 stdout = stdout and bytes.decode(stdout)
615 stderr = stderr and bytes.decode(stderr)
616 return stdout, stderr
600 617
601 def test_issue7964(self): 618 def test_issue7964(self):
602 # open the file as binary so we can force \r\n newline 619 # open the file as binary so we can force \r\n newline
603 with open(support.TESTFN, 'wb') as f: 620 with open(support.TESTFN, 'wb') as f:
604 f.write(b'print("testing my pdb")\r\n') 621 f.write(b'print("testing my pdb")\r\n')
605 cmd = [sys.executable, '-m', 'pdb', support.TESTFN] 622 cmd = [sys.executable, '-m', 'pdb', support.TESTFN]
606 proc = subprocess.Popen(cmd, 623 proc = subprocess.Popen(cmd,
607 stdout=subprocess.PIPE, 624 stdout=subprocess.PIPE,
608 stdin=subprocess.PIPE, 625 stdin=subprocess.PIPE,
609 stderr=subprocess.STDOUT, 626 stderr=subprocess.STDOUT,
610 ) 627 )
611 self.addCleanup(proc.stdout.close) 628 self.addCleanup(proc.stdout.close)
612 stdout, stderr = proc.communicate(b'quit\n') 629 stdout, stderr = proc.communicate(b'quit\n')
613 self.assertNotIn(b'SyntaxError', stdout, 630 self.assertNotIn(b'SyntaxError', stdout,
614 "Got a syntax error running test script under PDB") 631 "Got a syntax error running test script under PDB")
632
633 def test_issue13183(self):
634 script = """
635 from bar import bar
636
637 def foo():
638 bar()
639
640 def nope():
641 pass
642
643 def foobar():
644 foo()
645 nope()
646
647 foobar()
648 """
649 commands = """
650 from bar import bar
651 break bar
652 continue
653 step
654 step
655 quit
656 """
657 bar = """
658 def bar():
659 print('1')
660 """
661 with open('bar.py', 'w') as f:
662 f.write(textwrap.dedent(bar))
663 stdout, stderr = self.run_pdb(script, commands)
664 self.assertIn('main.py(5)foo()->None', stdout.split('\n')[-3],
665 'Fail to step into the caller after a return')
615 666
616 def tearDown(self): 667 def tearDown(self):
617 support.unlink(support.TESTFN) 668 support.unlink(support.TESTFN)
618 669
619 670
620 def test_main(): 671 def test_main():
621 from test import test_pdb 672 from test import test_pdb
622 support.run_doctest(test_pdb, verbosity=True) 673 support.run_doctest(test_pdb, verbosity=True)
623 support.run_unittest(PdbTestCase) 674 support.run_unittest(PdbTestCase)
624 675
625 676
626 if __name__ == '__main__': 677 if __name__ == '__main__':
627 test_main() 678 test_main()
OLDNEW
« no previous file with comments | « Lib/bdb.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+