summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/test/source/test_file_loader.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-05-11 18:48:41 (GMT)
committerBrett Cannon <brett@python.org>2012-05-11 18:48:41 (GMT)
commitc049952de76cbcd00e490e48445ed7a50d3dc83a (patch)
tree91d1ff6bffbb8d6c5b04a8bae6b53944eb078335 /Lib/importlib/test/source/test_file_loader.py
parent0c59b039b86afa9f51c30f7d9f340d9c75984488 (diff)
downloadcpython-c049952de76cbcd00e490e48445ed7a50d3dc83a.zip
cpython-c049952de76cbcd00e490e48445ed7a50d3dc83a.tar.gz
cpython-c049952de76cbcd00e490e48445ed7a50d3dc83a.tar.bz2
Issue #13959: Have
importlib.abc.FileLoader.load_module()/get_filename() and importlib.machinery.ExtensionFileLoader.load_module() have their single argument be optional as the loader's constructor has all the ncessary information. This allows for the deprecation of imp.load_source()/load_compile()/load_package().
Diffstat (limited to 'Lib/importlib/test/source/test_file_loader.py')
-rw-r--r--Lib/importlib/test/source/test_file_loader.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/Lib/importlib/test/source/test_file_loader.py b/Lib/importlib/test/source/test_file_loader.py
index c4c7545..ffa0c24 100644
--- a/Lib/importlib/test/source/test_file_loader.py
+++ b/Lib/importlib/test/source/test_file_loader.py
@@ -1,5 +1,6 @@
from ... import _bootstrap
import importlib
+import importlib.abc
from .. import abc
from .. import util
from . import util as source_util
@@ -24,6 +25,40 @@ class SimpleTest(unittest.TestCase):
"""
+ def test_load_module_API(self):
+ # If fullname is not specified that assume self.name is desired.
+ class TesterMixin(importlib.abc.Loader):
+ def load_module(self, fullname): return fullname
+
+ class Tester(importlib.abc.FileLoader, TesterMixin):
+ def get_code(self, _): pass
+ def get_source(self, _): pass
+ def is_package(self, _): pass
+
+ name = 'mod_name'
+ loader = Tester(name, 'some_path')
+ self.assertEqual(name, loader.load_module())
+ self.assertEqual(name, loader.load_module(None))
+ self.assertEqual(name, loader.load_module(name))
+ with self.assertRaises(ImportError):
+ loader.load_module(loader.name + 'XXX')
+
+ def test_get_filename_API(self):
+ # If fullname is not set then assume self.path is desired.
+ class Tester(importlib.abc.FileLoader):
+ def get_code(self, _): pass
+ def get_source(self, _): pass
+ def is_package(self, _): pass
+
+ path = 'some_path'
+ name = 'some_name'
+ loader = Tester(name, path)
+ self.assertEqual(path, loader.get_filename(name))
+ self.assertEqual(path, loader.get_filename())
+ self.assertEqual(path, loader.get_filename(None))
+ with self.assertRaises(ImportError):
+ loader.get_filename(name + 'XXX')
+
# [basic]
def test_module(self):
with source_util.create_modules('_temp') as mapping: