def test_contains_missing_input_output_disallows_conditions(self, condition):
     sparse_yaml_input_str = input_requirements_yaml(self.field, condition, [Values.REQUIRED])
     sparse_yaml_output_str = output_requirements_yaml(self.field, condition, [Values.ALWAYS])
     for yaml_str in (sparse_yaml_input_str, sparse_yaml_output_str):
         parsed_yaml = load(yaml_str, get_type_schema_yaml_validator())
         with pytest.raises(YAMLValidationError):
             revalidate_typeschema(parsed_yaml)
    def test_sparsity_output_only_single_value(self):
        condition = Conditions.EQUALS
        sparse_yaml_str = output_requirements_yaml(self.field, condition, Values.output_values())

        parsed_yaml = load(sparse_yaml_str, get_type_schema_yaml_validator())
        with pytest.raises(YAMLValidationError):
            revalidate_typeschema(parsed_yaml)
    def test_contains_missing_output_disallowed_values(self, value):
        condition = Conditions.EQUALS
        sparse_yaml_str = output_requirements_yaml(self.field, condition, [value])

        parsed_yaml = load(sparse_yaml_str, get_type_schema_yaml_validator())
        with pytest.raises(YAMLValidationError):
            revalidate_typeschema(parsed_yaml)
 def yaml_str_to_schema_dict(yaml_str: str) -> dict:
     """this emulates how we cast a yaml to a dict for validation in
     `datarobot_drum.drum.common.read_model_metadata_yaml` and these assumptions
     are tested in: `tests.drum.test_units.test_read_model_metadata_properly_casts_typeschema` """
     schema = load(yaml_str, get_type_schema_yaml_validator())
     revalidate_typeschema(schema)
     return schema.data
    def test_datatypes_allowed_conditions(self, condition):
        values = [Values.NUM, Values.TXT]
        input_data_type_str = input_requirements_yaml(self.field, condition, values)
        output_data_type_str = output_requirements_yaml(self.field, condition, values)

        for data_type_str in (input_data_type_str, output_data_type_str):
            parsed_yaml = load(data_type_str, get_type_schema_yaml_validator())
            revalidate_typeschema(parsed_yaml)
    def test_revalidate_typescehma_mutates_yaml_num_columns_to_int(self):
        yaml_single_int = input_requirements_yaml(self.field, Conditions.EQUALS, [1])
        yaml_int_list = input_requirements_yaml(self.field, Conditions.EQUALS, [1, 2])
        parsed_single_int = load(yaml_single_int, get_type_schema_yaml_validator())
        parsed_int_list = load(yaml_int_list, get_type_schema_yaml_validator())

        def get_value(yaml):
            return yaml[str(RequirementTypes.INPUT_REQUIREMENTS)][0]["value"].data

        assert isinstance(get_value(parsed_single_int), str)
        assert isinstance(get_value(parsed_int_list)[0], str)

        revalidate_typeschema(parsed_single_int)
        revalidate_typeschema(parsed_int_list)

        assert isinstance(get_value(parsed_single_int), int)
        assert isinstance(get_value(parsed_int_list)[0], int)
    def test_datatyped_allowed_values(self, value):
        condition = Conditions.EQUALS
        input_data_type_str = input_requirements_yaml(self.field, condition, [value])
        output_data_type_str = output_requirements_yaml(self.field, condition, [value])

        for data_type_str in (input_data_type_str, output_data_type_str):
            parsed_yaml = load(data_type_str, get_type_schema_yaml_validator())
            revalidate_typeschema(parsed_yaml)
    def test_contains_missing_input_only_single_value(self):
        condition = Conditions.EQUALS
        sparse_yaml_str = input_requirements_yaml(
            self.field, condition, [Values.FORBIDDEN, Values.SUPPORTED]
        )

        parsed_yaml = load(sparse_yaml_str, get_type_schema_yaml_validator())
        with pytest.raises(YAMLValidationError):
            revalidate_typeschema(parsed_yaml)
    def test_datatypes_multiple_values(self):
        condition = Conditions.IN
        values = Values.data_values()
        input_data_type_str = input_requirements_yaml(self.field, condition, values)
        output_data_type_str = output_requirements_yaml(self.field, condition, values)

        for data_type_str in (input_data_type_str, output_data_type_str):
            parsed_yaml = load(data_type_str, get_type_schema_yaml_validator())
            revalidate_typeschema(parsed_yaml)
    def test_contains_missing_output_only_single_value(self):
        condition = Conditions.EQUALS
        sparse_yaml_str = output_requirements_yaml(
            self.field, condition, [Values.NEVER, Values.DYNAMIC]
        )

        parsed_yaml = load(sparse_yaml_str, get_type_schema_yaml_validator())
        with pytest.raises(YAMLValidationError):
            revalidate_typeschema(parsed_yaml)
    def test_datatypes_mix_allowed_and_unallowed_values(self):
        values = [Values.NUM, Values.REQUIRED]
        condition = Conditions.EQUALS
        input_data_type_str = input_requirements_yaml(self.field, condition, values)
        output_data_type_str = output_requirements_yaml(self.field, condition, values)

        for data_type_str in (input_data_type_str, output_data_type_str):
            parsed_yaml = load(data_type_str, get_type_schema_yaml_validator())
            with pytest.raises(YAMLValidationError):
                revalidate_typeschema(parsed_yaml)
