Added test to check if a key in the profile is defined in the definition

This commit is contained in:
Jaime van Kessel 2019-02-15 14:06:46 +01:00
parent aefacde7d5
commit c0d75b38b7
12 changed files with 37 additions and 15 deletions

View file

@ -307,7 +307,7 @@ class CuraApplication(QtApplication):
super().initialize() super().initialize()
self.__sendCommandToSingleInstance() self.__sendCommandToSingleInstance()
self.__initializeSettingDefinitionsAndFunctions() self._initializeSettingDefinitionsAndFunctions()
self.__addAllResourcesAndContainerResources() self.__addAllResourcesAndContainerResources()
self.__addAllEmptyContainers() self.__addAllEmptyContainers()
self.__setLatestResouceVersionsForVersionUpgrade() self.__setLatestResouceVersionsForVersionUpgrade()
@ -338,7 +338,7 @@ class CuraApplication(QtApplication):
# Adds custom property types, settings types, and extra operators (functions) that need to be registered in # Adds custom property types, settings types, and extra operators (functions) that need to be registered in
# SettingDefinition and SettingFunction. # SettingDefinition and SettingFunction.
def __initializeSettingDefinitionsAndFunctions(self): def _initializeSettingDefinitionsAndFunctions(self):
self._cura_formula_functions = CuraFormulaFunctions(self) self._cura_formula_functions = CuraFormulaFunctions(self)
# Need to do this before ContainerRegistry tries to load the machines # Need to do this before ContainerRegistry tries to load the machines

View file

@ -28,7 +28,6 @@ wall_thickness = 1
infill_pattern = triangles infill_pattern = triangles
speed_infill = =math.ceil(speed_print * 50 / 60) speed_infill = =math.ceil(speed_print * 50 / 60)
prime_tower_purge_volume = 1
material_bed_temperature_layer_0 = 90 material_bed_temperature_layer_0 = 90
default_material_bed_temperature = 80 default_material_bed_temperature = 80

View file

@ -26,7 +26,6 @@ speed_wall_0 = =math.ceil(speed_wall * 30 / 40)
infill_pattern = triangles infill_pattern = triangles
speed_infill = =math.ceil(speed_print * 50 / 60) speed_infill = =math.ceil(speed_print * 50 / 60)
prime_tower_purge_volume = 1
material_bed_temperature_layer_0 = 90 material_bed_temperature_layer_0 = 90
default_material_bed_temperature = 80 default_material_bed_temperature = 80

View file

@ -27,7 +27,6 @@ speed_wall = =math.ceil(speed_print * 30 / 50)
infill_pattern = triangles infill_pattern = triangles
speed_infill = =math.ceil(speed_print * 40 / 50) speed_infill = =math.ceil(speed_print * 40 / 50)
prime_tower_purge_volume = 1
material_bed_temperature_layer_0 = 90 material_bed_temperature_layer_0 = 90
default_material_bed_temperature = 80 default_material_bed_temperature = 80

View file

@ -25,7 +25,6 @@ speed_wall = =math.ceil(speed_print * 30 / 55)
infill_pattern = triangles infill_pattern = triangles
speed_infill = =math.ceil(speed_print * 45 / 55) speed_infill = =math.ceil(speed_print * 45 / 55)
prime_tower_purge_volume = 1
material_bed_temperature_layer_0 = 90 material_bed_temperature_layer_0 = 90
default_material_bed_temperature = 80 default_material_bed_temperature = 80

View file

@ -24,7 +24,6 @@ speed_topbottom = =math.ceil(speed_print * 25 / 40)
speed_wall = =math.ceil(speed_print * 30 / 40) speed_wall = =math.ceil(speed_print * 30 / 40)
jerk_travel = 50 jerk_travel = 50
prime_tower_purge_volume = 1
material_bed_temperature_layer_0 = 90 material_bed_temperature_layer_0 = 90
default_material_bed_temperature = 80 default_material_bed_temperature = 80

View file

@ -25,7 +25,6 @@ speed_wall = =math.ceil(speed_print * 40 / 45)
speed_wall_0 = =math.ceil(speed_wall * 30 / 40) speed_wall_0 = =math.ceil(speed_wall * 30 / 40)
jerk_travel = 50 jerk_travel = 50
prime_tower_purge_volume = 1
material_bed_temperature_layer_0 = 90 material_bed_temperature_layer_0 = 90
default_material_bed_temperature = 80 default_material_bed_temperature = 80

View file

@ -24,7 +24,6 @@ speed_topbottom = =math.ceil(speed_print * 25 / 40)
speed_wall = =math.ceil(speed_print * 30 / 40) speed_wall = =math.ceil(speed_print * 30 / 40)
jerk_travel = 50 jerk_travel = 50
prime_tower_purge_volume = 1
material_bed_temperature_layer_0 = 90 material_bed_temperature_layer_0 = 90
default_material_bed_temperature = 80 default_material_bed_temperature = 80

