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

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 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 >>> with PdbTestInput(['x', 'continue']): 590 >>> with PdbTestInput(['x', 'continue']):
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
600 def dedent_to_bytes(lines):
601 """Dedent 'lines' and return it as a bytes object."""
602 return str.encode(textwrap.dedent(lines))
603
599 class PdbTestCase(unittest.TestCase): 604 class PdbTestCase(unittest.TestCase):
605
606 def run_pdb(self, script, commands):
607 """Run 'script' lines with pdb and the pdb 'commands'."""
608 filename = 'main.py'
609 with open(filename, 'wb') as f:
610 f.write(dedent_to_bytes(script))
611 cmd = [sys.executable, '-m', 'pdb', filename]
612 proc = subprocess.Popen(cmd,
613 stdout=subprocess.PIPE,
614 stdin=subprocess.PIPE,
615 stderr=subprocess.STDOUT,
616 )
617 self.addCleanup(proc.stdout.close)
618 stdout, stderr = proc.communicate(dedent_to_bytes(commands))
619 stdout = stdout and bytes.decode(stdout)
620 stderr = stderr and bytes.decode(stderr)
621 return stdout, stderr
600 622
601 def test_issue7964(self): 623 def test_issue7964(self):
602 # open the file as binary so we can force \r\n newline 624 # open the file as binary so we can force \r\n newline
603 with open(support.TESTFN, 'wb') as f: 625 with open(support.TESTFN, 'wb') as f:
604 f.write(b'print("testing my pdb")\r\n') 626 f.write(b'print("testing my pdb")\r\n')
605 cmd = [sys.executable, '-m', 'pdb', support.TESTFN] 627 cmd = [sys.executable, '-m', 'pdb', support.TESTFN]
606 proc = subprocess.Popen(cmd, 628 proc = subprocess.Popen(cmd,
607 stdout=subprocess.PIPE, 629 stdout=subprocess.PIPE,
608 stdin=subprocess.PIPE, 630 stdin=subprocess.PIPE,
609 stderr=subprocess.STDOUT, 631 stderr=subprocess.STDOUT,
610 ) 632 )
611 self.addCleanup(proc.stdout.close) 633 self.addCleanup(proc.stdout.close)
612 stdout, stderr = proc.communicate(b'quit\n') 634 stdout, stderr = proc.communicate(b'quit\n')
613 self.assertNotIn(b'SyntaxError', stdout, 635 self.assertNotIn(b'SyntaxError', stdout,
614 "Got a syntax error running test script under PDB") 636 "Got a syntax error running test script under PDB")
637
638 def test_issueXXX(self):
639 script = """
640 from bar import bar
641
642 def foo():
643 bar()
644
645 def nope():
646 pass
647
648 def foobar():
649 foo()
650 nope()
651
652 foobar()
653 """
654 commands = """
655 from bar import bar
656 break bar
657 continue
658 step
659 step
660 quit
661 """
662 bar = """
663 def bar():
664 print('1')
665 """
666 with open('bar.py', 'wb') as f:
667 f.write(dedent_to_bytes(bar))
668 stdout, stderr = self.run_pdb(script, commands)
669 self.assertIn('main.py(5)foo()->None', stdout.split('\n')[-3],
670 'Fail to step in the caller after a return')
615 671
616 def tearDown(self): 672 def tearDown(self):
617 support.unlink(support.TESTFN) 673 support.unlink(support.TESTFN)
618 674
619 675
620 def test_main(): 676 def test_main():
621 from test import test_pdb 677 from test import test_pdb
622 support.run_doctest(test_pdb, verbosity=True) 678 support.run_doctest(test_pdb, verbosity=True)
623 support.run_unittest(PdbTestCase) 679 support.run_unittest(PdbTestCase)
624 680
625 681
626 if __name__ == '__main__': 682 if __name__ == '__main__':
627 test_main() 683 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+