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

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

Issue 14285: Traceback wrong on ImportError while executing a package
Left Patch Set: Created 4 years, 6 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:
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_cmd_line_script.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
(no file at all)
1 # Test the runpy module 1 # Test the runpy module
2 import unittest 2 import unittest
3 import os 3 import os
4 import os.path 4 import os.path
5 import sys 5 import sys
6 import re 6 import re
7 import tempfile 7 import tempfile
8 import importlib, importlib.machinery, importlib.util 8 import importlib, importlib.machinery, importlib.util
9 import py_compile 9 import py_compile
10 from test.support import ( 10 from test.support import (
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 else: 190 else:
191 self.fail("Expected import error for " + mod_name) 191 self.fail("Expected import error for " + mod_name)
192 192
193 def test_invalid_names(self): 193 def test_invalid_names(self):
194 # Builtin module 194 # Builtin module
195 self.expect_import_error("sys") 195 self.expect_import_error("sys")
196 # Non-existent modules 196 # Non-existent modules
197 self.expect_import_error("sys.imp.eric") 197 self.expect_import_error("sys.imp.eric")
198 self.expect_import_error("os.path.half") 198 self.expect_import_error("os.path.half")
199 self.expect_import_error("a.bee") 199 self.expect_import_error("a.bee")
200 # Relative names not allowed
200 self.expect_import_error(".howard") 201 self.expect_import_error(".howard")
201 self.expect_import_error("..eaten") 202 self.expect_import_error("..eaten")
203 self.expect_import_error(".test_runpy")
204 self.expect_import_error(".unittest")
202 # Package without __main__.py 205 # Package without __main__.py
203 self.expect_import_error("multiprocessing") 206 self.expect_import_error("multiprocessing")
204 207
205 def test_library_module(self): 208 def test_library_module(self):
206 self.assertEqual(run_module("runpy")["__name__"], "runpy") 209 self.assertEqual(run_module("runpy")["__name__"], "runpy")
207 210
208 def _add_pkg_dir(self, pkg_dir, namespace=False): 211 def _add_pkg_dir(self, pkg_dir, namespace=False):
209 os.mkdir(pkg_dir) 212 os.mkdir(pkg_dir)
210 if namespace: 213 if namespace:
211 return None 214 return None
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 with self.subTest(name): 456 with self.subTest(name):
454 source = "raise {0}('{0} in __init__.py.')".format(name) 457 source = "raise {0}('{0} in __init__.py.')".format(name)
455 with open(init, "wt", encoding="ascii") as mod_file: 458 with open(init, "wt", encoding="ascii") as mod_file:
456 mod_file.write(source) 459 mod_file.write(source)
457 try: 460 try:
458 run_module(mod_name) 461 run_module(mod_name)
459 except exception as err: 462 except exception as err:
460 self.assertNotIn("finding spec", format(err)) 463 self.assertNotIn("finding spec", format(err))
461 else: 464 else:
462 self.fail("Nothing raised; expected {}".format(name)) 465 self.fail("Nothing raised; expected {}".format(name))
466 try:
467 run_module(mod_name + ".submodule")
468 except exception as err:
469 self.assertNotIn("finding spec", format(err))
470 else:
471 self.fail("Nothing raised; expected {}".format(name))
463 472
464 def test_run_package_in_namespace_package(self): 473 def test_run_package_in_namespace_package(self):
465 for depth in range(1, 4): 474 for depth in range(1, 4):
466 if verbose > 1: print("Testing package depth:", depth) 475 if verbose > 1: print("Testing package depth:", depth)
467 self._check_package(depth, parent_namespaces=True) 476 self._check_package(depth, parent_namespaces=True)
468 477
469 def test_run_namespace_package(self): 478 def test_run_namespace_package(self):
470 for depth in range(1, 4): 479 for depth in range(1, 4):
471 if verbose > 1: print("Testing package depth:", depth) 480 if verbose > 1: print("Testing package depth:", depth)
472 self._check_package(depth, namespace=True) 481 self._check_package(depth, namespace=True)
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 f.write(""" 713 f.write("""
705 #coding:latin1 714 #coding:latin1
706 s = "non-ASCII: h\xe9" 715 s = "non-ASCII: h\xe9"
707 """) 716 """)
708 result = run_path(filename) 717 result = run_path(filename)
709 self.assertEqual(result['s'], "non-ASCII: h\xe9") 718 self.assertEqual(result['s'], "non-ASCII: h\xe9")
710 719
711 720
712 if __name__ == "__main__": 721 if __name__ == "__main__":
713 unittest.main() 722 unittest.main()
LEFTRIGHT

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