diff options
author | Brian Curtin <brian@python.org> | 2012-04-16 05:10:17 (GMT) |
---|---|---|
committer | Brian Curtin <brian@python.org> | 2012-04-16 05:10:17 (GMT) |
commit | b206a80dab519256a348e9800c4e52659d948359 (patch) | |
tree | 7e26ffa873c4937b70d713f9f7d76a6a0b0920c4 /Lib/test/test_import.py | |
parent | 15439817bf77a6e3e68f7101fbe9723468613aff (diff) | |
download | cpython-b206a80dab519256a348e9800c4e52659d948359.zip cpython-b206a80dab519256a348e9800c4e52659d948359.tar.gz cpython-b206a80dab519256a348e9800c4e52659d948359.tar.bz2 |
Fix #10854. Make use of the new path and name attributes on ImportError
for extension modules on Windows.
Diffstat (limited to 'Lib/test/test_import.py')
-rw-r--r-- | Lib/test/test_import.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py index 8510eb8..5053d49 100644 --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -337,6 +337,24 @@ 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 + 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.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 |