예제 #12
0
    Bool(),
    Optional(ModelMetadataKeys.INFERENCE_MODEL):
    Map({
        Optional("targetName"): Str(),
        Optional("positiveClassLabel"): Str(),
        Optional("negativeClassLabel"): Str(),
        Optional("classLabels"): Seq(Str()),
        Optional("classLabelsFile"): Str(),
        Optional("predictionThreshold"): Int(),
    }),
    Optional(ModelMetadataKeys.TRAINING_MODEL):
    Map({Optional("trainOnProject"): Str()}),
    Optional(ModelMetadataKeys.HYPERPARAMETERS):
    Any(),
    Optional(ModelMetadataKeys.VALIDATION_SCHEMA):
    get_type_schema_yaml_validator(),
    Optional(ModelMetadataKeys.CUSTOM_PREDICTOR):
    Any(),
})


def validate_config_fields(model_config, *fields):
    missing_sections = []
    for f in fields:
        if f not in model_config:
            missing_sections.append(f)

    if missing_sections:
        raise DrumCommonException(
            "The following keys are missing in {} file.\n"
            "Missing keys: {}".format(MODEL_CONFIG_FILENAME, missing_sections))
 def test_failing_on_bad_value(self, passing_yaml_string):
     bad_yaml = passing_yaml_string.replace("NUM", "oooooops")
     parsed_yaml = load(bad_yaml, get_type_schema_yaml_validator())
     with pytest.raises(YAMLValidationError):
         revalidate_typeschema(parsed_yaml)
 def test_failing_on_bad_field(self, passing_yaml_string):
     bad_yaml = passing_yaml_string.replace("sparse", "oooooops")
     with pytest.raises(YAMLValidationError):
         load(bad_yaml, get_type_schema_yaml_validator())
 def test_failing_on_bad_requirements_key(self, requirements_key, passing_yaml_string):
     bad_yaml = passing_yaml_string.replace(str(requirements_key), "oooooops")
     with pytest.raises(YAMLValidationError):
         load(bad_yaml, get_type_schema_yaml_validator())
 def test_happy_path(self, passing_yaml_string):
     parsed_yaml = load(passing_yaml_string, get_type_schema_yaml_validator())
     revalidate_typeschema(parsed_yaml)
 def test_regression_test_datatypes_multi_values(self, permutation):
     corner_case = input_requirements_yaml(Fields.DATA_TYPES, Conditions.IN, permutation)
     parsed_yaml = load(corner_case, get_type_schema_yaml_validator())
     revalidate_typeschema(parsed_yaml)
 def test_number_of_columns_cannot_use_other_values(self, value):
     yaml_str = input_requirements_yaml(self.field, Conditions.EQUALS, [value])
     parsed_yaml = load(yaml_str, get_type_schema_yaml_validator())
     with pytest.raises(YAMLValidationError):
         revalidate_typeschema(parsed_yaml)
 def test_number_of_columns_can_have_multiple_ints(self):
     yaml_str = input_requirements_yaml(self.field, Conditions.EQUALS, [1, 0, -1])
     parsed_yaml = load(yaml_str, get_type_schema_yaml_validator())
     revalidate_typeschema(parsed_yaml)
 def test_number_of_columns_can_use_all_conditions(self, condition):
     sparse_yaml_input_str = input_requirements_yaml(self.field, condition, [1])
     sparse_yaml_output_str = output_requirements_yaml(self.field, condition, [1])
     for yaml_str in (sparse_yaml_input_str, sparse_yaml_output_str):
         parsed_yaml = load(yaml_str, get_type_schema_yaml_validator())
         revalidate_typeschema(parsed_yaml)
    def test_contains_missing_input_allowed_values(self, value):
        condition = Conditions.EQUALS
        sparse_yaml_str = input_requirements_yaml(self.field, condition, [value])

        parsed_yaml = load(sparse_yaml_str, get_type_schema_yaml_validator())
        revalidate_typeschema(parsed_yaml)