Esempio n. 1
0
    def get_unisolated_imported_module(self):
        ''' get_module() should return a requested module, which should 
        remain in sys.modules as it has been loaded unisolated.
        The same module should be returned on successive invocations. 
        The same module should be returned from different contexts '''

        same_context = ExecutionContext()
        same_context.add_import_path(self._nonsrc_path(same_context))
        different_context = ExecutionContext(isolate_imports=False)
        different_context.add_import_path(self._nonsrc_path(different_context))
        for mod in ('import_me', 'module_with_state'):
            spec = lancelot.Spec(same_context)
            spec.get_module(mod).should_be(Type(types.ModuleType))

            same_module = same_context.get_module(mod)
            spec.get_module(mod).should_be(SameAs(same_module))

            sys_spec = lancelot.Spec(sys.modules)
            sys_spec.it().should_contain(mod)

            different_module = different_context.get_module(mod)
            spec.get_module(mod).should_be(SameAs(different_module))

            same_context.cleanup_imports()
            different_context.cleanup_imports()
Esempio n. 2
0
    def get_unisolated_imported_module(self):
        ''' get_module() should return a requested module, which should 
        remain in sys.modules as it has been loaded unisolated.
        The same module should be returned on successive invocations. 
        The same module should be returned from different contexts '''
        
        same_context = ExecutionContext()
        same_context.add_import_path(self._nonsrc_path(same_context))
        different_context = ExecutionContext(isolate_imports=False)
        different_context.add_import_path(self._nonsrc_path(different_context))
        for mod in ('import_me', 
                     'module_with_state'):
            spec = lancelot.Spec(same_context)
            spec.get_module(mod).should_be(Type(types.ModuleType))

            same_module = same_context.get_module(mod)
            spec.get_module(mod).should_be(SameAs(same_module))
            
            sys_spec = lancelot.Spec(sys.modules)
            sys_spec.it().should_contain(mod)
        
            different_module = different_context.get_module(mod)
            spec.get_module(mod).should_be(SameAs(different_module))
            
            same_context.cleanup_imports()
            different_context.cleanup_imports()
Esempio n. 3
0
    def cleansup_sys_modules(self):
        ''' cleanup_imports() should not choke on module that were imported
        but are no longer in sys.modules '''
        execution_context = ExecutionContext()
        path = self._nonsrc_path(execution_context)
        execution_context.add_import_path(path)
        execution_context.get_module('import_me')

        spec = lancelot.Spec(execution_context)
        del (sys.modules['import_me'])
        spec.cleanup_imports().should_not_raise(Exception)
Esempio n. 4
0
 def cleansup_sys_modules(self):
     ''' cleanup_imports() should not choke on module that were imported
     but are no longer in sys.modules '''
     execution_context = ExecutionContext()
     path = self._nonsrc_path(execution_context)
     execution_context.add_import_path(path)
     execution_context.get_module('import_me')
     
     spec = lancelot.Spec(execution_context)
     del(sys.modules['import_me'])
     spec.cleanup_imports().should_not_raise(Exception)