View file

@ -30,7 +30,6 @@ material_standby_temperature = 100
multiple_mesh_overlap = 0.2 multiple_mesh_overlap = 0.2
prime_tower_enable = True prime_tower_enable = True
prime_tower_flow = 100 prime_tower_flow = 100
prime_tower_wall_thickness = =prime_tower_line_width * 2
retract_at_layer_change = False retract_at_layer_change = False
retraction_count_max = 12 retraction_count_max = 12
retraction_extra_prime_amount = 0.5 retraction_extra_prime_amount = 0.5

View file

@ -30,7 +30,6 @@ material_standby_temperature = 100
multiple_mesh_overlap = 0.2 multiple_mesh_overlap = 0.2
prime_tower_enable = True prime_tower_enable = True
prime_tower_flow = 100 prime_tower_flow = 100
prime_tower_wall_thickness = =prime_tower_line_width * 2
retract_at_layer_change = False retract_at_layer_change = False
retraction_count_max = 12 retraction_count_max = 12
retraction_extra_prime_amount = 0.5 retraction_extra_prime_amount = 0.5

View file

@ -29,7 +29,6 @@ material_standby_temperature = 100
multiple_mesh_overlap = 0.2 multiple_mesh_overlap = 0.2
prime_tower_enable = True prime_tower_enable = True
prime_tower_flow = 100 prime_tower_flow = 100
prime_tower_wall_thickness = =prime_tower_line_width * 2
retract_at_layer_change = False retract_at_layer_change = False
retraction_count_max = 12 retraction_count_max = 12
retraction_extra_prime_amount = 0.5 retraction_extra_prime_amount = 0.5

View file

@ -1,13 +1,18 @@
# Copyright (c) 2019 Ultimaker B.V. # Copyright (c) 2019 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
from unittest.mock import MagicMock
import pytest import pytest
from UM.Settings.DefinitionContainer import DefinitionContainer
from UM.Settings.InstanceContainer import InstanceContainer from UM.Settings.InstanceContainer import InstanceContainer
import os import os
import os.path import os.path
from UM.VersionUpgradeManager import VersionUpgradeManager
from cura.CuraApplication import CuraApplication
def collectAllQualities(): def collectAllQualities():
result = [] result = []
@ -25,8 +30,21 @@ def collecAllDefinitionIds():
return result return result
def collectAllSettingIds():
VersionUpgradeManager._VersionUpgradeManager__instance = VersionUpgradeManager(MagicMock())
application = CuraApplication()
application._initializeSettingDefinitionsAndFunctions()
definition_container = DefinitionContainer("whatever")
with open(os.path.join(os.path.dirname(__file__), "..", "..", "resources", "definitions", "fdmprinter.def.json"), encoding="utf-8") as data:
definition_container.deserialize(data.read())
return definition_container.getAllKeys()
all_definition_ids = collecAllDefinitionIds() all_definition_ids = collecAllDefinitionIds()
quality_filepaths = collectAllQualities() quality_filepaths = collectAllQualities()
all_setting_ids = collectAllSettingIds()
## Atempt to load all the quality types ## Atempt to load all the quality types
@ -34,13 +52,27 @@ quality_filepaths = collectAllQualities()
def test_validateQualityProfiles(file_name): def test_validateQualityProfiles(file_name):
try: try:
with open(file_name, encoding="utf-8") as data: with open(file_name, encoding="utf-8") as data:
json = data.read() serialized = data.read()
result = InstanceContainer._readAndValidateSerialized(json) result = InstanceContainer._readAndValidateSerialized(serialized)
# Fairly obvious, but all the types here should be of the type quality # Fairly obvious, but all the types here should be of the type quality
assert InstanceContainer.getConfigurationTypeFromSerialized(json) == "quality" assert InstanceContainer.getConfigurationTypeFromSerialized(serialized) == "quality"
# All quality profiles must be linked to an existing definition. # All quality profiles must be linked to an existing definition.
assert result["general"]["definition"] in all_definition_ids assert result["general"]["definition"] in all_definition_ids
# We don't care what the value is, as long as it's there.
assert result["metadata"].get("quality_type", None) is not None
# Check that all the values that we say something about are known.
if "values" in result:
quality_setting_keys = set(result["values"])
# Prune all the comments from the values
quality_setting_keys = {key for key in quality_setting_keys if not key.startswith("#")}
has_unknown_settings = not quality_setting_keys.issubset(all_setting_ids)
if has_unknown_settings:
print("The following setting(s) %s are defined in the quality %s, but not in fdmprinter.def.json" % ([key for key in quality_setting_keys if key not in all_setting_ids], file_name))
assert False
except Exception as e: except Exception as e:
# File can't be read, header sections missing, whatever the case, this shouldn't happen! # 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)) print("Go an Exception while reading he file [%s]: %s" % (file_name, e))