def test_dict_need_all_keys(d1): dict_t = vd.Dict(one=vd.Str(), two=vd.Str(), three=vd.Bool()).opts(need_all_keys=True) with pytest.raises(vd.ValidatorException): dict_t(d1) d1["three"] = True assert dict_t(d1) == d1
def test_dict_unknown_keys(d1): dict_t = vd.Dict(one=vd.Str(), two=vd.Str()).opts(only_known_keys=False) d1["three"] = 79 assert dict_t(d1) == d1 parsed_dict = dict_t(d1) assert parsed_dict.one == "hello" assert parsed_dict.two == "world" assert parsed_dict["one"] == "hello" assert parsed_dict["two"] == "world" assert parsed_dict["three"] == 79
def test_str(): str_t = vd.Str() assert str_t("hello world") == "hello world" with pytest.raises(vd.ValidatorException): str_t(4) with pytest.raises(vd.ValidatorException): str_t(True)
def test_choice_validators(): choice_t = vd.Choice(vd.Str(), vd.Bool()) assert choice_t(True) is True assert choice_t("True") == "True" with pytest.raises(vd.ValidatorException): choice_t(8) with pytest.raises(vd.ValidatorException): choice_t(dict(one=1, two="2"))
def test_dict_default_value(d1): dict_t = vd.Dict(one=vd.Str(), two=vd.Str()).opts(only_known_keys=False, default_val_type=vd.Str()) d1["three"] = "a string" assert dict_t(d1) == d1 parsed_dict = dict_t(d1) assert parsed_dict.one == "hello" assert parsed_dict.two == "world" assert parsed_dict["one"] == "hello" assert parsed_dict["two"] == "world" assert parsed_dict["three"] == "a string" d1["three"] = 79 with pytest.raises(vd.ValidatorException): dict_t(d1)
def test_list1(str_list, int_list): list_t1 = vd.List(vd.Str()) assert list_t1(str_list) == str_list with pytest.raises(vd.ValidatorException): list_t1(4) with pytest.raises(vd.ValidatorException): list_t1(dict(one=1, two="2")) with pytest.raises(vd.ValidatorException): list_t1(int_list)
def test_dict(d1): dict_t = vd.Dict(one=vd.Str(), two=vd.Str()) assert dict_t(d1) == d1 parsed_dict = dict_t(d1) assert parsed_dict.one == "hello" assert parsed_dict.two == "world" assert parsed_dict["one"] == "hello" assert parsed_dict["two"] == "world" with pytest.raises(vd.ValidatorException): dict_t(4) with pytest.raises(vd.ValidatorException): dict_t(dict(one=1, two="2")) with pytest.raises(vd.ValidatorException): dict_t([1, 2, 3]) with pytest.raises(vd.ValidatorException): dict_t(dict(one=1, two="2", three=3))
def test_choice_mixed(): choice_t = vd.Choice(3, 2.22, vd.Str(), vd.Bool()) assert choice_t(True) is True assert choice_t("True") == "True" assert choice_t(3) == 3 assert choice_t(2.22) == 2.22 with pytest.raises(vd.ValidatorException): choice_t(8) with pytest.raises(vd.ValidatorException): choice_t(dict(one=1, two="2")) with pytest.raises(vd.ValidatorException): choice_t(7.92342)
def test_fixed_list(str_list, int_list, mixed_list): list_t = vd.FixedList(vd.Int(), vd.Str(), vd.Int()) assert list_t(mixed_list) == mixed_list with pytest.raises(vd.ValidatorException): list_t(4) with pytest.raises(vd.ValidatorException): list_t(dict(one=1, two="2")) with pytest.raises(vd.ValidatorException): list_t(str_list) with pytest.raises(vd.ValidatorException): list_t(int_list)
def run(config): # Set up the schema stage_description = vd.Dict(glob=vd.Str(), recursive=vd.Bool(), print_dirs=vd.Bool()) all_stage_description = vd.List( vd.Object(StudyDirectory, args=stage_description)) # Process the provided config stages = all_stage_description(config) # Execute things for stage in stages: stage.execute()