• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python support.is_instance函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中unittest.test.testmock.support.is_instance函数的典型用法代码示例。如果您正苦于以下问题:Python is_instance函数的具体用法?Python is_instance怎么用?Python is_instance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_call

    def test_call(self):
        mock = Mock()
        self.assertTrue(is_instance(mock.return_value, Mock),
                        "Default return_value should be a Mock")

        result = mock()
        self.assertEqual(mock(), result,
                         "different result from consecutive calls")
        mock.reset_mock()

        ret_val = mock(sentinel.Arg)
        self.assertTrue(mock.called, "called not set")
        self.assertEqual(mock.call_count, 1, "call_count incoreect")
        self.assertEqual(mock.call_args, ((sentinel.Arg,), {}),
                         "call_args not set")
        self.assertEqual(mock.call_args_list, [((sentinel.Arg,), {})],
                         "call_args_list not initialised correctly")

        mock.return_value = sentinel.ReturnValue
        ret_val = mock(sentinel.Arg, key=sentinel.KeyArg)
        self.assertEqual(ret_val, sentinel.ReturnValue,
                         "incorrect return value")

        self.assertEqual(mock.call_count, 2, "call_count incorrect")
        self.assertEqual(mock.call_args,
                         ((sentinel.Arg,), {'key': sentinel.KeyArg}),
                         "call_args not set")
        self.assertEqual(mock.call_args_list, [
            ((sentinel.Arg,), {}),
            ((sentinel.Arg,), {'key': sentinel.KeyArg})
        ],
            "call_args_list not set")
开发者ID:MarkTseng,项目名称:cpython,代码行数:32,代码来源:testmock.py


示例2: test_constructor

    def test_constructor(self):
        mock = Mock()

        self.assertFalse(mock.called, "called not initialised correctly")
        self.assertEqual(mock.call_count, 0,
                         "call_count not initialised correctly")
        self.assertTrue(is_instance(mock.return_value, Mock),
                        "return_value not initialised correctly")

        self.assertEqual(mock.call_args, None,
                         "call_args not initialised correctly")
        self.assertEqual(mock.call_args_list, [],
                         "call_args_list not initialised correctly")
        self.assertEqual(mock.method_calls, [],
                          "method_calls not initialised correctly")

        # Can't use hasattr for this test as it always returns True on a mock
        self.assertNotIn('_items', mock.__dict__,
                         "default mock should not have '_items' attribute")

        self.assertIsNone(mock._mock_parent,
                          "parent not initialised correctly")
        self.assertIsNone(mock._mock_methods,
                          "methods not initialised correctly")
        self.assertEqual(mock._mock_children, {},
                         "children not initialised incorrectly")
开发者ID:MarkTseng,项目名称:cpython,代码行数:26,代码来源:testmock.py


示例3: test_patch_spec_callable_class

    def test_patch_spec_callable_class(self):
        class CallableX(X):
            def __call__(self):
                pass

        class Sub(CallableX):
            pass

        class Multi(SomeClass, Sub):
            pass

        for arg in 'spec', 'spec_set':
            for Klass in CallableX, Sub, Multi:
                with patch('%s.X' % __name__, **{arg: Klass}) as mock:
                    instance = mock()
                    mock.assert_called_once_with()

                    self.assertTrue(is_instance(instance, MagicMock))
                    # inherited spec
                    self.assertRaises(AttributeError, getattr, instance,
                                      'foobarbaz')

                    result = instance()
                    # instance is callable, result has no spec
                    instance.assert_called_once_with()

                    result(3, 2, 1)
                    result.assert_called_once_with(3, 2, 1)
                    result.foo(3, 2, 1)
                    result.foo.assert_called_once_with(3, 2, 1)
开发者ID:2014c2g10,项目名称:2014c2,代码行数:30,代码来源:testcallable.py


示例4: test_attribute_access_returns_mocks

 def test_attribute_access_returns_mocks(self):
     mock = Mock()
     something = mock.something
     self.assertTrue(is_instance(something, Mock), "attribute isn't a mock")
     self.assertEqual(mock.something, something, 'different attributes returned for same name')
     mock = Mock()
     mock.something.return_value = 3
     self.assertEqual(mock.something(), 3, 'method returned wrong value')
     self.assertTrue(mock.something.called, "method didn't record being called")
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:9,代码来源:testmock.py


示例5: test_constructor

 def test_constructor(self):
     mock = Mock()
     self.assertFalse(mock.called, 'called not initialised correctly')
     self.assertEqual(mock.call_count, 0, 'call_count not initialised correctly')
     self.assertTrue(is_instance(mock.return_value, Mock), 'return_value not initialised correctly')
     self.assertEqual(mock.call_args, None, 'call_args not initialised correctly')
     self.assertEqual(mock.call_args_list, [], 'call_args_list not initialised correctly')
     self.assertEqual(mock.method_calls, [], 'method_calls not initialised correctly')
     self.assertNotIn('_items', mock.__dict__, "default mock should not have '_items' attribute")
     self.assertIsNone(mock._mock_parent, 'parent not initialised correctly')
     self.assertIsNone(mock._mock_methods, 'methods not initialised correctly')
     self.assertEqual(mock._mock_children, {}, 'children not initialised incorrectly')
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:12,代码来源:testmock.py


示例6: test_with_statement_as

 def test_with_statement_as(self):
     with patch("%s.something" % __name__) as mock_something:
         self.assertEqual(something, mock_something, "unpatched")
         self.assertTrue(is_instance(mock_something, MagicMock), "patching wrong type")
     self.assertEqual(something, sentinel.Something)
开发者ID:40123107,项目名称:2014cda,代码行数:5,代码来源:testwith.py


示例7: assertNotCallable

 def assertNotCallable(self, mock):
     self.assertTrue(is_instance(mock, NonCallableMagicMock))
     self.assertFalse(is_instance(mock, CallableMixin))
开发者ID:2014c2g10,项目名称:2014c2,代码行数:3,代码来源:testcallable.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.safe_repr函数代码示例发布时间:2022-05-27
下一篇:
Python suite.TestSuite类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap