コード例 #1
0
    def test_should_raise_exception_when_trying_to_use_matcher_as_second_keyword_argument_in_native_verification(
            self):

        test_object = Mock(targetpackage.TheClass())

        test_object.some_method(1, 2, 3, hello='world')

        exception_raised = False
        try:
            verify(test_object).some_method(1,
                                            2,
                                            3,
                                            hello='world',
                                            world=ANY_VALUE)
        except VerificationError as error:
            exception_raised = True
            assert_that(
                str(error),
                ends_with("""
          Please configure your mock using fluentmock.when in order
          to be able to use matchers!

"""))

        assert_that(exception_raised)
コード例 #2
0
ファイル: when_tests.py プロジェクト: uttamk/fluentmock
    def test_should_patch_away_method_of_mock(self):

        test_object = Mock(targetpackage.TheClass())

        when(test_object).some_method(1).then_return(0)

        assert_that(test_object.some_method(1), equal_to(0))
コード例 #3
0
    def test_should_verify_a_call_to_a_field_of_a_mock_with_arguments(self):

        test_object = Mock(targetpackage.TheClass())

        test_object.some_method(1, 2, 3)

        verify(test_object).some_method(1, 2, 3)
コード例 #4
0
    def test_should_verify_never_called_a_field_of_a_mock_without_any_arguments(
            self):

        test_object = Mock(targetpackage.TheClass())

        test_object.some_method(1, 2, 3)

        verify(test_object, NEVER).some_method()
コード例 #5
0
    def test_should_verify_that_mock_has_been_called_exactly_once(self):

        test_object = Mock(targetpackage.TheClass())

        when(test_object).some_method(1).then_return(0)

        assert_that(test_object.some_method(1), equal_to(0))

        verify(test_object, times=1).some_method(1)
コード例 #6
0
    def test_should_verify_a_call_to_a_field_of_a_mock_with_any_argument(self):

        test_object = Mock(targetpackage.TheClass())

        when(test_object).some_method(1).then_return(0)

        assert_that(test_object.some_method(1), equal_to(0))

        verify(test_object).some_method(ANY_VALUE)
コード例 #7
0
    def test_should_verify_a_call_to_a_object_with_multiple_arguments(self):

        test_object = targetpackage.TheClass()

        when(test_object).some_method(1, 2).then_return('123')

        test_object.some_method(1, 2)

        verify(test_object).some_method(1, 2)
コード例 #8
0
    def test_should_raise_exception_when_called_a_field_of_a_mock_once_but_twice_expected(
            self):

        test_object = Mock(targetpackage.TheClass())

        test_object.some_method(1, 2, 3)

        exception_raised = False
        try:
            verify(test_object, times=2).some_method(1, 2, 3)
        except VerificationError as error:
            exception_raised = True
            assert_that(
                str(error),
                equal_to("""
Expected: call mock.Mock.some_method(1, 2, 3) << exactly 2 times >>
 but was: call mock.Mock.some_method(1, 2, 3)
"""))

        assert_that(exception_raised)
コード例 #9
0
    def test_should_raise_exception_when_called_a_field_of_a_mock_with_keyword_arguments(
            self):

        test_object = Mock(targetpackage.TheClass())

        test_object.some_method(1, 2, 3, hello='world')

        exception_raised = False
        try:
            verify(test_object, NEVER).some_method(1, 2, 3, hello='world')
        except VerificationError as error:
            exception_raised = True
            assert_that(
                str(error),
                equal_to("""
Expected: call mock.Mock.some_method(1, 2, 3, hello='world') << should never be called >>
 but was: call mock.Mock.some_method(1, 2, 3, hello='world')
"""))

        assert_that(exception_raised)