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


Python mock.assert_called_with函数代码示例

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


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

示例1: test_success

def test_success(cli_paths):
    string_io = io.StringIO()
    pytest.helpers.create_cli_project(cli_paths.test_directory_path)
    material_path = pytest.helpers.create_cli_material(
        cli_paths.test_directory_path, "test_material"
    )
    script = supriya.cli.ManageMaterialScript()
    command = ["--edit", "test_material"]
    mock_path = "supriya.cli.ProjectPackageScript._call_subprocess"
    with unittest.mock.patch(mock_path) as mock:
        mock.return_value = 0
        with uqbar.io.RedirectedStreams(stdout=string_io), uqbar.io.DirectoryChange(
            cli_paths.inner_project_path
        ):
            try:
                script(command)
            except SystemExit as exception:
                if exception.args[0]:
                    raise RuntimeError("SystemExit: {}".format(exception.code))
    pytest.helpers.compare_strings(
        r"""
        Edit candidates: 'test_material' ...
        """,
        string_io.getvalue(),
    )
    definition_path = material_path.joinpath("definition.py")
    command = "{} {!s}".format(
        supriya.config.get("core", "editor", fallback="vim"), definition_path
    )
    mock.assert_called_with(command)
开发者ID:josiah-wolf-oberholtzer,项目名称:supriya,代码行数:30,代码来源:test_cli_ManageMaterialScript_edit.py

示例2: test_init_and_close_loop_for_test

    def test_init_and_close_loop_for_test(self):
        default_loop = self.create_default_loop()

        @asynctest.lenient
        class LoopTest(asynctest.TestCase):
            failing = False

            def runTest(self):
                try:
                    self.assertIsNotNone(self.loop)
                    self.assertFalse(self.loop.close.called)
                except Exception:
                    self.failing = True
                    raise

            def runFailingTest(self):
                self.runTest()
                raise SystemError()

        for method, test in itertools.product(self.run_methods, ('runTest', 'runFailingTest', )):
            with self.subTest(method=method, test=test), \
                    unittest.mock.patch('asyncio.new_event_loop') as mock:
                mock_loop = unittest.mock.Mock(asyncio.AbstractEventLoop)
                mock.return_value = mock_loop

                case = LoopTest(test)
                try:
                    getattr(case, method)()
                except SystemError:
                    pass

                mock.assert_called_with()
                mock_loop.close.assert_called_with()
                self.assertFalse(case.failing)
                self.assertIs(default_loop, asyncio.get_event_loop())
开发者ID:foolswood,项目名称:asynctest,代码行数:35,代码来源:test_case.py

示例3: test_side_effect

    def test_side_effect(self):
        mock = Mock()

        def effect(*args, **kwargs):
            raise SystemError('kablooie')

        mock.side_effect = effect
        self.assertRaises(SystemError, mock, 1, 2, fish=3)
        mock.assert_called_with(1, 2, fish=3)

        results = [1, 2, 3]
        def effect():
            return results.pop()
        mock.side_effect = effect

        self.assertEqual([mock(), mock(), mock()], [3, 2, 1],
                          "side effect not used correctly")

        mock = Mock(side_effect=sentinel.SideEffect)
        self.assertEqual(mock.side_effect, sentinel.SideEffect,
                          "side effect in constructor not used")

        def side_effect():
            return DEFAULT
        mock = Mock(side_effect=side_effect, return_value=sentinel.RETURN)
        self.assertEqual(mock(), sentinel.RETURN)
开发者ID:MarkTseng,项目名称:cpython,代码行数:26,代码来源:testmock.py

示例4: test_received_cmd_is_invalid

 def test_received_cmd_is_invalid(self):
     inst = self.make_agent(core.BaseAgent, None)
     with unittest.mock.patch.object(inst.timer, 'wait',
                                     return_value=('invalid', None)):
         with unittest.mock.patch.object(inst.timer, 'response') as mock:
             inst.delayfunc(5)
             mock.assert_called_with(is_ok=False, detail='invalid cmd')
开发者ID:zhangjoto,项目名称:agent,代码行数:7,代码来源:test_core.py

示例5: test_callbackConnect_non_gns3_server

def test_callbackConnect_non_gns3_server(http_client):

    params = {
        "virus": True,
    }
    mock = unittest.mock.MagicMock()
    http_client._callbackConnect("GET", "/version", mock, {}, {}, params)
    assert http_client._connected is False
    mock.assert_called_with({"message": "The remote server http://127.0.0.1:8000 is not a GNS3 server"}, error=True, server=http_client)
开发者ID:AJNOURI,项目名称:gns3-gui,代码行数:9,代码来源:test_http_client.py

示例6: test_assert_called_with

 def test_assert_called_with(self):
     mock = Mock()
     mock()
     mock.assert_called_with()
     self.assertRaises(AssertionError, mock.assert_called_with, 1)
     mock.reset_mock()
     self.assertRaises(AssertionError, mock.assert_called_with)
     mock(1, 2, 3, a='fish', b='nothing')
     mock.assert_called_with(1, 2, 3, a='fish', b='nothing')
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:9,代码来源:testmock.py

示例7: test_java_exception_side_effect

 def test_java_exception_side_effect(self):
     import java
     mock = Mock(side_effect=java.lang.RuntimeException('Boom!'))
     try:
         mock(1, 2, fish=3)
     except java.lang.RuntimeException:
         pass
     self.fail('java exception not raised')
     mock.assert_called_with(1, 2, fish=3)
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:9,代码来源:testmock.py

