def upgrade_legacy_config_file(project_dir): has_ini_config = check_if_ini_config_file_exists(project_dir) has_json_config = check_if_json_config_file_exists(project_dir) if not has_ini_config: raise ValueError("No `populus.ini` file found") elif has_json_config: raise ValueError( "Cannot upgrade config file if there is already an existing " "`populus.json` file.") ini_config_file_path = get_ini_config_file_path(project_dir) json_config_file_path = get_json_config_file_path(project_dir) upgraded_config = translate_legacy_ini_config_file(ini_config_file_path) default_config = load_default_config() config = deep_merge_dicts(default_config, upgraded_config) write_config( project_dir, config, json_config_file_path, ) backup_ini_config_file_path = "{0}.bak".format(ini_config_file_path) shutil.move(ini_config_file_path, backup_ini_config_file_path) return backup_ini_config_file_path
def test_deep_merge_with_non_mapping_as_primary_value(): dict_a = {'a': 1, 'b': {'x': 5, 'y': 6}} dict_b = {'c': 3, 'b': {'y': 7, 'z': 8}} dict_c = {'d': 5, 'b': 6} assert deep_merge_dicts(dict_a, dict_b, dict_c) == { 'a': 1, 'b': 6, 'c': 3, 'd': 5 }
def test_deep_merge_orger_precidence(): assert deep_merge_dicts({ 'a': 1, 'b': 2 }, { 'b': 3, 'c': 4 }) == { 'a': 1, 'b': 3, 'c': 4 }
def test_deep_merge_does_not_mutate(): dict_a = {'a': 1, 'b': 2} dict_b = {'b': 3, 'c': 4} dict_c = {'c': 5, 'd': 6} assert deep_merge_dicts(dict_a, dict_b, dict_c) == { 'a': 1, 'b': 3, 'c': 5, 'd': 6 } assert dict_a == {'a': 1, 'b': 2} assert dict_b == {'b': 3, 'c': 4} assert dict_c == {'c': 5, 'd': 6}
def test_deep_merge_with_multiple_args(): assert deep_merge_dicts({ 'a': 1, 'b': 2 }, { 'c': 3, 'd': 4 }) == { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
def test_deep_merge_with_non_mappings_in_secondary_value_positions(): dict_a = {'a': 1, 'b': {'x': 5, 'y': 6}} dict_b = {'c': 3, 'b': 72} dict_c = {'d': 5, 'b': {'z': 9}} assert deep_merge_dicts(dict_a, dict_b, dict_c) == { 'a': 1, 'b': { 'x': 5, 'y': 6, 'z': 9 }, 'c': 3, 'd': 5 }
def test_deep_merge_with_deep_dicts(): dict_a = {'a': 1, 'b': {'x': 5, 'y': 6}} dict_b = {'c': 3, 'b': {'y': 7, 'z': 8}} dict_c = {'d': 5, 'b': {'z': 9}} assert deep_merge_dicts(dict_a, dict_b, dict_c) == { 'a': 1, 'b': { 'x': 5, 'y': 7, 'z': 9 }, 'c': 3, 'd': 5 }
def test_deep_merge_with_single_arg(): assert deep_merge_dicts({'a': 1, 'b': 2}) == {'a': 1, 'b': 2}
def test_deep_merge_with_no_args(): assert deep_merge_dicts() == {}