diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2014-04-19 06:13:23 (GMT) |
---|---|---|
committer | Eric Snow <ericsnowcurrently@gmail.com> | 2014-04-19 06:13:23 (GMT) |
commit | 658af3137237407549e71cc1c3a3dd4f2c86b675 (patch) | |
tree | 5966ba969f867c851131bc67f68936ac3f6b23f0 /Lib/test/test_pkgutil.py | |
parent | bddecc386123409c6b16cf931c1b175ded07bfcd (diff) | |
download | cpython-658af3137237407549e71cc1c3a3dd4f2c86b675.zip cpython-658af3137237407549e71cc1c3a3dd4f2c86b675.tar.gz cpython-658af3137237407549e71cc1c3a3dd4f2c86b675.tar.bz2 |
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 c4410a9..9704156 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: |