test_options.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:aws-ec2rescue-linux 作者: awslabs 项目源码 文件源码
def test_options_write_config_per_module_args(self):
        """Test that attempting to write a config with per module args yields expected results."""
        configuration_path = os.path.join(self.callpath, "test/configurations/test_write.cfg")
        sys.argv = ["ec2rl", "run"]
        module_path = os.path.join(self.callpath, "test/modules/mod.d")
        modules = ec2rlcore.moduledir.ModuleDir(module_path)
        self.options = ec2rlcore.options.Options(subcommands=self.__subcommands)
        # Test for module present in modules list
        self.options.per_module_args["atop"] = {}
        self.options.per_module_args["atop"]["times"] = "1"
        # Test for module not present in modules list
        self.options.per_module_args["test"] = {}
        self.options.per_module_args["test"]["times"] = "1"
        # Test for module named "Global"
        self.options.per_module_args["Global"] = {}
        self.options.per_module_args["Global"]["times"] = "1"
        with mock.patch("{}.open".format(builtins_name), new_callable=mock.mock_open()) as open_mock:
            config = self.options.write_config(configuration_path, modules)

            self.assertIsInstance(config, configparser.ConfigParser)
            self.assertEqual(config["atop"]["times"], "1")
            self.assertEqual(config["test"]["times"], "1")
            self.assertFalse("times" in config["Global"])
            self.assertTrue(open_mock.called)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号