2009-03-12 19:47:53 -03:00
|
|
|
from importlib import _bootstrap
|
2009-02-06 22:06:43 -04:00
|
|
|
from . import util as ext_util
|
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):
|
2009-03-12 19:47:53 -03:00
|
|
|
loader = _bootstrap._ExtensionFileLoader(ext_util.NAME,
|
2010-07-03 18:48:25 -03:00
|
|
|
ext_util.FILEPATH)
|
2009-01-17 20:24:28 -04:00
|
|
|
return loader.load_module(fullname)
|
|
|
|
|
2009-01-31 20:49:41 -04:00
|
|
|
def test_module(self):
|
2009-02-06 22:06:43 -04:00
|
|
|
with util.uncache(ext_util.NAME):
|
|
|
|
module = self.load_module(ext_util.NAME)
|
|
|
|
for attr, value in [('__name__', ext_util.NAME),
|
|
|
|
('__file__', ext_util.FILEPATH),
|
2009-02-06 21:52:25 -04:00
|
|
|
('__package__', '')]:
|
2009-01-17 20:24:28 -04:00
|
|
|
self.assertEqual(getattr(module, attr), value)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(ext_util.NAME in sys.modules)
|
|
|
|
self.assertTrue(isinstance(module.__loader__,
|
2009-03-12 19:47:53 -03:00
|
|
|
_bootstrap._ExtensionFileLoader))
|
2009-01-17 20:24:28 -04:00
|
|
|
|
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-06 22:06:43 -04:00
|
|
|
with util.uncache(ext_util.NAME):
|
|
|
|
module1 = self.load_module(ext_util.NAME)
|
|
|
|
module2 = self.load_module(ext_util.NAME)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(module1 is module2)
|
2009-01-31 20:49:41 -04:00
|
|
|
|
|
|
|
def test_state_after_failure(self):
|
|
|
|
# No easy way to trigger a failure after a successful import.
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_unloadable(self):
|
2009-08-27 20:49:21 -03:00
|
|
|
with self.assertRaises(ImportError):
|
|
|
|
self.load_module('asdfjkl;')
|
2009-01-17 20:24:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_main():
|
|
|
|
from test.support import run_unittest
|
|
|
|
run_unittest(LoaderTests)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_main()
|