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

Delta Between Two Patch Sets: Lib/test/test_pdb.py

Issue 13183: pdb skips frames after hitting a breakpoint and running step
Left Patch Set: Created 8 years, 4 months ago
Right Patch Set: Created 8 years, 4 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/bdb.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 import textwrap
9 9
10 from test import support 10 from test import support
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 >>> with PdbTestInput(['x', 'continue']): 590 >>> with PdbTestInput(['x', 'continue']):
591 ... x=0 591 ... x=0
592 ... pdb_invoke('runeval', compile('x+1', '<string>', 'eval')) 592 ... pdb_invoke('runeval', compile('x+1', '<string>', 'eval'))
593 > <string>(1)<module>()->None 593 > <string>(1)<module>()->None
594 (Pdb) x 594 (Pdb) x
595 1 595 1
596 (Pdb) continue 596 (Pdb) continue
597 """ 597 """
598 598
599 599
600 def dedent_to_bytes(lines):
601 """Dedent 'lines' and return it as a bytes object."""
602 return str.encode(textwrap.dedent(lines))
603
604 class PdbTestCase(unittest.TestCase): 600 class PdbTestCase(unittest.TestCase):
605 601
606 def run_pdb(self, script, commands): 602 def run_pdb(self, script, commands):
607 """Run 'script' lines with pdb and the pdb 'commands'.""" 603 """Run 'script' lines with pdb and the pdb 'commands'."""
608 filename = 'main.py' 604 filename = 'main.py'
609 with open(filename, 'wb') as f: 605 with open(filename, 'w') as f:
610 f.write(dedent_to_bytes(script)) 606 f.write(textwrap.dedent(script))
611 cmd = [sys.executable, '-m', 'pdb', filename] 607 cmd = [sys.executable, '-m', 'pdb', filename]
612 proc = subprocess.Popen(cmd, 608 stdout = stderr = None
613 stdout=subprocess.PIPE, 609 with subprocess.Popen(cmd, stdout=subprocess.PIPE,
614 stdin=subprocess.PIPE, 610 stdin=subprocess.PIPE,
615 stderr=subprocess.STDOUT, 611 stderr=subprocess.STDOUT,
616 ) 612 ) as proc:
617 self.addCleanup(proc.stdout.close) 613 stdout, stderr = proc.communicate(str.encode(commands))
618 stdout, stderr = proc.communicate(dedent_to_bytes(commands))
619 stdout = stdout and bytes.decode(stdout) 614 stdout = stdout and bytes.decode(stdout)
620 stderr = stderr and bytes.decode(stderr) 615 stderr = stderr and bytes.decode(stderr)
621 return stdout, stderr 616 return stdout, stderr
622 617
623 def test_issue7964(self): 618 def test_issue7964(self):
624 # 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
625 with open(support.TESTFN, 'wb') as f: 620 with open(support.TESTFN, 'wb') as f:
626 f.write(b'print("testing my pdb")\r\n') 621 f.write(b'print("testing my pdb")\r\n')
627 cmd = [sys.executable, '-m', 'pdb', support.TESTFN] 622 cmd = [sys.executable, '-m', 'pdb', support.TESTFN]
628 proc = subprocess.Popen(cmd, 623 proc = subprocess.Popen(cmd,
629 stdout=subprocess.PIPE, 624 stdout=subprocess.PIPE,
630 stdin=subprocess.PIPE, 625 stdin=subprocess.PIPE,
631 stderr=subprocess.STDOUT, 626 stderr=subprocess.STDOUT,
632 ) 627 )
633 self.addCleanup(proc.stdout.close) 628 self.addCleanup(proc.stdout.close)
634 stdout, stderr = proc.communicate(b'quit\n') 629 stdout, stderr = proc.communicate(b'quit\n')
635 self.assertNotIn(b'SyntaxError', stdout, 630 self.assertNotIn(b'SyntaxError', stdout,
636 "Got a syntax error running test script under PDB") 631 "Got a syntax error running test script under PDB")
637 632
638 def test_issueXXX(self): 633 def test_issue13183(self):
639 script = """ 634 script = """
640 from bar import bar 635 from bar import bar
641 636
642 def foo(): 637 def foo():
643 bar() 638 bar()
644 639
645 def nope(): 640 def nope():
646 pass 641 pass
647 642
648 def foobar(): 643 def foobar():
649 foo() 644 foo()
650 nope() 645 nope()
651 646
652 foobar() 647 foobar()
653 """ 648 """
654 commands = """ 649 commands = """
655 from bar import bar 650 from bar import bar
656 break bar 651 break bar
657 continue 652 continue
658 step 653 step
659 step 654 step
660 quit 655 quit
661 """ 656 """
662 bar = """ 657 bar = """
663 def bar(): 658 def bar():
664 print('1') 659 print('1')
665 """ 660 """
666 with open('bar.py', 'wb') as f: 661 with open('bar.py', 'w') as f:
667 f.write(dedent_to_bytes(bar)) 662 f.write(textwrap.dedent(bar))
668 stdout, stderr = self.run_pdb(script, commands) 663 stdout, stderr = self.run_pdb(script, commands)
669 self.assertIn('main.py(5)foo()->None', stdout.split('\n')[-3], 664 self.assertIn('main.py(5)foo()->None', stdout.split('\n')[-3],
670 'Fail to step in the caller after a return') 665 'Fail to step into the caller after a return')
671 666
672 def tearDown(self): 667 def tearDown(self):
673 support.unlink(support.TESTFN) 668 support.unlink(support.TESTFN)
674 669
675 670
676 def test_main(): 671 def test_main():
677 from test import test_pdb 672 from test import test_pdb
678 support.run_doctest(test_pdb, verbosity=True) 673 support.run_doctest(test_pdb, verbosity=True)
679 support.run_unittest(PdbTestCase) 674 support.run_unittest(PdbTestCase)
680 675
681 676
682 if __name__ == '__main__': 677 if __name__ == '__main__':
683 test_main() 678 test_main()
LEFTRIGHT
« Lib/bdb.py ('k') | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

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