Esempio n. 1
0
    def test_method_calls(self):

        class Sub(SomeClass):
            __qualname__ = 'SpecSignatureTest.test_method_calls.<locals>.Sub'
            attr = SomeClass()

        mock = create_autospec(Sub)
        mock.one(1, 2)
        mock.two()
        mock.three(3)
        expected = [call.one(1, 2), call.two(), call.three(3)]
        self.assertEqual(mock.method_calls, expected)
        mock.attr.one(1, 2)
        mock.attr.two()
        mock.attr.three(3)
        expected.extend([call.attr.one(1, 2), call.attr.two(), call.attr.three(3)])
        self.assertEqual(mock.method_calls, expected)
Esempio n. 2
0
    def test_method_calls(self):
        class Sub(SomeClass):
            attr = SomeClass()

        mock = create_autospec(Sub)
        mock.one(1, 2)
        mock.two()
        mock.three(3)
        expected = [call.one(1, 2), call.two(), call.three(3)]
        self.assertEqual(mock.method_calls, expected)
        mock.attr.one(1, 2)
        mock.attr.two()
        mock.attr.three(3)
        expected.extend(
            [call.attr.one(1, 2),
             call.attr.two(),
             call.attr.three(3)])
        self.assertEqual(mock.method_calls, expected)
Esempio n. 3
0
    def test_manager_mock(self):


        class Foo(object):
            one = 'one'
            two = 'two'
        manager = Mock()
        p1 = patch.object(Foo, 'one')
        p2 = patch.object(Foo, 'two')
        mock_one = p1.start()
        self.addCleanup(p1.stop)
        mock_two = p2.start()
        self.addCleanup(p2.stop)
        manager.attach_mock(mock_one, 'one')
        manager.attach_mock(mock_two, 'two')
        Foo.two()
        Foo.one()
        self.assertEqual(manager.mock_calls, [call.two(), call.one()])
Esempio n. 4
0
    def test_manager_mock(self):

        class Foo(object):
            __qualname__ = 'MockTest.test_manager_mock.<locals>.Foo'
            one = 'one'
            two = 'two'

        manager = Mock()
        p1 = patch.object(Foo, 'one')
        p2 = patch.object(Foo, 'two')
        mock_one = p1.start()
        self.addCleanup(p1.stop)
        mock_two = p2.start()
        self.addCleanup(p2.stop)
        manager.attach_mock(mock_one, 'one')
        manager.attach_mock(mock_two, 'two')
        Foo.two()
        Foo.one()
        self.assertEqual(manager.mock_calls, [call.two(), call.one()])
Esempio n. 5
0
    def test_method_calls(self):
        class Sub(SomeClass):
            attr = SomeClass()

        mock = create_autospec(Sub)
        mock.one(1, 2)
        mock.two()
        mock.three(3)

        expected = [call.one(1, 2), call.two(), call.three(3)]
        self.assertEqual(mock.method_calls, expected)

        mock.attr.one(1, 2)
        mock.attr.two()
        mock.attr.three(3)

        expected.extend(
            [call.attr.one(1, 2), call.attr.two(), call.attr.three(3)]
        )
        self.assertEqual(mock.method_calls, expected)
Esempio n. 6
0
    def test_manager_mock(self):
        class Foo(object):
            one = "one"
            two = "two"

        manager = Mock()
        p1 = patch.object(Foo, "one")
        p2 = patch.object(Foo, "two")

        mock_one = p1.start()
        self.addCleanup(p1.stop)
        mock_two = p2.start()
        self.addCleanup(p2.stop)

        manager.attach_mock(mock_one, "one")
        manager.attach_mock(mock_two, "two")

        Foo.two()
        Foo.one()

        self.assertEqual(manager.mock_calls, [call.two(), call.one()])