def test_validateVariantProfiles(file_name):
    try:
        with open(file_name, encoding="utf-8") as data:
            serialized = data.read()
            result = InstanceContainer._readAndValidateSerialized(serialized)
            # Fairly obvious, but all the types here should be of the type quality
            assert InstanceContainer.getConfigurationTypeFromSerialized(
                serialized) == "variant"
            # All quality profiles must be linked to an existing definition.
            assert result["general"]["definition"] in all_definition_ids

            # Check that all the values that we say something about are known.
            if "values" in result:
                variant_setting_keys = set(result["values"])
                # Prune all the comments from the values
                variant_setting_keys = {
                    key
                    for key in variant_setting_keys if not key.startswith("#")
                }

                has_unknown_settings = not variant_setting_keys.issubset(
                    all_setting_ids)
                if has_unknown_settings:
                    print(
                        "The following setting(s) %s are defined in the variant %s, but not in fdmprinter.def.json"
                        % ([
                            key for key in variant_setting_keys
                            if key not in all_setting_ids
                        ], file_name))
                    assert False
    except Exception as e:
        # File can't be read, header sections missing, whatever the case, this shouldn't happen!
        print("Got an Exception while reading he file [%s]: %s" %
              (file_name, e))
        assert False
Exemple #2
0
def test_validateIntentProfiles(file_name):
    try:
        with open(file_name, encoding="utf-8") as f:
            serialized = f.read()
            result = InstanceContainer._readAndValidateSerialized(serialized)
            assert InstanceContainer.getConfigurationTypeFromSerialized(
                serialized
            ) == "intent", "The intent folder must only contain intent profiles."
            assert result["general"][
                "definition"] in all_definition_ids, "The definition for this intent profile must exist."
            assert result["metadata"].get(
                "intent_category", None
            ) is not None, "All intent profiles must have some intent category."
            assert result["metadata"].get(
                "quality_type", None
            ) is not None, "All intent profiles must be linked to some quality type."
            assert result["metadata"].get(
                "material", None
            ) is not None, "All intent profiles must be linked to some material."
            assert result["metadata"].get(
                "variant", None
            ) is not None, "All intent profiles must be linked to some variant."

            # Check that all the values that we say something about are known.
            if "values" in result:
                intent_setting_keys = set(result["values"])
                unknown_settings = intent_setting_keys - all_setting_ids
                assert len(
                    unknown_settings
                ) == 0, "The settings {setting_list} are defined in the intent {file_name}, but not in fdmprinter.def.json".format(
                    setting_list=unknown_settings, file_name=file_name)
    except Exception as e:
        # File can't be read, header sections missing, whatever the case, this shouldn't happen!
        assert False, "Got an exception while reading the file {file_name}: {err}".format(
            file_name=file_name, err=str(e))