diff options
author | Brett Cannon <brett@python.org> | 2012-04-20 19:22:50 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2012-04-20 19:22:50 (GMT) |
commit | f0434e647aa3e7b82a740be4a820aec951a885ac (patch) | |
tree | ea6c3e0d3b874549cc081a54e0e0c63ac132da38 /Lib | |
parent | 3c23a87e58ba5ba3161eaacae98a49a79e1f2786 (diff) | |
download | cpython-f0434e647aa3e7b82a740be4a820aec951a885ac.zip cpython-f0434e647aa3e7b82a740be4a820aec951a885ac.tar.gz cpython-f0434e647aa3e7b82a740be4a820aec951a885ac.tar.bz2 |
Issue #14599: Generalize a test for ImportError.path and add support
in Python/dynload_shlibs.c.
This should fix the remaining importlib test failure on Windows.
Support in AIX and HP-UX will be in a separate checkin.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_imp.py | 11 | ||||
-rw-r--r-- | Lib/test/test_import.py | 22 |
2 files changed, 11 insertions, 22 deletions
diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py index 432ca41..9fe8f43 100644 --- a/Lib/test/test_imp.py +++ b/Lib/test/test_imp.py @@ -179,6 +179,17 @@ class ImportTests(unittest.TestCase): self.assertRaises(SyntaxError, imp.find_module, "badsyntax_pep3120", [path]) + def test_load_dynamic_ImportError_path(self): + # Issue #1559549 added `name` and `path` attributes to ImportError + # in order to provide better detail. Issue #10854 implemented those + # attributes on import failures of extensions on Windows. + path = 'bogus file path' + name = 'extension' + with self.assertRaises(ImportError) as err: + imp.load_dynamic(name, path) + self.assertIn(path, err.exception.path) + self.assertEqual(name, err.exception.name) + class ReloadTests(unittest.TestCase): diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py index 9e7c5c0..8510eb8 100644 --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -337,28 +337,6 @@ class ImportTests(unittest.TestCase): del sys.path[0] remove_files(TESTFN) - @unittest.skipUnless(sys.platform == "win32", "Windows-specific") - def test_extension_import_fail(self): - # Issue 1559549 added `name` and `path` attributes to ImportError - # in order to provide better detail. Issue 10854 implemented those - # attributes on import failures of extensions on Windows. - debug = True if sys.executable[-6:] == "_d.exe" else False - pkg_name = "extension" - pkg_file = pkg_name + "{}".format("_d.pyd" if debug else ".pyd") - with open(pkg_file, "w"): pass - importlib.invalidate_caches() - try: - with self.assertRaises(ImportError) as err: - import extension - self.assertEqual(err.exception.name, pkg_name) - # The path we get back has the dot-slash, e.g., ".\\extension.pyd" - self.assertIsNotNone(err.exception.path, - 'unexpected None for ImportError.path: ' - '{!r}'.format(err.exception)) - self.assertEqual(os.path.relpath(err.exception.path), pkg_file) - finally: - unlink(pkg_file) - class PycRewritingTests(unittest.TestCase): # Test that the `co_filename` attribute on code objects always points |