def get_unisolated_module_type(self): ''' get_type() should return a requested module type, given the fully qualified name including module. The same type should be returned on successive invocations. The same type should also be returned from different contexts. State in a module should not be isolated within each context''' _types = {'StateAlteringClass': 'module_with_state'} execution_context = ExecutionContext(isolate_imports=False) execution_context.add_import_path(self._nonsrc_path(execution_context)) for _type, mod in _types.items(): fully_qualified_name = '%s.%s' % (mod, _type) same_type = execution_context.get_type(fully_qualified_name) lancelot.Spec(same_type.__name__).it().should_be(_type) spec = lancelot.Spec(execution_context) spec.get_type(fully_qualified_name).should_be(SameAs(same_type)) other_context = ExecutionContext(isolate_imports=False) other_context.add_import_path(self._nonsrc_path(other_context)) different_type = other_context.get_type(fully_qualified_name) spec.get_type(fully_qualified_name).should_be( SameAs(different_type)) instances = same_type(), different_type() spec = lancelot.Spec(instances[0]) spec.when(spec.alter_state()) spec.then(spec.get_state()).should_contain(1) spec.then(instances[1].get_state).should_contain(1) execution_context.cleanup_imports() other_context.cleanup_imports()
def get_unisolated_module_type(self): ''' get_type() should return a requested module type, given the fully qualified name including module. The same type should be returned on successive invocations. The same type should also be returned from different contexts. State in a module should not be isolated within each context''' _types = {'StateAlteringClass':'module_with_state'} execution_context = ExecutionContext(isolate_imports=False) execution_context.add_import_path(self._nonsrc_path(execution_context)) for _type, mod in _types.items(): fully_qualified_name = '%s.%s' % (mod, _type) same_type = execution_context.get_type(fully_qualified_name) lancelot.Spec(same_type.__name__).it().should_be(_type) spec = lancelot.Spec(execution_context) spec.get_type(fully_qualified_name).should_be(SameAs(same_type)) other_context = ExecutionContext(isolate_imports=False) other_context.add_import_path(self._nonsrc_path(other_context)) different_type = other_context.get_type(fully_qualified_name) spec.get_type(fully_qualified_name).should_be( SameAs(different_type)) instances = same_type(), different_type() spec = lancelot.Spec(instances[0]) spec.when(spec.alter_state()) spec.then(spec.get_state()).should_contain(1) spec.then(instances[1].get_state).should_contain(1) execution_context.cleanup_imports() other_context.cleanup_imports()
def get_type_all_lowercaps(self): ''' get_type(namewithoutspaces) => get_type (Namewithoutspaces) ''' context = ExecutionContext() context.add_type_prefix('waferslim.examples.helper_fixtures') multiplication = context.get_type('Multiplication') spec = lancelot.Spec(context) spec.get_type('multiplication').should_be(multiplication) context.cleanup_imports()
def uses_added_type_context(self): ''' add_type_context() should allow classes to be found without fully-dot-qualified prefixes''' ctx = ExecutionContext() test_case_type = ctx.get_type('unittest.TestCase') spec = lancelot.Spec(ctx) spec.get_type('TestCase').should_raise(TypeError) spec.when(spec.add_type_prefix('unittest')) spec.then(spec.get_type('TestCase')).should_not_raise(TypeError) spec.then(spec.get_type('TestCase')).should_be(test_case_type) ctx.cleanup_imports()
def uses_added_type_context(self): ''' add_type_context() should allow classes to be found without fully-dot-qualified prefixes. A unicode param may be passed.''' ctx = ExecutionContext() test_case_type = ctx.get_type('unittest.TestCase') spec = lancelot.Spec(ctx) spec.get_type('TestCase').should_raise(TypeError) spec.when(spec.add_type_prefix('unittest')) spec.then(spec.get_type('TestCase')).should_not_raise(TypeError) spec.then(spec.get_type('TestCase')).should_be(test_case_type) second_ctx = ExecutionContext() spec = lancelot.Spec(second_ctx) spec.when(spec.add_type_prefix(u'waferslim.examples.decision_table')) spec.then(spec.get_type(u'ShouldIBuyMilk')).should_not_raise(TypeError) ctx.cleanup_imports()