diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2014-04-19 00:13:23 -0600 |
---|---|---|
committer | Eric Snow <ericsnowcurrently@gmail.com> | 2014-04-19 00:13:23 -0600 |
commit | a05a707aa9ef9ffaf155c2f625f12d49eb47a81a (patch) | |
tree | a4b9851463ae0ff1397ccdc0ba19a17bfb2f35c9 /Lib/test/test_pkgutil.py | |
parent | 38d44e25cf7eecf044a9781ef3afe96a27be7408 (diff) | |
download | cpython-a05a707aa9ef9ffaf155c2f625f12d49eb47a81a.tar.gz |
Issue #21200: Return None from pkgutil.get_loader() when __spec__ is missing.
Diffstat (limited to 'Lib/test/test_pkgutil.py')
-rw-r--r-- | Lib/test/test_pkgutil.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/Lib/test/test_pkgutil.py b/Lib/test/test_pkgutil.py index c4410a9041..9704156a52 100644 --- a/Lib/test/test_pkgutil.py +++ b/Lib/test/test_pkgutil.py @@ -1,4 +1,4 @@ -from test.support import run_unittest, unload, check_warnings +from test.support import run_unittest, unload, check_warnings, CleanImport import unittest import sys import importlib @@ -345,6 +345,23 @@ class ImportlibMigrationTests(unittest.TestCase): finally: __loader__ = this_loader + def test_get_loader_handles_missing_spec_attribute(self): + name = 'spam' + mod = type(sys)(name) + del mod.__spec__ + with CleanImport(name): + sys.modules[name] = mod + loader = pkgutil.get_loader(name) + self.assertIsNone(loader) + + def test_get_loader_handles_spec_attribute_none(self): + name = 'spam' + mod = type(sys)(name) + mod.__spec__ = None + with CleanImport(name): + sys.modules[name] = mod + loader = pkgutil.get_loader(name) + self.assertIsNone(loader) def test_find_loader_avoids_emulation(self): with check_warnings() as w: |