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


Python mock.__class__方法代碼示例

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


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

示例1: test_spec_class

# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import __class__ [as 別名]
def test_spec_class(self):
        class X(object):
            pass

        mock = Mock(spec=X)
        self.assertTrue(isinstance(mock, X))

        mock = Mock(spec=X())
        self.assertTrue(isinstance(mock, X))

        self.assertIs(mock.__class__, X)
        self.assertEqual(Mock().__class__.__name__, 'Mock')

        mock = Mock(spec_set=X)
        self.assertTrue(isinstance(mock, X))

        mock = Mock(spec_set=X())
        self.assertTrue(isinstance(mock, X)) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:20,代碼來源:testmock.py

示例2: test_spec_class

# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import __class__ [as 別名]
def test_spec_class(self):
        class X(object):
            pass

        mock = Mock(spec=X)
        self.assertIsInstance(mock, X)

        mock = Mock(spec=X())
        self.assertIsInstance(mock, X)

        self.assertIs(mock.__class__, X)
        self.assertEqual(Mock().__class__.__name__, 'Mock')

        mock = Mock(spec_set=X)
        self.assertIsInstance(mock, X)

        mock = Mock(spec_set=X())
        self.assertIsInstance(mock, X) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:20,代碼來源:testmock.py

示例3: test_class_assignable

# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import __class__ [as 別名]
def test_class_assignable(self):
        for mock in Mock(), MagicMock():
            self.assertNotIsInstance(mock, int)

            mock.__class__ = int
            self.assertIsInstance(mock, int)
            mock.foo 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:9,代碼來源:testmock.py

示例4: test_isinstance_under_settrace

# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import __class__ [as 別名]
def test_isinstance_under_settrace(self):
        # bpo-36593 : __class__ is not set for a class that has __class__
        # property defined when it's used with sys.settrace(trace) set.
        # Delete the module to force reimport with tracing function set
        # restore the old reference later since there are other tests that are
        # dependent on unittest.mock.patch. In testpatch.PatchTest
        # test_patch_dict_test_prefix and test_patch_test_prefix not restoring
        # causes the objects patched to go out of sync

        old_patch = unittest.mock.patch

        # Directly using __setattr__ on unittest.mock causes current imported
        # reference to be updated. Use a lambda so that during cleanup the
        # re-imported new reference is updated.
        self.addCleanup(lambda patch: setattr(unittest.mock, 'patch', patch),
                        old_patch)

        with patch.dict('sys.modules'):
            del sys.modules['unittest.mock']

            def trace(frame, event, arg):
                return trace

            sys.settrace(trace)
            self.addCleanup(sys.settrace, None)

            from unittest.mock import (
                Mock, MagicMock, NonCallableMock, NonCallableMagicMock
            )

            mocks = [
                Mock, MagicMock, NonCallableMock, NonCallableMagicMock
            ]

            for mock in mocks:
                obj = mock(spec=Something)
                self.assertIsInstance(obj, Something) 
開發者ID:guohuadeng,項目名稱:odoo13-x64,代碼行數:39,代碼來源:testmock.py


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