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

Python call.foo函数代码示例

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

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



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

示例1: test_attribute_call

 def test_attribute_call(self):
     self.assertEqual(call.foo(1), ('foo', (1,), {}))
     self.assertEqual(call.bar.baz(fish='eggs'), ('bar.baz', (), {'fish': 'eggs'}))
     mock = Mock()
     mock.foo(1, 2, 3)
     mock.bar.baz(a=3, b=6)
     self.assertEqual(mock.method_calls, [call.foo(1, 2, 3), call.bar.baz(a=3, b=6)])
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:7,代码来源:testhelpers.py


示例2: test_assert_has_calls

    def test_assert_has_calls(self):
        kalls1 = [call(1, 2), ({"a": 3},), ((3, 4),), call(b=6), ("", (1,), {"b": 6})]
        kalls2 = [call.foo(), call.bar(1)]
        kalls2.extend(call.spam().baz(a=3).call_list())
        kalls2.extend(call.bam(set(), foo={}).fish([1]).call_list())

        mocks = []
        for mock in Mock(), MagicMock():
            mock(1, 2)
            mock(a=3)
            mock(3, 4)
            mock(b=6)
            mock(1, b=6)
            mocks.append((mock, kalls1))

        mock = Mock()
        mock.foo()
        mock.bar(1)
        mock.spam().baz(a=3)
        mock.bam(set(), foo={}).fish([1])
        mocks.append((mock, kalls2))

        for mock, kalls in mocks:
            for i in range(len(kalls)):
                for step in 1, 2, 3:
                    these = kalls[i : i + step]
                    mock.assert_has_calls(these)

                    if len(these) > 1:
                        self.assertRaises(AssertionError, mock.assert_has_calls, list(reversed(these)))
开发者ID:GaloisInc,项目名称:echronos,代码行数:30,代码来源:testmock.py


示例3: test_adding_child_mock

 def test_adding_child_mock(self):
     for Klass in (NonCallableMock, Mock, MagicMock, NonCallableMagicMock):
         mock = Klass()
         mock.foo = Mock()
         mock.foo()
         self.assertEqual(mock.method_calls, [call.foo()])
         self.assertEqual(mock.mock_calls, [call.foo()])
         mock = Klass()
         mock.bar = Mock(name='name')
         mock.bar()
         self.assertEqual(mock.method_calls, [])
         self.assertEqual(mock.mock_calls, [])
         mock = Klass()
         mock.baz = MagicMock()()
         mock.baz()
         self.assertEqual(mock.method_calls, [])
         self.assertEqual(mock.mock_calls, [])
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:17,代码来源:testmock.py


示例4: test_adding_child_mock

    def test_adding_child_mock(self):
        for Klass in NonCallableMock, Mock, MagicMock, NonCallableMagicMock:
            mock = Klass()

            mock.foo = Mock()
            mock.foo()

            self.assertEqual(mock.method_calls, [call.foo()])
            self.assertEqual(mock.mock_calls, [call.foo()])

            mock = Klass()
            mock.bar = Mock(name='name')
            mock.bar()
            self.assertEqual(mock.method_calls, [])
            self.assertEqual(mock.mock_calls, [])

            # mock with an existing _new_parent but no name
            mock = Klass()
            mock.baz = MagicMock()()
            mock.baz()
            self.assertEqual(mock.method_calls, [])
            self.assertEqual(mock.mock_calls, [])
开发者ID:MarkTseng,项目名称:cpython,代码行数:22,代码来源:testmock.py


示例5: test_extended_call

 def test_extended_call(self):
     result = call(1).foo(2).bar(3, a=4)
     self.assertEqual(result, ('().foo().bar', (3,), dict(a=4)))
     mock = MagicMock()
     mock(1, 2, a=3, b=4)
     self.assertEqual(mock.call_args, call(1, 2, a=3, b=4))
     self.assertNotEqual(mock.call_args, call(1, 2, 3))
     self.assertEqual(mock.call_args_list, [call(1, 2, a=3, b=4)])
     self.assertEqual(mock.mock_calls, [call(1, 2, a=3, b=4)])
     mock = MagicMock()
     mock.foo(1).bar()().baz.beep(a=6)
     last_call = call.foo(1).bar()().baz.beep(a=6)
     self.assertEqual(mock.mock_calls[-1], last_call)
     self.assertEqual(mock.mock_calls, last_call.call_list())
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:14,代码来源:testhelpers.py