示例8: test_callbackConnect_version_non_local

def test_callbackConnect_version_non_local(http_client):

    params = {
        "local": False,
        "version": __version__
    }
    mock = unittest.mock.MagicMock()
    http_client._callbackConnect("GET", "/version", mock, {}, {}, params)
    assert http_client._connected is False
    mock.assert_called_with({"message": "Running server is not a GNS3 local server (not started with --local)"}, error=True, server=http_client)
开发者ID:AJNOURI,项目名称:gns3-gui,代码行数:10,代码来源:test_http_client.py

示例9: test_callbackConnect_major_version_invalid

def test_callbackConnect_major_version_invalid(http_client):

    params = {
        "local": True,
        "version": "1.2.3"
    }
    mock = unittest.mock.MagicMock()
    http_client._callbackConnect("GET", "/version", mock, {}, {}, params)
    assert http_client._connected is False
    mock.assert_called_with({"message": "Client version {} differs with server version 1.2.3".format(__version__)}, error=True, server=http_client)
开发者ID:AJNOURI,项目名称:gns3-gui,代码行数:10,代码来源:test_http_client.py

示例10: test_setting_call

    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:MarkTseng,项目名称:cpython,代码行数:10,代码来源:testmock.py

示例11: test_callbackConnect_non_gns3_server

def test_callbackConnect_non_gns3_server(http_client):

    http_client.setMaxRetryConnection(0)
    params = {
        "virus": True,
    }
    mock = unittest.mock.MagicMock()
    http_client._query_waiting_connections.append((None, mock))
    http_client._callbackConnect(params)
    assert http_client._connected is False
    mock.assert_called_with({"message": "The remote server http://127.0.0.1:3080 is not a GNS3 server"}, error=True, server=None)
开发者ID:GNS3,项目名称:gns3-gui,代码行数:11,代码来源:test_http_client.py

示例12: test_callbackConnect_major_version_invalid

def test_callbackConnect_major_version_invalid(http_client):

    params = {
        "local": True,
        "version": "1.2.3"
    }
    mock = unittest.mock.MagicMock()
    http_client._query_waiting_connections.append((None, mock))
    http_client._callbackConnect(params)
    assert http_client._connected is False
    mock.assert_called_with({"message": "Client version {} is not the same as server (controller) version 1.2.3".format(__version__)}, error=True, server=None)
开发者ID:GNS3,项目名称:gns3-gui,代码行数:11,代码来源:test_http_client.py

示例13: test_java_exception_side_effect

    def test_java_exception_side_effect(self):
        import java
        mock = Mock(side_effect=java.lang.RuntimeException("Boom!"))

        # can't use assertRaises with java exceptions
        try:
            mock(1, 2, fish=3)
        except java.lang.RuntimeException:
            pass
        else:
            self.fail('java exception not raised')
        mock.assert_called_with(1,2, fish=3)
开发者ID:MarkTseng,项目名称:cpython,代码行数:12,代码来源:testmock.py

示例14: test_assert_called_with

    def test_assert_called_with(self):
        mock = Mock()
        mock()

        # Will raise an exception if it fails
        mock.assert_called_with()
        self.assertRaises(AssertionError, mock.assert_called_with, 1)

        mock.reset_mock()
        self.assertRaises(AssertionError, mock.assert_called_with)

        mock(1, 2, 3, a="fish", b="nothing")
        mock.assert_called_with(1, 2, 3, a="fish", b="nothing")
开发者ID:GaloisInc,项目名称:echronos,代码行数:13,代码来源:testmock.py

示例15: test_init_and_close_loop_for_test

    def test_init_and_close_loop_for_test(self):
        default_loop = self.create_default_loop()

        @asynctest.lenient
        class LoopTest(asynctest.TestCase):
            failing = False

            def runTest(self):
                try:
                    self.assertIsNotNone(self.loop)
                    self.assertFalse(self.loop.close.called)
                except Exception:
                    self.failing = True
                    raise

            def runFailingTest(self):
                self.runTest()
                raise SystemError()

        for method, test in itertools.product(self.run_methods, ('runTest', 'runFailingTest', )):
            with self.subTest(method=method, test=test), \
                    unittest.mock.patch('asyncio.new_event_loop') as mock:
                mock_loop = unittest.mock.Mock(asyncio.AbstractEventLoop)
                mock_loop.run_until_complete.side_effect = default_loop.run_until_complete

                if sys.version_info >= (3, 6):
                    mock_loop.shutdown_asyncgens = asynctest.CoroutineMock()

                mock.return_value = mock_loop

                case = LoopTest(test)
                try:
                    getattr(case, method)()
                except SystemError:
                    pass

                mock.assert_called_with()
                mock_loop.close.assert_called_with()

                if sys.version_info >= (3, 6):
                    mock_loop.shutdown_asyncgens.assert_awaited()

                # If failing is True, one of the assertions in runTest failed
                self.assertFalse(case.failing)
                # Also, ensure we didn't override the original loop
                self.assertIs(default_loop, asyncio.get_event_loop())
开发者ID:Martiusweb,项目名称:asynctest,代码行数:46,代码来源:test_case.py


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