当前位置: 首页>>代码示例>>Python>>正文


Python mock.__name__方法代码示例

本文整理汇总了Python中unittest.mock.__name__方法的典型用法代码示例。如果您正苦于以下问题:Python mock.__name__方法的具体用法?Python mock.__name__怎么用?Python mock.__name__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unittest.mock的用法示例。


在下文中一共展示了mock.__name__方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_spec_class

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import __name__ [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 __name__ [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_attach_mock_patch_autospec

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import __name__ [as 别名]
def test_attach_mock_patch_autospec(self):
        parent = Mock()

        with mock.patch(f'{__name__}.something', autospec=True) as mock_func:
            self.assertEqual(mock_func.mock._extract_mock_name(), 'something')
            parent.attach_mock(mock_func, 'child')
            parent.child(1)
            something(2)
            mock_func(3)

            parent_calls = [call.child(1), call.child(2), call.child(3)]
            child_calls = [call(1), call(2), call(3)]
            self.assertEqual(parent.mock_calls, parent_calls)
            self.assertEqual(parent.child.mock_calls, child_calls)
            self.assertEqual(something.mock_calls, child_calls)
            self.assertEqual(mock_func.mock_calls, child_calls)
            self.assertIn('mock.child', repr(parent.child.mock))
            self.assertEqual(mock_func.mock._extract_mock_name(), 'mock.child') 
开发者ID:guohuadeng,项目名称:odoo13-x64,代码行数:20,代码来源:testmock.py

示例4: test__name__

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import __name__ [as 别名]
def test__name__(self):
        mock = Mock()
        self.assertRaises(AttributeError, lambda: mock.__name__)

        mock.__name__ = 'foo'
        self.assertEqual(mock.__name__, 'foo') 
开发者ID:war-and-code,项目名称:jawfish,代码行数:8,代码来源:testmock.py


注:本文中的unittest.mock.__name__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。