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


Python MagicMock.assert_called_once_with方法代码示例

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


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

示例1: test_update_step

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once_with [as 别名]
 def test_update_step(self):
     task = self.do_configure(axes_to_scan=["x", "y"])
     positionsA = task.put_many.call_args_list[3][0][1]["positionsA"]
     self.assertEqual(len(positionsA), 11)
     self.assertEqual(positionsA[-1], 0.375)
     self.assertEqual(self.o.end_index, 4)
     self.assertEqual(len(self.o.completed_steps_lookup), 11)
     update_completed_steps = MagicMock()
     task = MagicMock()
     self.o.update_step(3, update_completed_steps, task)
     update_completed_steps.assert_called_once_with(1, self.o)
     self.assertEqual(self.o.loading, False)
     self.assertEqual(task.put_many.call_count, 2)
     self.assertEqual(task.post.call_count, 1)
     self.check_resolutions_and_use(task.put_many.call_args_list[0][0][1])
     self.assertEqual(task.post.call_args_list[0],
                      call(self.child["appendProfile"]))
     self.assertEqual(task.put_many.call_args_list[1][0][1], dict(
         timeArray=[
             500000, 500000, 500000, 500000, 100000],
         velocityMode=[
             0, 0, 0, 1, 3],
         userPrograms=[
             4, 3, 4, 2, 8],
         pointsToBuild=5,
         positionsA=[
             0.25, 0.125, 0.0, -0.125, -0.1375],
         positionsB=[
             0.1, 0.1, 0.1, 0.1, 0.1]))
开发者ID:dls-controls,项目名称:pymalcolm,代码行数:31,代码来源:test_pmactrajectorypart.py

示例2: test_getattr

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once_with [as 别名]
    def test_getattr(self):
        mocked_full = MagicMock()
        mocked_os = MagicMock()
        mocked_stat = MagicMock()
        mocked_repo = MagicMock()

        mocked_stat.simple = "stat"
        mocked_os.lstat.return_value = mocked_stat
        mocked_full.return_value = "full_path"
        mocked_repo._full_path = mocked_full

        with patch.multiple('gitfs.views.current', os=mocked_os,
                            STATS=['simple']):
            current = CurrentView(repo=mocked_repo, uid=1, gid=1,
                                  repo_path="repo_path",
                                  ignore=CachedIgnore())
            current._full_path = mocked_full

            result = current.getattr("path")
            asserted_result = {
                'st_uid': 1,
                'st_gid': 1,
                'simple': "stat"
            }
            assert result == asserted_result

            mocked_os.lstat.assert_called_once_with("full_path")
            mocked_full.assert_called_once_with("path")
开发者ID:Marius786,项目名称:gitfs,代码行数:30,代码来源:test_current.py

示例3: test_get_view

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once_with [as 别名]
    def test_get_view(self):
        mocked_index = MagicMock()
        mocked_current = MagicMock()
        mocked_view = MagicMock(return_value=mocked_current)

        router, mocks = self.get_new_router()

        router.register([
            ("/history", mocked_view),
            ("/current", mocked_view),
            ("/", MagicMock(return_value=mocked_index)),
        ])
        with patch('gitfs.router.lru_cache') as mocked_cache:
            mocked_cache.get_if_exists.return_value = None

            view, path = router.get_view("/current")
            assert view == mocked_current
            assert path == "/"
            asserted_call = {
                'repo': mocks['repo'],
                'ignore': mocks['repo'].ignore,
                'repo_path': mocks['repo_path'],
                'mount_path': mocks['mount_path'],
                'regex': "/current",
                'relative_path': "/",
                'uid': 1,
                'gid': 1,
                'branch': mocks['branch'],
                'mount_time': 0,
                'queue': mocks['queue'],
                'max_size': mocks['max_size'],
                'max_offset': mocks['max_offset'],
            }
            mocked_view.assert_called_once_with(**asserted_call)
            mocked_cache.get_if_exists.assert_called_once_with("/current")
开发者ID:Marius786,项目名称:gitfs,代码行数:37,代码来源:test_router.py

示例4: test_add_correlation_info_to_message

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once_with [as 别名]
 def test_add_correlation_info_to_message(self):
     route_message_func = MagicMock()
     with patch('meniscus.correlation.correlator.sinks.route_message',
                route_message_func):
         correlator._add_correlation_info_to_message(
             self.tenant, self.cee_msg)
     route_message_func.assert_called_once_with(self.cee_msg)
开发者ID:ProjectMeniscus,项目名称:meniscus,代码行数:9,代码来源:correlator_test.py

