Exemplo n.º 1
0
    def test_number_of_calls_matter(self):
        expect_call(self.mock.hello)
        self.mock.hello()
        self.mock.hello()

        with self.assertRaises(UnexpectedBehavior):
            self.mock.assert_that_is_satisfied()
Exemplo n.º 2
0
    def test_mock_without_args_is_empty_mock(self):
        self.mock = mock()
        expect_call(self.mock.hello)

        self.mock.hello()

        self.mock.assert_that_is_satisfied()
Exemplo n.º 3
0
    def test_expect_several_times_matches_exactly(self):
        expect_call(self.mock.one_arg_method).with_args(1).times(2)

        self.mock.one_arg_method(1)
        self.mock.one_arg_method(1)

        self.mock.assert_that_is_satisfied()
Exemplo n.º 4
0
    def test_times_and_return_value(self):
        expect_call(self.mock.one_arg_method).returning(1000).times(2)

        self.assertEqual(1000, self.mock.one_arg_method(1))
        self.assertEqual(1000, self.mock.one_arg_method(1))

        self.mock.assert_that_is_satisfied()
Exemplo n.º 5
0
    def test_expect_several_times_without_args_definition(self):
        expect_call(self.mock.one_arg_method).times(2)

        self.mock.one_arg_method(1)
        self.mock.one_arg_method(1)

        self.mock.assert_that_is_satisfied()
Exemplo n.º 6
0
 def test_assert_expectations_alternative(self):
     expect_call(self.mock.hello)
     try:
         self.mock.assert_expectations()
         self.fail('Not satisfied')
     except UnexpectedBehavior:
         pass
Exemplo n.º 7
0
    def test_expect_several_times(self):
        expect_call(self.mock.one_arg_method).with_args(1).times(2)

        self.mock.one_arg_method(1)

        with self.assertRaises(UnexpectedBehavior):
            self.mock.assert_that_is_satisfied()
Exemplo n.º 8
0
 def test_define_expectation_args_and_fail(self):
     expect_call(self.mock.one_arg_method).with_args(1)
     try:
         self.mock.one_arg_method(2)
         self.fail('Unexpected call')
     except UnexpectedBehavior:
         pass
Exemplo n.º 9
0
 def test_assert_expectations_are_satisfied(self):
     expect_call(self.mock.hello)
     try:
         self.mock.assert_that_is_satisfied()
         self.fail('Not satisfied!')
     except UnexpectedBehavior:
         pass
Exemplo n.º 10
0
    def test_several_expectations_in_empty_mock(self):
        expect_call(self.mock.hello)
        expect_call(self.mock.one_arg_method).with_args(1)

        self.mock.hello()
        self.mock.one_arg_method(1)

        self.mock.assert_that_is_satisfied()
Exemplo n.º 11
0
    def test_several_expectations_with_args_in_empty_mock(self):
        expect_call(self.mock.one_arg_method).with_args(1)
        expect_call(self.mock.one_arg_method).with_args(2)

        self.assertTrue(self.mock.one_arg_method(1) is None)
        self.assertTrue(self.mock.one_arg_method(2) is None)

        self.mock.assert_that_is_satisfied()
Exemplo n.º 12
0
 def test_defend_agains_less_than_2_times(self):
     try:
         expect_call(self.mock.one_arg_method).times(1)
         self.fail('times cant be less than 2')
     except WrongApiUsage:
         pass
Exemplo n.º 13
0
    def test_expectations_on_synonyms(self):
        expect_call(self.mock.one_arg_method)

        self.mock.alias_method(1)

        self.mock.assert_that_is_satisfied()
Exemplo n.º 14
0
 def test_assert_satisfied_when_it_really_is(self):
     expect_call(self.mock.hello)
     self.mock.hello()
     self.mock.assert_that_is_satisfied()
Exemplo n.º 15
0
    def test_expect_call_returning_value(self):
        expect_call(self.mock.one_arg_method).with_args(1).returning(1000)

        self.assertEqual(1000, self.mock.one_arg_method(1))
Exemplo n.º 16
0
    def test_several_expectations_with_args(self):
        expect_call(self.mock.one_arg_method).with_args(1)
        expect_call(self.mock.two_args_method).with_args(2, 3)

        self.assertTrue(self.mock.one_arg_method(1) is None)
        self.assertTrue(self.mock.two_args_method(2, 3) is None)
Exemplo n.º 17
0
    def test_mock_can_work_from_empty_object(self):
        expect_call(self.mock.hello)

        self.mock.hello()

        self.mock.assert_that_is_satisfied()
Exemplo n.º 18
0
    def test_define_several_expectatiosn(self):
        expect_call(self.mock.hello)
        expect_call(self.mock.one_arg_method)

        self.assertTrue(self.mock.hello() is None)
        self.assertTrue(self.mock.one_arg_method(1) is None)
Exemplo n.º 19
0
 def test_define_expectation_args(self):
     expect_call(self.mock.one_arg_method).with_args(1)
     self.assertTrue(self.mock.one_arg_method(1) is None)
Exemplo n.º 20
0
 def test_using_when_or_expect_call_without_double(self):
     with self.assertRaises(WrongApiUsage):
         expect_call(Collaborator())
Exemplo n.º 21
0
 def test_define_expectation_and_call_method(self):
     expect_call(self.mock.hello)
     self.assertTrue(self.mock.hello() is None)