diff options
author | Matthias Bussonnier <bussonniermatthias@gmail.com> | 2017-02-15 00:05:25 (GMT) |
---|---|---|
committer | Brett Cannon <brettcannon@users.noreply.github.com> | 2017-02-15 00:05:25 (GMT) |
commit | bc4bed440504597cac47d0a215ee094bfa99ba7e (patch) | |
tree | 0598b2b4776f859b7ab15f70e7cdb65475c5d8c1 /Lib/test/test_import | |
parent | 5ec08cea9574cf53c985af5dbed6bc3d56ff58b7 (diff) | |
download | cpython-bc4bed440504597cac47d0a215ee094bfa99ba7e.zip cpython-bc4bed440504597cac47d0a215ee094bfa99ba7e.tar.gz cpython-bc4bed440504597cac47d0a215ee094bfa99ba7e.tar.bz2 |
bpo-29546: Set 'path' on ImportError for ``from ... import ...`` (GH-91)
Diffstat (limited to 'Lib/test/test_import')
-rw-r--r-- | Lib/test/test_import/__init__.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index d61782a..df678f1 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -80,6 +80,25 @@ class ImportTests(unittest.TestCase): with self.assertRaises(ImportError): from importlib import something_that_should_not_exist_anywhere + def test_from_import_missing_attr_has_name_and_path(self): + with self.assertRaises(ImportError) as cm: + from os import i_dont_exist + self.assertEqual(cm.exception.name, 'os') + self.assertEqual(cm.exception.path, os.__file__) + + def test_from_import_missing_attr_has_name(self): + with self.assertRaises(ImportError) as cm: + # _warning has no path as it's a built-in module. + from _warning import i_dont_exist + self.assertEqual(cm.exception.name, '_warning') + self.assertIsNone(cm.exception.path) + + def test_from_import_missing_attr_path_is_canonical(self): + with self.assertRaises(ImportError) as cm: + from os.path import i_dont_exist + self.assertIn(cm.exception.name, {'posixpath', 'ntpath'}) + self.assertIsNotNone(cm.exception) + def test_case_sensitivity(self): # Brief digression to test that import is case-sensitive: if we got # this far, we know for sure that "random" exists. |