示例5: test_solve_conflicts_both_update_a_file

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once_with [as 别名]
    def test_solve_conflicts_both_update_a_file(self):
        mocked_theirs = MagicMock()
        mocked_ours = MagicMock(id="id", path="path")
        mocked_full = MagicMock(return_value="full_path")
        mocked_repo = MagicMock(_full_path=mocked_full)

        mocked_repo.get().data = "data"

        def conflicts():
            yield None, mocked_theirs, mocked_ours

        mock_path = 'gitfs.merges.accept_mine.open'
        with patch(mock_path, create=True) as mocked_open:
            mocked_file = MagicMock(spec=file)
            mocked_open.return_value = mocked_file

            mine = AcceptMine(mocked_repo)

            mine.solve_conflicts(conflicts())

            mocked_full.assert_called_once_with("path")
            mocked_open.assert_called_once_with("full_path", "w")
            mocked_repo.get.has_calls([call("id")])
            mocked_open().__enter__().write.assert_called_once_with("data")
            mocked_repo.index.add.assert_called_once_with("path")
开发者ID:AlexSnet,项目名称:gitfs,代码行数:27,代码来源:test_accept_mine.py

示例6: test_freeze_command

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once_with [as 别名]
    def test_freeze_command(self):
        eggs = [
            'M2Crypto==0.21.1',
            '-e [email protected]:s0undt3ch/[email protected]#egg=SaltTesting-dev',
            'bbfreeze==1.1.0',
            'bbfreeze-loader==1.1.0',
            'pycrypto==2.6'
        ]
        mock = MagicMock(
            return_value={
                'retcode': 0,
                'stdout': '\n'.join(eggs)
            }
        )
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            ret = pip.freeze()
            mock.assert_called_once_with(
                'pip freeze',
                runas=None,
                cwd=None
            )
            self.assertEqual(ret, eggs)

        # Non zero returncode raises exception?
        mock = MagicMock(return_value={'retcode': 1, 'stderr': 'CABOOOOMMM!'})
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            self.assertRaises(
                CommandExecutionError,
                pip.freeze,
            )
开发者ID:sijis,项目名称:salt,代码行数:32,代码来源:pip_test.py

示例7: test_assess_status

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once_with [as 别名]
 def test_assess_status(self):
     with patch.object(nutils, 'assess_status_func') as asf:
         callee = MagicMock()
         asf.return_value = callee
         nutils.assess_status('test-config')
         asf.assert_called_once_with('test-config')
         callee.assert_called_once_with()
开发者ID:dosaboy,项目名称:charm-neutron-api,代码行数:9,代码来源:test_neutron_api_utils.py

示例8: test_delete_sequence

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once_with [as 别名]
 def test_delete_sequence(self):
     self.mongo_handler.status = mongodb.STATUS_CONNECTED
     sequence = 'sequence01'
     delete_sequence = MagicMock()
     self.mongo_handler.delete = delete_sequence
     self.mongo_handler.delete_sequence(sequence)
     delete_sequence.assert_called_once_with('counters', {'name': sequence})
开发者ID:aelkikhia,项目名称:meniscus,代码行数:9,代码来源:mongodb_test.py

示例9: test_remove_broken_public_id

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once_with [as 别名]
    def test_remove_broken_public_id(self, remove_owner,
                                           HTTPCallbackGroup,
                                           get_associated_privates):
        # Setup
        HTTPCallbackGroup.return_value = MagicMock()
        on_success_handler = MagicMock()
        on_failure_handler = MagicMock()
        self.handler.forward_error = MagicMock()
        sip_uri = SIP_URI2

        # Test
        numbers.remove_public_id(self.db_sess,
                                 sip_uri,
                                 on_success_handler,
                                 on_failure_handler,
                                 False)

        # Fail the Priv->Pub lookup
        get_associated_privates.assert_called_once_with(sip_uri, ANY)
        HTTPCallbackGroup.assert_called_once_with(ANY, ANY)
        failure_callback = HTTPCallbackGroup.call_args[0][1]

        error = MagicMock()
        error.code = 404
        failure_callback(error)

        # Asserts
        remove_owner.assert_called_once_with(self.db_sess, sip_uri)
        self.db_sess.commit.assert_called_once()
        on_success_handler.assert_called_once_with({})
开发者ID:rkday,项目名称:ellis,代码行数:32,代码来源:numbers.py

示例10: test_connection

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once_with [as 别名]
 def test_connection(self):
     connection = MagicMock(return_value=MagicMock())
     with patch('meniscus.data.adapters.mongodb.MongoClient', connection):
         self.mongo_handler.connect()
     connection.assert_called_once_with(self.mongo_handler.mongo_servers,
                                        slave_okay=True)
     self.assertEquals(self.mongo_handler.status, mongodb.STATUS_CONNECTED)
