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

Delta Between Two Patch Sets: Lib/test/test_import/__init__.py

Issue 23447: Import fails when doing a circular import involving an `import *`
Left Patch Set: Created 3 years, 9 months ago
Right Patch Set: Created 3 years, 6 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/test/test_import/data/circular_imports/wildcard.py ('k') | Python/ceval.c » ('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 # We import importlib *ASAP* in order to test #15386 1 # We import importlib *ASAP* in order to test #15386
2 import importlib 2 import importlib
3 import importlib.util 3 import importlib.util
4 from importlib._bootstrap_external import _get_sourcefile 4 from importlib._bootstrap_external import _get_sourcefile
5 import builtins 5 import builtins
6 import marshal 6 import marshal
7 import os 7 import os
8 import platform 8 import platform
9 import py_compile 9 import py_compile
10 import random 10 import random
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 stdout, stderr = popen.communicate() 316 stdout, stderr = popen.communicate()
317 self.assertIn(b"ImportError", stdout) 317 self.assertIn(b"ImportError", stdout)
318 318
319 def test_from_import_message_for_nonexistent_module(self): 319 def test_from_import_message_for_nonexistent_module(self):
320 with self.assertRaisesRegex(ImportError, "^No module named 'bogus'"): 320 with self.assertRaisesRegex(ImportError, "^No module named 'bogus'"):
321 from bogus import foo 321 from bogus import foo
322 322
323 def test_from_import_message_for_existing_module(self): 323 def test_from_import_message_for_existing_module(self):
324 with self.assertRaisesRegex(ImportError, "^cannot import name 'bogus'"): 324 with self.assertRaisesRegex(ImportError, "^cannot import name 'bogus'"):
325 from re import bogus 325 from re import bogus
326
327 def test_from_import_AttributeError(self):
328 # Issue #24492: trying to import an attribute that raises an
329 # AttributeError should lead to an ImportError.
330 class AlwaysAttributeError:
331 def __getattr__(self, _):
332 raise AttributeError
333
334 module_name = 'test_from_import_AttributeError'
335 self.addCleanup(unload, module_name)
336 sys.modules[module_name] = AlwaysAttributeError()
337 with self.assertRaises(ImportError):
338 from test_from_import_AttributeError import does_not_exist
326 339
327 340
328 @skip_if_dont_write_bytecode 341 @skip_if_dont_write_bytecode
329 class FilePermissionTests(unittest.TestCase): 342 class FilePermissionTests(unittest.TestCase):
330 # tests for file mode on cached .pyc files 343 # tests for file mode on cached .pyc files
331 344
332 @unittest.skipUnless(os.name == 'posix', 345 @unittest.skipUnless(os.name == 'posix',
333 "test meaningful only on posix systems") 346 "test meaningful only on posix systems")
334 def test_creation_mode(self): 347 def test_creation_mode(self):
335 mask = 0o022 348 mask = 0o022
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 try: 1121 try:
1109 import test.test_import.data.circular_imports.rebinding as rebinding 1122 import test.test_import.data.circular_imports.rebinding as rebinding
1110 except ImportError: 1123 except ImportError:
1111 self.fail('circular import with rebinding of module attribute failed ') 1124 self.fail('circular import with rebinding of module attribute failed ')
1112 from test.test_import.data.circular_imports.subpkg import util 1125 from test.test_import.data.circular_imports.subpkg import util
1113 self.assertIs(util.util, rebinding.util) 1126 self.assertIs(util.util, rebinding.util)
1114 1127
1115 def test_wildcard(self): 1128 def test_wildcard(self):
1116 try: 1129 try:
1117 import test.test_import.data.circular_imports.wildcard 1130 import test.test_import.data.circular_imports.wildcard
1118 except ImportError: 1131 except (ImportError, AttributeError):
1119 self.fail('circular import with a wildcard failed') 1132 self.fail('circular import with a wildcard failed')
1120 1133
1121 1134
1122 if __name__ == '__main__': 1135 if __name__ == '__main__':
1123 # Test needs to be a package, so we can do relative imports. 1136 # Test needs to be a package, so we can do relative imports.
1124 unittest.main() 1137 unittest.main()
LEFTRIGHT

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