mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	svn+ssh://svn.python.org/python/branches/py3k ........ r73715 | benjamin.peterson | 2009-07-01 01:06:06 +0200 (Mi, 01 Jul 2009) | 1 line convert old fail* assertions to assert* ........
		
			
				
	
	
		
			58 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
from importlib import _bootstrap
 | 
						|
from . import util as ext_util
 | 
						|
from .. import abc
 | 
						|
from .. import util
 | 
						|
 | 
						|
import sys
 | 
						|
import unittest
 | 
						|
 | 
						|
 | 
						|
class LoaderTests(abc.LoaderTests):
 | 
						|
 | 
						|
    """Test load_module() for extension modules."""
 | 
						|
 | 
						|
    def load_module(self, fullname):
 | 
						|
        loader = _bootstrap._ExtensionFileLoader(ext_util.NAME,
 | 
						|
                                                ext_util.FILEPATH, False)
 | 
						|
        return loader.load_module(fullname)
 | 
						|
 | 
						|
    def test_module(self):
 | 
						|
        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),
 | 
						|
                                ('__package__', '')]:
 | 
						|
                self.assertEqual(getattr(module, attr), value)
 | 
						|
            self.assertTrue(ext_util.NAME in sys.modules)
 | 
						|
            self.assertTrue(isinstance(module.__loader__,
 | 
						|
                                    _bootstrap._ExtensionFileLoader))
 | 
						|
 | 
						|
    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):
 | 
						|
        with util.uncache(ext_util.NAME):
 | 
						|
            module1 = self.load_module(ext_util.NAME)
 | 
						|
            module2 = self.load_module(ext_util.NAME)
 | 
						|
            self.assertTrue(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):
 | 
						|
        self.assertRaises(ImportError, self.load_module, 'asdfjkl;')
 | 
						|
 | 
						|
 | 
						|
def test_main():
 | 
						|
    from test.support import run_unittest
 | 
						|
    run_unittest(LoaderTests)
 | 
						|
 | 
						|
 | 
						|
if __name__ == '__main__':
 | 
						|
    test_main()
 |