def test_should_stubbing_be_treated_as_interaction(self): when(self.tester).has_a_call(call.booleanReturningMethod()).then_return(True) self.tester.booleanReturningMethod() with raises(NoInteractionWanted): verify_no_more_interactions(self.tester)
def test_should_evaluate_latest_stubbing_first(self): when(self.tester).has_a_call(call.object_returning_method(instance_of(int))).then_return(100) when(self.tester).has_a_call(call.object_returning_method(200)).then_return(200) assert 200 == self.tester.object_returning_method(200) assert 100 == self.tester.object_returning_method(666) assert self.tester.object_returning_method("blah") is None, "default behavior should return null"
def test_should_not_count_in_stubbed_invocations(self): when(self.tester).has_a_call(call.add('test')).then_return(False) when(self.tester).has_a_call(call.add('test')).then_return(True) self.tester.add('test') self.tester.add('test') verify(self.tester, times(2)).had_called_with(call.add('test'))
def test_should_stubbing_not_be_treated_as_interaction(self): when(self.tester).has_a_call(call.simple_method('one')).then_raise(RuntimeError()) when(self.tester).has_a_call(call.simple_method('two')).then_raise(RuntimeError()) verify_zero_interaction(self.tester)
def test_should_allow_stubbing_to_string(self): other_tester = MagicMock() when(other_tester).has_a_call(magic_call.__str__()).then_return("test") assert str(self.tester) != 'test' assert str(other_tester) == 'test'