开发者ID:aelkikhia,项目名称:meniscus,代码行数:9,代码来源:mongodb_test.py

示例11: test_create_sequence_existing_sequence

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once_with [as 别名]
 def test_create_sequence_existing_sequence(self):
     self.mongo_handler.status = mongodb.STATUS_CONNECTED
     sequence = 'sequence01'
     create_sequence = MagicMock()
     self.mongo_handler.find_one = create_sequence
     self.mongo_handler.create_sequence(sequence)
     create_sequence.assert_called_once_with('counters', {'name': sequence})
开发者ID:aelkikhia,项目名称:meniscus,代码行数:9,代码来源:mongodb_test.py

示例12: test_propagate_tle

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once_with [as 别名]
  def test_propagate_tle(self):
    """ Tests the _propagate_tle() method which is responsible for performing one round of propagation and sending the 
    new position data to the registered position data handlers. """

    # Mock time to return a known time
    old_time = time.time
    time.time = lambda : 1385438844
    
    # Create a service to test with
    test_service = sgp4_tracker.SGP4PropagationService('direct_downlink_aprs_service', 'tracker', self.standard_device_config)
    test_service.set_tle("1 37853U 11061D   13328.80218348  .00012426  00000-0  90147-3 0  6532",
                         "2 37853 101.7000 256.9348 0228543 286.4751 136.0421 14.85566785112276")

    # Register a mock position receiver
    results = None
    def test_receiver(targetting_info):
      results = targetting_info
    test_receiver2 = MagicMock()
    test_service.register_position_receiver(test_receiver)
    test_service.register_position_receiver(test_receiver2)

    # Run the propagator and verify the results
    results = test_service._propagate_tle()
    test_receiver2.assert_called_once_with(results)
    self.assertEqual(results['timestamp'], 1385438844)
    self.assertEqual(results['altitude'], 643468.9375)
    self.assertEqual(results['elevation'], -41.31524396861143)
    self.assertEqual(results['azimuth'], 111.91629687167571)
    self.assertEqual(results['latitude'], -0.9842437063337659)
    self.assertEqual(results['longitude'], -48.365802362005475)

    # Restore the time module
    time.time = old_time
开发者ID:MichiganExplorationLab,项目名称:Mercury2-HWM,代码行数:35,代码来源:test_sgp4_tracker.py

示例13: test_add_endpoint_command_parses

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once_with [as 别名]
def test_add_endpoint_command_parses():
    # Do not skip
    add_endpoint_mock = MagicMock()
    spark_controller.add_endpoint = add_endpoint_mock
    command = "add"
    name = "name"
    language = "python"
    connection_string = "url=http://location:port;username=name;password=word"
    line = " ".join([command, name, language, connection_string])

    magic.spark(line)

    add_endpoint_mock.assert_called_once_with(name, language, connection_string, False)

    # Skip
    add_endpoint_mock = MagicMock()
    spark_controller.add_endpoint = add_endpoint_mock
    command = "add"
    name = "name"
    language = "python"
    connection_string = "url=http://location:port;username=name;password=word"
    line = " ".join([command, name, language, connection_string, "skip"])

    magic.spark(line)

    add_endpoint_mock.assert_called_once_with(name, language, connection_string, True)
开发者ID:ellisonbg,项目名称:sparkmagic,代码行数:28,代码来源:test_remotesparkmagics.py

示例14: test__rvm

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once_with [as 别名]
 def test__rvm(self):
     mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
     with patch.dict(rvm.__salt__, {'cmd.run_all': mock}):
         rvm._rvm("install", "1.9.3")
         mock.assert_called_once_with(
             "/usr/local/rvm/bin/rvm install 1.9.3", runas=None
         )
开发者ID:herlo,项目名称:salt,代码行数:9,代码来源:rvm_test.py

示例15: test_install_multiple_editable

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once_with [as 别名]
    def test_install_multiple_editable(self):
        editables = [
            'git+https://github.com/jek/blinker.git#egg=Blinker',
            'git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting'
        ]

        # Passing editables as a list
        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            pip.install(editable=editables)
            mock.assert_called_once_with(
                'pip install '
                '--editable=git+https://github.com/jek/blinker.git#egg=Blinker '
                '--editable=git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting',
                runas=None,
                cwd=None
            )

        # Passing editables as a comma separated list
        mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
        with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
            pip.install(editable=','.join(editables))
            mock.assert_called_once_with(
                'pip install '
                '--editable=git+https://github.com/jek/blinker.git#egg=Blinker '
                '--editable=git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting',
                runas=None,
                cwd=None
            )
开发者ID:sijis,项目名称:salt,代码行数:31,代码来源:pip_test.py


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