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

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

Issue 14285: Traceback wrong on ImportError while executing a package
Patch Set: Created 4 years, 2 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/runpy.py ('k') | Lib/test/test_runpy.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.*' 430 ('builtins.x.y', br'Error while finding spec.*AttributeError'),
431 br'ImportError.*No module named.*not a package'),
432 ('os.path', br'loader.*cannot handle'), 431 ('os.path', br'loader.*cannot handle'),
433 ('importlib', br'No module named.*' 432 ('importlib', br'No module named.*'
434 br'is a package and cannot be directly executed'), 433 br'is a package and cannot be directly executed'),
435 ('importlib.nonexistant', br'No module named'), 434 ('importlib.nonexistant', br'No module named'),
436 ) 435 )
437 for name, regex in tests: 436 for name, regex in tests:
438 with self.subTest(name): 437 with self.subTest(name):
439 rc, _, err = assert_python_failure('-m', name) 438 rc, _, err = assert_python_failure('-m', name)
440 self.assertEqual(rc, 1) 439 self.assertEqual(rc, 1)
441 self.assertRegex(err, regex) 440 self.assertRegex(err, regex)
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 text = stderr.decode('ascii') 523 text = stderr.decode('ascii')
525 self.assertEqual(text, "some text") 524 self.assertEqual(text, "some text")
526 525
527 526
528 def test_main(): 527 def test_main():
529 support.run_unittest(CmdLineTest) 528 support.run_unittest(CmdLineTest)
530 support.reap_children() 529 support.reap_children()
531 530
532 if __name__ == '__main__': 531 if __name__ == '__main__':
533 test_main() 532 test_main()
OLDNEW
« no previous file with comments | « Lib/runpy.py ('k') | Lib/test/test_runpy.py » ('j') | no next file with comments »

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