Test extruders for correctness but not for validity

The validity can't be tested using the built-in validator since that one checks if there are no settings that 'override' non-existing settings. And some of the settings overridden in an extruder are not in the inheritance stack since fdmextruder doesn't inherit from fdmprinter.

We'll check though that all settings that are overridden don't override a default_value while there is a value, and whether they don't have IDs.
This commit is contained in:
Ghostkeeper 2019-11-01 14:34:07 +01:00
parent 174b326f57
commit 6e6c510dcd
No known key found for this signature in database
GPG key ID: 59A4C0959592C05C

View file

@ -33,7 +33,7 @@ def definition_container():
## Tests all definition containers ## Tests all definition containers
@pytest.mark.parametrize("file_path", definition_filepaths) @pytest.mark.parametrize("file_path", machine_filepaths)
def test_validateMachineDefinitionContainer(file_path, definition_container): def test_validateMachineDefinitionContainer(file_path, definition_container):
file_name = os.path.basename(file_path) file_name = os.path.basename(file_path)
if file_name == "fdmprinter.def.json" or file_name == "fdmextruder.def.json": if file_name == "fdmprinter.def.json" or file_name == "fdmextruder.def.json":
@ -60,7 +60,7 @@ def assertIsDefinitionValid(definition_container, file_path):
# When a definition container defines a "default_value" but inherits from a # When a definition container defines a "default_value" but inherits from a
# definition that defines a "value", the "default_value" is ineffective. This # definition that defines a "value", the "default_value" is ineffective. This
# test fails on those things. # test fails on those things.
@pytest.mark.parametrize("file_path", machine_filepaths) @pytest.mark.parametrize("file_path", definition_filepaths)
def test_validateOverridingDefaultValue(file_path: str): def test_validateOverridingDefaultValue(file_path: str):
with open(file_path, encoding = "utf-8") as f: with open(file_path, encoding = "utf-8") as f:
doc = json.load(f) doc = json.load(f)
@ -71,7 +71,7 @@ def test_validateOverridingDefaultValue(file_path: str):
return # No settings are being overridden. No need to check anything. return # No settings are being overridden. No need to check anything.
parent_settings = getInheritedSettings(doc["inherits"]) parent_settings = getInheritedSettings(doc["inherits"])
for key, val in doc["overrides"].items(): for key, val in doc["overrides"].items():
if "value" in parent_settings[key]: if key in parent_settings and "value" in parent_settings[key]:
assert "default_value" not in val, "Unnecessary default_value for {key} in {file_name}".format(key = key, file_name = file_path) # If there is a value in the parent settings, then the default_value is not effective. assert "default_value" not in val, "Unnecessary default_value for {key} in {file_name}".format(key = key, file_name = file_path) # If there is a value in the parent settings, then the default_value is not effective.
## Get all settings and their properties from a definition we're inheriting ## Get all settings and their properties from a definition we're inheriting
@ -132,7 +132,7 @@ def merge_dicts(base: Dict[str, Any], overrides: Dict[str, Any]) -> Dict[str, An
# #
# ID fields are legacy. They should not be used any more. This is legacy that # ID fields are legacy. They should not be used any more. This is legacy that
# people don't seem to be able to get used to. # people don't seem to be able to get used to.
@pytest.mark.parametrize("file_path", machine_filepaths) @pytest.mark.parametrize("file_path", definition_filepaths)
def test_noId(file_path: str): def test_noId(file_path: str):
with open(file_path, encoding = "utf-8") as f: with open(file_path, encoding = "utf-8") as f:
doc = json.load(f) doc = json.load(f)