當前位置: 首頁>>代碼示例>>Python>>正文


Python mock.two方法代碼示例

本文整理匯總了Python中unittest.mock.two方法的典型用法代碼示例。如果您正苦於以下問題:Python mock.two方法的具體用法?Python mock.two怎麽用?Python mock.two使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在unittest.mock的用法示例。


在下文中一共展示了mock.two方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_manager_mock

# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import two [as 別名]
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()]) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:22,代碼來源:testmock.py

示例2: test_setting_call

# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import two [as 別名]
def test_setting_call(self):
        mock = Mock()
        def __call__(self, a):
            return self._mock_call(a)

        type(mock).__call__ = __call__
        mock('one')
        mock.assert_called_with('one')

        self.assertRaises(TypeError, mock, 'one', 'two') 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:12,代碼來源:testmock.py

示例3: test_assert_has_calls_nested_without_spec

# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import two [as 別名]
def test_assert_has_calls_nested_without_spec(self):
        m = MagicMock()
        m().foo().bar().baz()
        m.one().two().three()
        calls = call.one().two().three().call_list()
        m.assert_has_calls(calls) 
開發者ID:guohuadeng,項目名稱:odoo13-x64,代碼行數:8,代碼來源:testmock.py

示例4: test_mock_add_spec

# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import two [as 別名]
def test_mock_add_spec(self):
        class _One(object):
            one = 1
        class _Two(object):
            two = 2
        class Anything(object):
            one = two = three = 'four'

        klasses = [
            Mock, MagicMock, NonCallableMock, NonCallableMagicMock
        ]
        for Klass in list(klasses):
            klasses.append(lambda K=Klass: K(spec=Anything))
            klasses.append(lambda K=Klass: K(spec_set=Anything))

        for Klass in klasses:
            for kwargs in dict(), dict(spec_set=True):
                mock = Klass()
                #no error
                mock.one, mock.two, mock.three

                for One, Two in [(_One, _Two), (['one'], ['two'])]:
                    for kwargs in dict(), dict(spec_set=True):
                        mock.mock_add_spec(One, **kwargs)

                        mock.one
                        self.assertRaises(
                            AttributeError, getattr, mock, 'two'
                        )
                        self.assertRaises(
                            AttributeError, getattr, mock, 'three'
                        )
                        if 'spec_set' in kwargs:
                            self.assertRaises(
                                AttributeError, setattr, mock, 'three', None
                            )

                        mock.mock_add_spec(Two, **kwargs)
                        self.assertRaises(
                            AttributeError, getattr, mock, 'one'
                        )
                        mock.two
                        self.assertRaises(
                            AttributeError, getattr, mock, 'three'
                        )
                        if 'spec_set' in kwargs:
                            self.assertRaises(
                                AttributeError, setattr, mock, 'three', None
                            )
            # note that creating a mock, setting an instance attribute, and
            # *then* setting a spec doesn't work. Not the intended use case 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:53,代碼來源:testmock.py


注:本文中的unittest.mock.two方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。