示例6: test_mock_calls

 def test_mock_calls(self):
     mock = MagicMock()
     self.assertIs(mock.mock_calls == [], True)
     mock = MagicMock()
     mock()
     expected = [('', (), {})]
     self.assertEqual(mock.mock_calls, expected)
     mock.foo()
     expected.append(call.foo())
     self.assertEqual(mock.mock_calls, expected)
     self.assertEqual(mock.foo.mock_calls, [('', (), {})])
     mock = MagicMock()
     mock().foo(1, 2, 3, a=4, b=5)
     expected = [('', (), {}), ('().foo', (1, 2, 3), dict(a=4, b=5))]
     self.assertEqual(mock.mock_calls, expected)
     self.assertEqual(mock.return_value.foo.mock_calls, [('', (1, 2, 3), dict(a=4, b=5))])
     self.assertEqual(mock.return_value.mock_calls, [('foo', (1, 2, 3), dict(a=4, b=5))])
     mock = MagicMock()
     mock().foo.bar().baz()
     expected = [('', (), {}), ('().foo.bar', (), {}), ('().foo.bar().baz', (), {})]
     self.assertEqual(mock.mock_calls, expected)
     self.assertEqual(mock().mock_calls, call.foo.bar().baz().call_list())
     for kwargs in (dict(), dict(name='bar')):
         mock = MagicMock(**kwargs)
         int(mock.foo)
         expected = [('foo.__int__', (), {})]
         self.assertEqual(mock.mock_calls, expected)
         mock = MagicMock(**kwargs)
         mock.a()()
         expected = [('a', (), {}), ('a()', (), {})]
         self.assertEqual(mock.mock_calls, expected)
         self.assertEqual(mock.a().mock_calls, [call()])
         mock = MagicMock(**kwargs)
         mock(1)(2)(3)
         self.assertEqual(mock.mock_calls, call(1)(2)(3).call_list())
         self.assertEqual(mock().mock_calls, call(2)(3).call_list())
         self.assertEqual(mock()().mock_calls, call(3).call_list())
         mock = MagicMock(**kwargs)
         mock(1)(2)(3).a.b.c(4)
         self.assertEqual(mock.mock_calls, call(1)(2)(3).a.b.c(4).call_list())
         self.assertEqual(mock().mock_calls, call(2)(3).a.b.c(4).call_list())
         self.assertEqual(mock()().mock_calls, call(3).a.b.c(4).call_list())
         mock = MagicMock(**kwargs)
         int(mock().foo.bar().baz())
         last_call = ('().foo.bar().baz().__int__', (), {})
         self.assertEqual(mock.mock_calls[-1], last_call)
         self.assertEqual(mock().mock_calls, call.foo.bar().baz().__int__().call_list())
         self.assertEqual(mock().foo.bar().mock_calls, call.baz().__int__().call_list())
         self.assertEqual(mock().foo.bar().baz.mock_calls, call().__int__().call_list())
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:49,代码来源:testmock.py


示例7: test_mock_calls

    def test_mock_calls(self):
        mock = MagicMock()

        # need to do this because MagicMock.mock_calls used to just return
        # a MagicMock which also returned a MagicMock when __eq__ was called
        self.assertIs(mock.mock_calls == [], True)

        mock = MagicMock()
        mock()
        expected = [('', (), {})]
        self.assertEqual(mock.mock_calls, expected)

        mock.foo()
        expected.append(call.foo())
        self.assertEqual(mock.mock_calls, expected)
        # intermediate mock_calls work too
        self.assertEqual(mock.foo.mock_calls, [('', (), {})])

        mock = MagicMock()
        mock().foo(1, 2, 3, a=4, b=5)
        expected = [
            ('', (), {}), ('().foo', (1, 2, 3), dict(a=4, b=5))
        ]
        self.assertEqual(mock.mock_calls, expected)
        self.assertEqual(mock.return_value.foo.mock_calls,
                         [('', (1, 2, 3), dict(a=4, b=5))])
        self.assertEqual(mock.return_value.mock_calls,
                         [('foo', (1, 2, 3), dict(a=4, b=5))])

        mock = MagicMock()
        mock().foo.bar().baz()
        expected = [
            ('', (), {}), ('().foo.bar', (), {}),
            ('().foo.bar().baz', (), {})
        ]
        self.assertEqual(mock.mock_calls, expected)
        self.assertEqual(mock().mock_calls,
                         call.foo.bar().baz().call_list())

        for kwargs in dict(), dict(name='bar'):
            mock = MagicMock(**kwargs)
            int(mock.foo)
            expected = [('foo.__int__', (), {})]
            self.assertEqual(mock.mock_calls, expected)

            mock = MagicMock(**kwargs)
            mock.a()()
            expected = [('a', (), {}), ('a()', (), {})]
            self.assertEqual(mock.mock_calls, expected)
            self.assertEqual(mock.a().mock_calls, [call()])

            mock = MagicMock(**kwargs)
            mock(1)(2)(3)
            self.assertEqual(mock.mock_calls, call(1)(2)(3).call_list())
            self.assertEqual(mock().mock_calls, call(2)(3).call_list())
            self.assertEqual(mock()().mock_calls, call(3).call_list())

            mock = MagicMock(**kwargs)
            mock(1)(2)(3).a.b.c(4)
            self.assertEqual(mock.mock_calls,
                             call(1)(2)(3).a.b.c(4).call_list())
            self.assertEqual(mock().mock_calls,
                             call(2)(3).a.b.c(4).call_list())
            self.assertEqual(mock()().mock_calls,
                             call(3).a.b.c(4).call_list())

            mock = MagicMock(**kwargs)
            int(mock().foo.bar().baz())
            last_call = ('().foo.bar().baz().__int__', (), {})
            self.assertEqual(mock.mock_calls[-1], last_call)
            self.assertEqual(mock().mock_calls,
                             call.foo.bar().baz().__int__().call_list())
            self.assertEqual(mock().foo.bar().mock_calls,
                             call.baz().__int__().call_list())
            self.assertEqual(mock().foo.bar().baz.mock_calls,
                             call().__int__().call_list())
开发者ID:MarkTseng,项目名称:cpython,代码行数:76,代码来源:testmock.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python patch.dict函数代码示例发布时间:2022-05-27
下一篇:
Python mock.Mock类代码示例发布时间: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