def override_comparators_dont_replace_all(self): ''' comparator overrides only affect comparator used for that type ''' mock_spec = MockSpec(comparators={float:EqualsEquals}) mock_call = mock_spec.your_mother(TypeError('hamster')) mock_call_result = mock_call.result_of('your_mother') spec = Spec(mock_call_result) spec.__call__(TypeError('hamster')) spec.should_not_raise(UnmetSpecification)
def override_comparators_dont_replace_all(self): ''' comparator overrides only affect comparator used for that type ''' mock_spec = MockSpec(comparators={float: EqualsEquals}) mock_call = mock_spec.your_mother(TypeError('hamster')) mock_call_result = mock_call.result_of('your_mother') spec = Spec(mock_call_result) spec.__call__(TypeError('hamster')) spec.should_not_raise(UnmetSpecification)
def correct_result_should_be_ok(self): ''' Specified and_result="bar" and was "bar": met specification. Note: and_result refers to the value returned from the callable invoked in verify(), not the return value from the mock. See the Hungarian gentleman in the examples for a clearer picture... ''' mock_spec = MockSpec() spec = Spec(CollaborateWith(mock_spec.foo().will_return('bar'), and_result='bar')) spec.verify(lambda: mock_spec.foo()) spec.should_not_raise(UnmetSpecification)
def correct_result_should_be_ok(self): ''' Specified and_result="bar" and was "bar": met specification. Note: and_result refers to the value returned from the callable invoked in verify(), not the return value from the mock. See the Hungarian gentleman in the examples for a clearer picture... ''' mock_spec = MockSpec() spec = Spec( CollaborateWith(mock_spec.foo().will_return('bar'), and_result='bar')) spec.verify(lambda: mock_spec.foo()) spec.should_not_raise(UnmetSpecification)
def should_check_unverified_collaborations(self): ''' check for unverified collaborations after start_collaborating ''' spec = Spec(MockSpec()) spec.when(spec.foo(), spec.start_collaborating()) spec.then(spec.verify()) msg = 'should be collaborating with unnamed_mock.foo()' spec.should_raise(UnmetSpecification(msg)) spec = Spec(MockSpec()) spec.when(spec.foo(), spec.start_collaborating(), spec.foo()) spec.then(spec.verify()) spec.should_not_raise(UnmetSpecification)
def verify_exceptions_with_comparator(self): ''' ExceptionValue should be used to verify Exception args ''' mock_call = MockSpec().your_mother(TypeError('hamster')) mock_call_result = mock_call.result_of('your_mother') spec = Spec(mock_call_result) spec.__call__(TypeError('hamster')) spec.should_not_raise(UnmetSpecification) mock_call = MockSpec().your_father(smelt_of=TypeError('elderberries')) mock_call_result = mock_call.result_of('your_father') spec = Spec(mock_call_result) spec.__call__(smelt_of=TypeError('elderberries')) spec.should_not_raise(UnmetSpecification)
def correct_call_should_be_ok(self): ''' Specified foo() and foo() called: met specification ''' mock_spec = MockSpec() spec = Spec(CollaborateWith(mock_spec.foo())) spec.verify(lambda: mock_spec.foo()) spec.should_not_raise(UnmetSpecification)