From 069dc6e65d35fcc4f1167619d1e101d9dec0a5be Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 1 Nov 2019 14:52:41 +0100 Subject: [PATCH] Add test to see if definition's extruder number matches up ...with its machine definition's metadata. --- tests/Settings/TestDefinitionContainer.py | 34 ++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/Settings/TestDefinitionContainer.py b/tests/Settings/TestDefinitionContainer.py index 6590c488fc..8bb7a754d3 100644 --- a/tests/Settings/TestDefinitionContainer.py +++ b/tests/Settings/TestDefinitionContainer.py @@ -137,4 +137,36 @@ def test_noId(file_path: str): with open(file_path, encoding = "utf-8") as f: doc = json.load(f) - assert "id" not in doc, "Definitions should not have an ID field." \ No newline at end of file + assert "id" not in doc, "Definitions should not have an ID field." + +## Verifies that extruders say that they work on the same extruder_nr as what +# is listed in their machine definition. +@pytest.mark.parametrize("file_path", extruder_filepaths) +def test_extruderMatch(file_path: str): + extruder_id = os.path.basename(file_path).split(".")[0] + with open(file_path, encoding = "utf-8") as f: + doc = json.load(f) + + if "metadata" not in doc: + return # May not be desirable either, but it's probably unfinished then. + if "machine" not in doc["metadata"] or "position" not in doc["metadata"]: + return # FDMextruder doesn't have this since it's not linked to a particular printer. + machine = doc["metadata"]["machine"] + position = doc["metadata"]["position"] + + # Find the machine definition. + for machine_filepath in machine_filepaths: + machine_id = os.path.basename(machine_filepath).split(".")[0] + if machine_id == machine: + break + else: + assert False, "The machine ID {machine} is not found.".format(machine = machine) + with open(machine_filepath, encoding = "utf-8") as f: + machine_doc = json.load(f) + + # Make sure that the two match up. + assert "metadata" in machine_doc, "Machine definition missing metadata entry." + assert "machine_extruder_trains" in machine_doc["metadata"], "Machine must define extruder trains." + extruder_trains = machine_doc["metadata"]["machine_extruder_trains"] + assert position in extruder_trains, "There must be a reference to the extruder in the machine definition." + assert extruder_trains[position] == extruder_id, "The extruder referenced in the machine definition must match up." \ No newline at end of file