|
@@ -17,6 +17,10 @@ Resources.addSearchPath(os.path.abspath(os.path.join(os.path.dirname(__file__),
|
|
|
|
|
|
|
|
|
machine_filepaths = sorted(os.listdir(os.path.join(os.path.dirname(__file__), "..", "..", "resources", "definitions")))
|
|
|
+machine_filepaths = [os.path.join(os.path.dirname(__file__), "..", "..", "resources", "definitions", filename) for filename in machine_filepaths]
|
|
|
+extruder_filepaths = sorted(os.listdir(os.path.join(os.path.dirname(__file__), "..", "..", "resources", "extruders")))
|
|
|
+extruder_filepaths = [os.path.join(os.path.dirname(__file__), "..", "..", "resources", "extruders", filename) for filename in extruder_filepaths]
|
|
|
+definition_filepaths = machine_filepaths + extruder_filepaths
|
|
|
all_meshes = os.listdir(os.path.join(os.path.dirname(__file__), "..", "..", "resources", "meshes"))
|
|
|
all_images = os.listdir(os.path.join(os.path.dirname(__file__), "..", "..", "resources", "images"))
|
|
|
|
|
@@ -29,17 +33,16 @@ def definition_container():
|
|
|
|
|
|
|
|
|
## Tests all definition containers
|
|
|
-@pytest.mark.parametrize("file_name", machine_filepaths)
|
|
|
-def test_validateMachineDefinitionContainer(file_name, definition_container):
|
|
|
+@pytest.mark.parametrize("file_path", definition_filepaths)
|
|
|
+def test_validateMachineDefinitionContainer(file_path, definition_container):
|
|
|
+ file_name = os.path.basename(file_path)
|
|
|
if file_name == "fdmprinter.def.json" or file_name == "fdmextruder.def.json":
|
|
|
return # Stop checking, these are root files.
|
|
|
|
|
|
- definition_path = os.path.join(os.path.dirname(__file__), "..", "..", "resources", "definitions")
|
|
|
- assertIsDefinitionValid(definition_container, definition_path, file_name)
|
|
|
+ assertIsDefinitionValid(definition_container, file_path)
|
|
|
|
|
|
-
|
|
|
-def assertIsDefinitionValid(definition_container, path, file_name):
|
|
|
- with open(os.path.join(path, file_name), encoding = "utf-8") as data:
|
|
|
+def assertIsDefinitionValid(definition_container, file_path):
|
|
|
+ with open(file_path, encoding = "utf-8") as data:
|
|
|
json = data.read()
|
|
|
parser, is_valid = definition_container.readAndValidateSerialized(json)
|
|
|
assert is_valid #The definition has invalid JSON structure.
|
|
@@ -57,10 +60,9 @@ def assertIsDefinitionValid(definition_container, path, file_name):
|
|
|
# When a definition container defines a "default_value" but inherits from a
|
|
|
# definition that defines a "value", the "default_value" is ineffective. This
|
|
|
# test fails on those things.
|
|
|
-@pytest.mark.parametrize("file_name", machine_filepaths)
|
|
|
-def test_validateOverridingDefaultValue(file_name: str):
|
|
|
- definition_path = os.path.join(os.path.dirname(__file__), "..", "..", "resources", "definitions", file_name)
|
|
|
- with open(definition_path, encoding = "utf-8") as f:
|
|
|
+@pytest.mark.parametrize("file_path", machine_filepaths)
|
|
|
+def test_validateOverridingDefaultValue(file_path: str):
|
|
|
+ with open(file_path, encoding = "utf-8") as f:
|
|
|
doc = json.load(f)
|
|
|
|
|
|
if "inherits" not in doc:
|
|
@@ -70,7 +72,7 @@ def test_validateOverridingDefaultValue(file_name: str):
|
|
|
parent_settings = getInheritedSettings(doc["inherits"])
|
|
|
for key, val in doc["overrides"].items():
|
|
|
if "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_name) # 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
|
|
|
# from.
|
|
@@ -130,10 +132,9 @@ 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
|
|
|
# people don't seem to be able to get used to.
|
|
|
-@pytest.mark.parametrize("file_name", machine_filepaths)
|
|
|
-def test_noId(file_name):
|
|
|
- definition_path = os.path.join(os.path.dirname(__file__), "..", "..", "resources", "definitions", file_name)
|
|
|
- with open(definition_path, encoding = "utf-8") as f:
|
|
|
+@pytest.mark.parametrize("file_path", machine_filepaths)
|
|
|
+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."
|