def test_mock_override(self):
        """
        Test that a mock overrides any other provided instance.

        """
        syringe.mock('mock')
        m = syringe.mock('mock')
        self.assertIs(m, self.injected)
示例#2
0
    def test_mock_override(self):
        """
        Test that a mock overrides any other provided instance.

        """
        syringe.mock('mock')
        m = syringe.mock('mock')
        self.assertIs(m, self.injected)
示例#3
0
    def test_same_instance(self):
        """
        Test that the injected mock is the actual mock instance.

        """
        m = syringe.mock('mock')
        self.assertIs(m, self.injected)
    def test_same_instance(self):
        """
        Test that the injected mock is the actual mock instance.

        """
        m = syringe.mock('mock')
        self.assertIs(m, self.injected)
    def test_call_mock(self):
        """
        Test that the actual mock is called when calling the injected mock.

        """
        m = syringe.mock("mock")
        m.ask.return_value = 42
        answer = self.injected.ask("what is the answer to life the universe and everything?")
        m.ask.assert_called_once_with("what is the answer to life the universe and everything?")
        self.assertEqual(42, answer)
示例#6
0
    def test_custom_mock(self):
        """
        Test that a custom object can be used as a mock.

        """
        class MyMock(object):
            pass

        m = MyMock()
        copy = syringe.mock('mymock', m)
        self.assertIs(m, copy)
        self.assertIs(m, syringe.get('mymock'))
示例#7
0
    def test_call_mock(self):
        """
        Test that the actual mock is called when calling the injected mock.

        """
        m = syringe.mock('mock')
        m.ask.return_value = 42
        answer = self.injected.ask(
            'what is the answer to life the universe and everything?')
        m.ask.assert_called_once_with(
            'what is the answer to life the universe and everything?')
        self.assertEqual(42, answer)
    def test_custom_mock(self):
        """
        Test that a custom object can be used as a mock.

        """
        class MyMock(object):
            pass

        m = MyMock()
        copy = syringe.mock('mymock', m)
        self.assertIs(m, copy)
        self.assertIs(m, syringe.get('mymock'))