From c3b447cd89fd69137c19fd547041bd5e6855fa13 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 15 Feb 2019 14:20:13 +0100 Subject: [PATCH] Also check if the variants are correct --- .../{TestQualities.py => TestProfiles.py} | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) rename tests/Settings/{TestQualities.py => TestProfiles.py} (63%) diff --git a/tests/Settings/TestQualities.py b/tests/Settings/TestProfiles.py similarity index 63% rename from tests/Settings/TestQualities.py rename to tests/Settings/TestProfiles.py index a11ebba8c6..3d6b158205 100644 --- a/tests/Settings/TestQualities.py +++ b/tests/Settings/TestProfiles.py @@ -41,10 +41,17 @@ def collectAllSettingIds(): definition_container.deserialize(data.read()) return definition_container.getAllKeys() +def collectAllVariants(): + result = [] + for root, directories, filenames in os.walk(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "resources", "variants"))): + for filename in filenames: + result.append(os.path.join(root, filename)) + return result all_definition_ids = collecAllDefinitionIds() quality_filepaths = collectAllQualities() all_setting_ids = collectAllSettingIds() +variant_filepaths = collectAllVariants() ## Atempt to load all the quality types @@ -77,3 +84,31 @@ def test_validateQualityProfiles(file_name): # File can't be read, header sections missing, whatever the case, this shouldn't happen! print("Go an Exception while reading he file [%s]: %s" % (file_name, e)) assert False + + +## Attempt to load all the quality types +@pytest.mark.parametrize("file_name", variant_filepaths) +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("Go an Exception while reading he file [%s]: %s" % (file_name, e)) + assert False