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


Python MagicMock.assert_called_once方法代码示例

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


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

示例1: test_save_configs

# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import assert_called_once [as 别名]
  def test_save_configs(self, option_parser_mock, path_exists_mock, shutil_copy_mock, os_remove_mock,
                        get_config_resp_mock, write_config_mock, file_handler_mock, logging_mock, set_formatter_mock):
    file_handler_mock.return_value = logging.FileHandler('') # disable creating real file
    opm = option_parser_mock.return_value
    path_exists_mock.return_value = True
    shutil_copy_mock = MagicMock()
    options = self.get_mock_options()
    args = ["backup-configs"]
    opm.parse_args.return_value = (options, args)

    def get_config_resp_side_effect(ops, type, error_if_na):
      if type == "global":
        return ("version1", "")
      elif type == "core-site":
        return ("version1", "")
      elif type == "hdfs-site":
        return ("version1", "")
      elif type == "mapred-site":
        return ("version2", "")
      elif type == "hbase-site":
        return ("version2", "")
      else:
        return (None, None)

    get_config_resp_mock.side_effect = get_config_resp_side_effect
    UpgradeHelper_HDP2.main()
    shutil_copy_mock.assert_called_once()
    os_remove_mock.assert_called_once_with("logfile")
    write_expected = [call("", "global", "version1"), call("", "core-site", "version1"),
                      call("", "hdfs-site", "version1"), call("", "mapred-site", "version2"),
                      call("", "hbase-site", "version2")]
    write_config_mock.assert_has_calls(write_expected, any_order=True)
    get_config_expected = [call(options, "global", True), call(options, "core-site", True),
                           call(options, "hdfs-site", True), call(options, "mapred-site", True),
                           call(options, "hbase-site", False), call(options, "oozie-site", False),
                           call(options, "webhcat-site", False), call(options, "hive-site", False)]
    get_config_resp_mock.assert_has_calls(get_config_expected, any_order=True)
    pass
开发者ID:adamosloizou,项目名称:fiware-cosmos-ambari,代码行数:40,代码来源:TestUpgradeScript_HDP2.py


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