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)
评论列表
文章目录