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

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

Issue 14285: Traceback wrong on ImportError while executing a package
Left Patch Set: Created 3 years, 9 months ago
Right Patch Set: Created 3 years, 9 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/runpy.py ('k') | Lib/test/test_runpy.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # tests command line execution of scripts 1 # tests command line execution of scripts
2 2
3 import contextlib 3 import contextlib
4 import importlib 4 import importlib
5 import importlib.machinery 5 import importlib.machinery
6 import zipimport 6 import zipimport
7 import unittest 7 import unittest
8 import sys 8 import sys
9 import os 9 import os
10 import os.path 10 import os.path
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 script_name = _make_test_script(pkg_dir, 'other', 420 script_name = _make_test_script(pkg_dir, 'other',
421 "if __name__ == '__main__': raise Va lueError") 421 "if __name__ == '__main__': raise Va lueError")
422 err = self.check_dash_m_failure('test_pkg.other', *example_args) 422 err = self.check_dash_m_failure('test_pkg.other', *example_args)
423 self.assertIn(b'ValueError', err) 423 self.assertIn(b'ValueError', err)
424 424
425 def test_dash_m_errors(self): 425 def test_dash_m_errors(self):
426 # Exercise error reporting for various invalid package executions 426 # Exercise error reporting for various invalid package executions
427 tests = ( 427 tests = (
428 ('builtins', br'No code object available'), 428 ('builtins', br'No code object available'),
429 ('builtins.x', br'Error while finding spec.*AttributeError'), 429 ('builtins.x', br'Error while finding spec.*AttributeError'),
430 ('builtins.x.y', br'Error while finding spec.*AttributeError'), 430 ('builtins.x.y', br'No module named.*not a package'),
431 ('os.path', br'loader.*cannot handle'), 431 ('os.path', br'loader.*cannot handle'),
432 ('importlib', br'No module named.*' 432 ('importlib', br'No module named.*'
433 br'is a package and cannot be directly executed'), 433 br'is a package and cannot be directly executed'),
434 ('importlib.nonexistant', br'No module named'), 434 ('importlib.nonexistant', br'No module named'),
435 ('.unittest', br'Relative module names not supported'),
435 ) 436 )
436 for name, regex in tests: 437 for name, regex in tests:
437 with self.subTest(name): 438 with self.subTest(name):
438 rc, _, err = assert_python_failure('-m', name) 439 rc, _, err = assert_python_failure('-m', name)
439 self.assertEqual(rc, 1) 440 self.assertEqual(rc, 1)
440 self.assertRegex(err, regex) 441 self.assertRegex(err, regex)
441 self.assertNotIn(b'Traceback', err) 442 self.assertNotIn(b'Traceback', err)
442 443
443 def test_dash_m_init_traceback(self): 444 def test_dash_m_init_traceback(self):
444 # These were wrapped in an ImportError and tracebacks were 445 # These were wrapped in an ImportError and tracebacks were
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 text = stderr.decode('ascii') 524 text = stderr.decode('ascii')
524 self.assertEqual(text, "some text") 525 self.assertEqual(text, "some text")
525 526
526 527
527 def test_main(): 528 def test_main():
528 support.run_unittest(CmdLineTest) 529 support.run_unittest(CmdLineTest)
529 support.reap_children() 530 support.reap_children()
530 531
531 if __name__ == '__main__': 532 if __name__ == '__main__':
532 test_main() 533 test_main()
LEFTRIGHT

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