diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2020-02-28 14:26:27 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-28 14:26:27 (GMT) |
commit | 4f17c5cd9a1ec50fe8de7ef68c39220a01a862cb (patch) | |
tree | 627e549365ac1eadeae19e013ec5c218898c0b6a /Lib/test/test_pkgutil.py | |
parent | e263bb1e97ae8f84fb4f2ab5b0c4f529a2e5696d (diff) | |
download | cpython-4f17c5cd9a1ec50fe8de7ef68c39220a01a862cb.zip cpython-4f17c5cd9a1ec50fe8de7ef68c39220a01a862cb.tar.gz cpython-4f17c5cd9a1ec50fe8de7ef68c39220a01a862cb.tar.bz2 |
bpo-12915: Improve Unicode support for package names and attributes. (GH-18517)
Diffstat (limited to 'Lib/test/test_pkgutil.py')
-rw-r--r-- | Lib/test/test_pkgutil.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_pkgutil.py b/Lib/test/test_pkgutil.py index 906150b..53456c2 100644 --- a/Lib/test/test_pkgutil.py +++ b/Lib/test/test_pkgutil.py @@ -229,8 +229,40 @@ class PkgutilTests(unittest.TestCase): ('logging.handlers:SysLogHandler.NO_SUCH_VALUE', AttributeError), ('logging.handlers.SysLogHandler.NO_SUCH_VALUE', AttributeError), ('ZeroDivisionError', ImportError), + ('os.path.9abc', ValueError), + ('9abc', ValueError), ) + # add some Unicode package names to the mix. + + unicode_words = ('\u0935\u092e\u0938', + '\xe9', '\xc8', + '\uc548\ub155\ud558\uc138\uc694', + '\u3055\u3088\u306a\u3089', + '\u3042\u308a\u304c\u3068\u3046', + '\u0425\u043e\u0440\u043e\u0448\u043e', + '\u0441\u043f\u0430\u0441\u0438\u0431\u043e', + '\u73b0\u4ee3\u6c49\u8bed\u5e38\u7528\u5b57\u8868') + + for uw in unicode_words: + d = os.path.join(self.dirname, uw) + os.makedirs(d, exist_ok=True) + # make an empty __init__.py file + f = os.path.join(d, '__init__.py') + with open(f, 'w') as f: + f.write('') + f.flush() + # now import the package we just created; clearing the caches is + # needed, otherwise the newly created package isn't found + importlib.invalidate_caches() + mod = importlib.import_module(uw) + success_cases += (uw, mod), + if len(uw) > 1: + failure_cases += (uw[:-1], ImportError), + + # add an example with a Unicode digit at the start + failure_cases += ('\u0966\u0935\u092e\u0938', ValueError), + for s, expected in success_cases: with self.subTest(s=s): o = pkgutil.resolve_name(s) |