diff options
author | Xiang Zhang <angwerzx@126.com> | 2018-03-24 10:39:36 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-24 10:39:36 (GMT) |
commit | d8b291a74284307610946f1b5801aa95d7f1e052 (patch) | |
tree | 617813bb9a48cc4af48cc8b9c0cc3c79694fa33c /Lib/test | |
parent | 5cbb84106efefd200933aa31e22abf39267d2557 (diff) | |
download | cpython-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')
-rw-r--r-- | Lib/test/test_import/__init__.py | 21 |
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. |