summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_import
diff options
context:
space:
mode:
authorXiang Zhang <angwerzx@126.com>2018-03-24 10:39:36 (GMT)
committerGitHub <noreply@github.com>2018-03-24 10:39:36 (GMT)
commitd8b291a74284307610946f1b5801aa95d7f1e052 (patch)
tree617813bb9a48cc4af48cc8b9c0cc3c79694fa33c /Lib/test/test_import
parent5cbb84106efefd200933aa31e22abf39267d2557 (diff)
downloadcpython-d8b291a74284307610946f1b5801aa95d7f1e052.zip
cpython-d8b291a74284307610946f1b5801aa95d7f1e052.tar.gz
cpython-d8b291a74284307610946f1b5801aa95d7f1e052.tar.bz2
bpo-32932: More revealing error message when non-str objects in __all__ (GH-5848)
Diffstat (limited to 'Lib/test/test_import')
-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.