def test_force_default_when_not_none(default_cfg_method): """ Test trying to set default value on a key that already has a valid value. """ default_cfg_path = os.path.join(CURRENT_PATH, "default_cfgs/default-config.yaml") actual_cfg_path = os.path.join(CURRENT_PATH, "actual_cfg/some-config.yaml") config = Config(default_cfg_path).load(actual_cfg_path) if default_cfg_method == "path": config.force_default_if_none("TEST_VALUE", default_cfg_path=default_cfg_path) elif default_cfg_method == "loaded_yaml": default_cfg = yaml_load(open(default_cfg_path)) config.force_default_if_none("TEST_VALUE", default_cfg=default_cfg) # should not have changed anything _assert_expected_cfg(config)
def test_force_default_when_none(default_cfg_method): """ Test setting default value on a key that is none """ default_cfg_path = os.path.join(CURRENT_PATH, "default_cfgs/default-config.yaml") actual_cfg_path = os.path.join(CURRENT_PATH, "actual_cfg/some-config.yaml") config = Config(default_cfg_path).load(actual_cfg_path) if default_cfg_method == "path": config.force_default_if_none("THIS_SHOULD_NOT_BE_NONE", default_cfg_path=default_cfg_path) elif default_cfg_method == "loaded_yaml": default_cfg = yaml_load(open(default_cfg_path)) config.force_default_if_none("THIS_SHOULD_NOT_BE_NONE", default_cfg=default_cfg) assert config["THIS_SHOULD_NOT_BE_NONE"] == "THIS_SHOULD_NOT_BE_NONE" _assert_expected_cfg(config)