def test_process_makefile__shared_subtrees_with_defaults__defaults_disabled(): subtree = {"A": IsInt(default=1234), "B": IsInt(default=5678)} specs = {"A": subtree, "B": WithoutDefaults(subtree)} current = {"A": {"B": 17}, "B": {"A": 71}} expected = {"A": {"A": 1234, "B": 17}, "B": {"A": 71}} result = process_makefile(current, specs) assert result == expected
def test_process_makefile__sets_missing_keys(): current = {"A": 1} specs = { "A": IsInt(default=0), "B": IsInt(default=-1), "C": IsInt(default=-2) } expected = {"A": 1, "B": -1, "C": -2} result = process_makefile(current, specs) assert result == expected
def test_process_makefile__sets_missing_recursive__with_missing_substructure(): current = {"A": 1} specs = { "A": IsInt(default=0), "B": { "C": IsInt(default=-1), "D": IsInt(default=-2) }, } expected = {"A": 1, "B": {"C": -1, "D": -2}} result = process_makefile(current, specs) assert result == expected
def test_process_makefile__missing_list_defaults_to_empty(): current = {"A": 1} expected = {"A": 1, "B": {"C": []}} specs = {"A": IsInt, "B": {"C": [IsInt]}} result = process_makefile(current, specs) assert result == expected
def test_process_makefile__wrong_list_types(): current = {"A": 1, "B": [17, "foo"]} specs = {"A": IsInt, "B": [IsInt]} with pytest.raises(MakefileError): process_makefile(current, specs)
def test_process_makefile__dict_keys_not_found(makefile, spec): with pytest.raises(MakefileError): process_makefile(makefile, spec)
def test__preprocess_makefile__with_default__missing_value(): spec = {"Key": _PreProcessWithDefault(314)} assert {"Key": 314} == process_makefile({}, spec)
def test__preprocess_makefile__invalid_value(): spec = {"Key": _PreProcess()} with pytest.raises(MakefileError): process_makefile({"Key": False}, spec)
def test__preprocess_makefile__expected_value(): spec = {"Key": _PreProcess()} assert {"Key": 13} == process_makefile({"Key": 13}, spec)
def test_process_makefile__list_spec_must_contain_only_specs(): specs = {"A": IsInt, "B": [1, 2, IsStr]} with pytest.raises(TypeError): process_makefile({}, specs)
def test_process_makefile__fails_when_required_value_not_set(): current = {"A": 1} specs = {"A": IsInt, "B": {"C": IsInt(default=REQUIRED_VALUE)}} with pytest.raises(MakefileError): process_makefile(current, specs)
def test_process_makefile__accept_when_required_value_is_set(): current = {"A": 1, "B": {"C": 3}} expected = {"A": 1, "B": {"C": 3}} specs = {"A": IsInt, "B": {"C": IsInt(default=REQUIRED_VALUE)}} result = process_makefile(current, specs) assert result == expected
def test_validate_makefile__unexpected_type_in_current(): current = {1: []} specs = {IsInt: {IsInt: IsInt}} with pytest.raises(MakefileError): process_makefile(current, specs)
def test_validate_makefile__unexpected_type_in_reference(): current = {1: 2} specs = {IsInt: 2} with pytest.raises(TypeError): process_makefile(current, specs)
def test_process_makefile__missing_list_default_value(): current = {"A": 1} expected = {"A": 1, "B": [1, 2, 3]} specs = {"A": IsInt, "B": IsListOf(IsInt, default=[1, 2, 3])} result = process_makefile(current, specs) assert result == expected
def test_process_makefile__fails_required_value_not_set_in_dynamic_subtree(): current = {"A": 1, "B": {}} specs = {"A": IsInt, IsStr: {"C": IsInt(default=REQUIRED_VALUE)}} with pytest.raises(MakefileError): process_makefile(current, specs)
def test_process_makefile__key_specified_but_no_entries(): current = {"A": 1, "B": None} expected = {"A": 1, "B": []} specs = {"A": IsInt, "B": [IsInt]} result = process_makefile(current, specs) assert result == expected
def test_process_makefile__accept_missing_value_if_in_implicit_subtree(): current = {"A": 1} expected = {"A": 1} specs = {"A": IsInt, IsStr: {"C": IsInt(default=REQUIRED_VALUE)}} result = process_makefile(current, specs) assert result == expected
def test__preprocess_makefile__missing_value(): spec = {"Key": _PreProcess()} assert {} == process_makefile({}, spec)
def test_process_makefile__path_shown_in_exception_for_dict(): with pytest.raises(MakefileError, match=_DUMMY_PATH_STR): process_makefile([], {}, _DUMMY_PATH)
def test__preprocess_makefile__processed_value(): spec = {"Key": _PreProcess()} assert {"Key": 14} == process_makefile({"Key": "14"}, spec)
def test_process_makefile__implicit_subdict_is_allowed(): current = {"A": 1, "B": None} expected = {"A": 1, "B": {"C": 3}} specs = {"A": IsInt, "B": {"C": IsInt(default=3)}} result = process_makefile(current, specs) assert result == expected
def test__preprocess_makefile__invalid_string(): spec = {"Key": _PreProcess()} # Failures in processing should propagate out with pytest.raises(ValueError): process_makefile({"Key": "x14"}, spec)
def test_process_makefile__list_types_accepted(): current = {"A": 1, "B": [17, "Foo"]} expected = {"A": 1, "B": [17, "Foo"]} specs = {"A": IsInt, "B": [IsInt, IsStr]} result = process_makefile(current, specs) assert result == expected
def test__preprocess_makefile__with_default__expected_value(): spec = {"Key": _PreProcessWithDefault(314)} assert {"Key": 14} == process_makefile({"Key": 14}, spec)
def test_process_makefile__dict_keys_found(makefile, spec): process_makefile(makefile, spec)