def test_set(self): before = self._conf.get("default.cloud") self._conf.set("default.cloud", "testcloud") new_config = Config() after = new_config.get("default.cloud") assert before != after new_config.set("default.cloud", before)
class TestConfig: """ Functional tests for the configuration Config class """ def __init__(self): self._conf = None def setup(self): self._conf = Config() def test_get_notfound_defaults(self): assert self._conf.get("nothere") is None assert self._conf.get("nothere", {}) == {} assert self._conf.get("default.nothere") is None custom_default = {"foo": "bar"} assert self._conf.get("default.nothere", custom_default) == custom_default def test_get_shorthand(self): raw_result = self._conf._cloudmesh.get("default").get("cloud") default_result = self._conf.get("default").get("cloud") short_result = self._conf.get("default.cloud") assert short_result == default_result == raw_result az_conf = self._conf.get("cloud.azure") az_id = az_conf.get('credentials.AZURE_SUBSCRIPTION_ID') assert az_id is not None def test_set(self): before = self._conf.get("default.cloud") self._conf.set("default.cloud", "testcloud") new_config = Config() after = new_config.get("default.cloud") assert before != after new_config.set("default.cloud", before)
def process_arguments(arguments): version = cm4.__version__ arguments = dotdict(arguments) if arguments.get("--version"): print(version) elif arguments.get("vm"): result = cm4.vm.Vm.process_arguments(arguments) pprint(result) elif arguments.get('aws'): cm4.aws.CommandAWS.process_arguments(arguments) elif arguments.get("vcluster"): cm4.vcluster.VirtualCluster.process_arguments(arguments) elif arguments.get("batch"): cm4.batch.Batch.process_arguments(arguments) elif arguments.get("openstack"): cm4.openstack.OpenstackCM.process_arguments(arguments) elif arguments.get("data"): cm4.data.data.process_arguments(arguments) elif arguments.get("set"): config = Config() if arguments.get("cloud"): config.set("default.cloud", arguments.get("CLOUD")) elif arguments.get("group"): config.set("default.group", arguments.get("GROUP")) elif arguments.get("role"): config.set("default.role", arguments.get("ROLE")) elif arguments.get("cluster"): config.set("default.cluster", arguments.get("CLUSTER")) elif arguments.get("experiment"): config.set("default.experiment", arguments.get("EXPERIMENT")) elif arguments.get("host"): config.set("default.host", arguments.get("HOST")) elif arguments.get("--key") and arguments.get("--value"): config.set(arguments.get("--key"), arguments.get("--value")) print("Config has been updated.")