summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_import/__init__.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py
index ceea79f..606b057 100644
--- a/Lib/test/test_import/__init__.py
+++ b/Lib/test/test_import/__init__.py
@@ -111,6 +111,27 @@ class ImportTests(unittest.TestCase):
self.assertIn(cm.exception.name, {'posixpath', 'ntpath'})
self.assertIsNotNone(cm.exception)
+ def test_from_import_star_invalid_type(self):
+ import re
+ with _ready_to_import() as (name, path):
+ with open(path, 'w') as f:
+ f.write("__all__ = [b'invalid_type']")
+ globals = {}
+ with self.assertRaisesRegex(
+ TypeError, f"{re.escape(name)}\.__all__ must be str"
+ ):
+ exec(f"from {name} import *", globals)
+ self.assertNotIn(b"invalid_type", globals)
+ with _ready_to_import() as (name, path):
+ with open(path, 'w') as f:
+ f.write("globals()[b'invalid_type'] = object()")
+ globals = {}
+ with self.assertRaisesRegex(
+ TypeError, f"{re.escape(name)}\.__dict__ must be str"
+ ):
+ exec(f"from {name} import *", globals)
+ self.assertNotIn(b"invalid_type", globals)
+
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.