OLD | NEW |
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 doctest | 3 import doctest |
4 import pdb | 4 import pdb |
5 import sys | 5 import sys |
6 import types | 6 import types |
7 import unittest | 7 import unittest |
8 import subprocess | 8 import subprocess |
9 import textwrap | 9 import textwrap |
10 | 10 |
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 -> for i in test_gen(): | 907 -> for i in test_gen(): |
908 (Pdb) next | 908 (Pdb) next |
909 > <doctest test.test_pdb.test_pdb_next_command_subiterator[2]>(5)test_functi
on() | 909 > <doctest test.test_pdb.test_pdb_next_command_subiterator[2]>(5)test_functi
on() |
910 -> x = 123 | 910 -> x = 123 |
911 (Pdb) continue | 911 (Pdb) continue |
912 """ | 912 """ |
913 | 913 |
914 | 914 |
915 class PdbTestCase(unittest.TestCase): | 915 class PdbTestCase(unittest.TestCase): |
916 | 916 |
| 917 @unittest.skipUnless(hasattr(subprocess, 'Popen'), "test requires subprocess
.Popen()") |
917 def run_pdb(self, script, commands): | 918 def run_pdb(self, script, commands): |
918 """Run 'script' lines with pdb and the pdb 'commands'.""" | 919 """Run 'script' lines with pdb and the pdb 'commands'.""" |
919 filename = 'main.py' | 920 filename = 'main.py' |
920 with open(filename, 'w') as f: | 921 with open(filename, 'w') as f: |
921 f.write(textwrap.dedent(script)) | 922 f.write(textwrap.dedent(script)) |
922 self.addCleanup(support.unlink, filename) | 923 self.addCleanup(support.unlink, filename) |
923 self.addCleanup(support.rmtree, '__pycache__') | 924 self.addCleanup(support.rmtree, '__pycache__') |
924 cmd = [sys.executable, '-m', 'pdb', filename] | 925 cmd = [sys.executable, '-m', 'pdb', filename] |
925 stdout = stderr = None | 926 stdout = stderr = None |
926 with subprocess.Popen(cmd, stdout=subprocess.PIPE, | 927 with subprocess.Popen(cmd, stdout=subprocess.PIPE, |
(...skipping 28 matching lines...) Expand all Loading... |
955 def bar(): | 956 def bar(): |
956 pass | 957 pass |
957 | 958 |
958 def quux(): | 959 def quux(): |
959 pass | 960 pass |
960 """, | 961 """, |
961 'bar', | 962 'bar', |
962 ('bar', 4), | 963 ('bar', 4), |
963 ) | 964 ) |
964 | 965 |
| 966 @unittest.skipUnless(hasattr(subprocess, 'Popen'), "test requires subprocess
.Popen()") |
965 def test_issue7964(self): | 967 def test_issue7964(self): |
966 # open the file as binary so we can force \r\n newline | 968 # open the file as binary so we can force \r\n newline |
967 with open(support.TESTFN, 'wb') as f: | 969 with open(support.TESTFN, 'wb') as f: |
968 f.write(b'print("testing my pdb")\r\n') | 970 f.write(b'print("testing my pdb")\r\n') |
969 cmd = [sys.executable, '-m', 'pdb', support.TESTFN] | 971 cmd = [sys.executable, '-m', 'pdb', support.TESTFN] |
970 proc = subprocess.Popen(cmd, | 972 proc = subprocess.Popen(cmd, |
971 stdout=subprocess.PIPE, | 973 stdout=subprocess.PIPE, |
972 stdin=subprocess.PIPE, | 974 stdin=subprocess.PIPE, |
973 stderr=subprocess.STDOUT, | 975 stderr=subprocess.STDOUT, |
974 ) | 976 ) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 pass | 1008 pass |
1007 """ | 1009 """ |
1008 with open('bar.py', 'w') as f: | 1010 with open('bar.py', 'w') as f: |
1009 f.write(textwrap.dedent(bar)) | 1011 f.write(textwrap.dedent(bar)) |
1010 self.addCleanup(support.unlink, 'bar.py') | 1012 self.addCleanup(support.unlink, 'bar.py') |
1011 stdout, stderr = self.run_pdb(script, commands) | 1013 stdout, stderr = self.run_pdb(script, commands) |
1012 self.assertTrue( | 1014 self.assertTrue( |
1013 any('main.py(5)foo()->None' in l for l in stdout.splitlines()), | 1015 any('main.py(5)foo()->None' in l for l in stdout.splitlines()), |
1014 'Fail to step into the caller after a return') | 1016 'Fail to step into the caller after a return') |
1015 | 1017 |
| 1018 @unittest.skipUnless(hasattr(subprocess, 'Popen'), "test requires subprocess
.Popen()") |
1016 def test_issue13210(self): | 1019 def test_issue13210(self): |
1017 # invoking "continue" on a non-main thread triggered an exception | 1020 # invoking "continue" on a non-main thread triggered an exception |
1018 # inside signal.signal | 1021 # inside signal.signal |
1019 | 1022 |
1020 # raises SkipTest if python was built without threads | 1023 # raises SkipTest if python was built without threads |
1021 support.import_module('threading') | 1024 support.import_module('threading') |
1022 | 1025 |
1023 with open(support.TESTFN, 'wb') as f: | 1026 with open(support.TESTFN, 'wb') as f: |
1024 f.write(textwrap.dedent(""" | 1027 f.write(textwrap.dedent(""" |
1025 import threading | 1028 import threading |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 | 1063 |
1061 | 1064 |
1062 def load_tests(*args): | 1065 def load_tests(*args): |
1063 from test import test_pdb | 1066 from test import test_pdb |
1064 suites = [unittest.makeSuite(PdbTestCase), doctest.DocTestSuite(test_pdb)] | 1067 suites = [unittest.makeSuite(PdbTestCase), doctest.DocTestSuite(test_pdb)] |
1065 return unittest.TestSuite(suites) | 1068 return unittest.TestSuite(suites) |
1066 | 1069 |
1067 | 1070 |
1068 if __name__ == '__main__': | 1071 if __name__ == '__main__': |
1069 unittest.main() | 1072 unittest.main() |
OLD | NEW |