2009-01-17 20:24:28 -04:00
|
|
|
import importlib
|
|
|
|
from . import test_path_hook
|
2009-01-31 20:49:41 -04:00
|
|
|
from .. import abc
|
2009-02-01 00:00:05 -04:00
|
|
|
from .. import util
|
2009-01-17 20:24:28 -04:00
|
|
|
|
|
|
|
import sys
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
2009-01-31 20:49:41 -04:00
|
|
|
class LoaderTests(abc.LoaderTests):
|
2009-01-17 20:24:28 -04:00
|
|
|
|
|
|
|
"""Test load_module() for extension modules."""
|
|
|
|
|
|
|
|
def load_module(self, fullname):
|
|
|
|
loader = importlib._ExtensionFileLoader(test_path_hook.NAME,
|
|
|
|
test_path_hook.FILEPATH,
|
|
|
|
False)
|
|
|
|
return loader.load_module(fullname)
|
|
|
|
|
2009-01-31 20:49:41 -04:00
|
|
|
def test_module(self):
|
2009-02-01 00:00:05 -04:00
|
|
|
with util.uncache(test_path_hook.NAME):
|
2009-01-17 20:24:28 -04:00
|
|
|
module = self.load_module(test_path_hook.NAME)
|
|
|
|
for attr, value in [('__name__', test_path_hook.NAME),
|
2009-02-06 21:52:25 -04:00
|
|
|
('__file__', test_path_hook.FILEPATH),
|
|
|
|
('__package__', '')]:
|
2009-01-17 20:24:28 -04:00
|
|
|
self.assertEqual(getattr(module, attr), value)
|
|
|
|
self.assert_(test_path_hook.NAME in sys.modules)
|
|
|
|
|
2009-01-31 20:49:41 -04:00
|
|
|
def test_package(self):
|
|
|
|
# Extensions are not found in packages.
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_lacking_parent(self):
|
|
|
|
# Extensions are not found in packages.
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_module_reuse(self):
|
2009-02-01 00:00:05 -04:00
|
|
|
with util.uncache(test_path_hook.NAME):
|
2009-01-31 20:49:41 -04:00
|
|
|
module1 = self.load_module(test_path_hook.NAME)
|
|
|
|
module2 = self.load_module(test_path_hook.NAME)
|
|
|
|
self.assert_(module1 is module2)
|
|
|
|
|
|
|
|
def test_state_after_failure(self):
|
|
|
|
# No easy way to trigger a failure after a successful import.
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_unloadable(self):
|
2009-01-17 20:24:28 -04:00
|
|
|
self.assertRaises(ImportError, self.load_module, 'asdfjkl;')
|
|
|
|
|
|
|
|
|
|
|
|
def test_main():
|
|
|
|
from test.support import run_unittest
|
|
|
|
run_unittest(LoaderTests)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_main()
|