Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksei S <a.sasin@ultimaker.com>2018-09-18 12:10:24 +0300
committerAleksei S <a.sasin@ultimaker.com>2018-09-18 12:10:24 +0300
commitc764b31e06d4899e90758b9042941f5ecfcd2858 (patch)
tree4fea75acb0cf3e20b5c6a7f5ce84f5560ec03e57 /scripts
parent261600121a5c0402cd9e90c6593144a77f61122c (diff)
Update unit test for 'visibilit_settings' and removed unused settings from expert.cfv
CURA-5734
Diffstat (limited to 'scripts')
-rw-r--r--scripts/check_setting_visibility.py119
1 files changed, 93 insertions, 26 deletions
diff --git a/scripts/check_setting_visibility.py b/scripts/check_setting_visibility.py
index 489b00747e..37e489c072 100644
--- a/scripts/check_setting_visibility.py
+++ b/scripts/check_setting_visibility.py
@@ -21,9 +21,7 @@ class SettingVisibilityInspection:
def __init__(self) -> None:
- self.all_settings_keys = []
- self.all_settings_categories = []
-
+ self.all_settings_keys = {}
def defineAllCuraSettings(self, fdmprinter_json_path: str) -> None:
@@ -34,18 +32,20 @@ class SettingVisibilityInspection:
def _flattenAllSettings(self, json_file: Dict[str, str]) -> None:
for key, data in json_file["settings"].items(): # top level settings are categories
- self._flattenSettings(data["children"]) # actual settings are children of top level category-settings
- def _flattenSettings(self, settings: Dict[str, str]) -> None:
+ if "type" in data and data["type"] == "category":
+
+ self.all_settings_keys[key] = []
+ self._flattenSettings(data["children"], key) # actual settings are children of top level category-settings
+
+ def _flattenSettings(self, settings: Dict[str, str], category) -> None:
for key, setting in settings.items():
if "type" in setting and setting["type"] != "category":
- self.all_settings_keys.append(key)
- else:
- self.all_settings_categories.append(key)
+ self.all_settings_keys[category].append(key)
if "children" in setting:
- self._flattenSettings(setting["children"])
+ self._flattenSettings(setting["children"], category)
def getSettingsFromSettingVisibilityFile(self, file_path: str):
@@ -70,13 +70,92 @@ class SettingVisibilityInspection:
def validateSettingsVisibility(self, setting_visibility_items: Dict):
+ not_valid_categories = {}
+ not_valid_setting_by_category = {}
+ not_valid_setting_by_order = {}
+
+ visible_settings_order = [] # This list is used to make sure that the settings are in the correct order.
+ # basic.cfg -> advanced.cfg -> expert.cfg. Like: if the setting 'layer_height' in 'basic.cfg' then the same setting
+ # also should be in 'advanced.cfg'
+
+ all_settings_categories = list(self.all_settings_keys.keys())
+
+ # visibility_type = basic, advanced, expert
for visibility_type in setting_visibility:
item = setting_visibility_items[visibility_type]
- for category, settings in item.items():
- ss = 3
+ not_valid_setting_by_category[visibility_type] = [] # this list is for keeping invalid settings.
+ not_valid_categories[visibility_type] = []
+
+ for category, category_settings in item.items():
+
+ # Validate Category, If category is not defined then the test will fail
+ if category not in all_settings_categories:
+ not_valid_categories[visibility_type].append(category)
+
+ for setting in category_settings:
+
+ # Check whether the setting exist in fdmprinter.def.json or not.
+ # If the setting is defined in the wrong category or does not exist there then the test will fail
+ if setting not in self.all_settings_keys[category]:
+ not_valid_setting_by_category[visibility_type].append(setting)
+
+ # Add the 'basic' settings to the list
+ if visibility_type == "basic":
+ visible_settings_order.append(setting)
+
+
+ # Check whether the settings are added in right order or not.
+ # The basic settings should be in advanced, and advanced in expert
+ for visibility_type in setting_visibility:
+
+ # Skip the basic because it cannot be compared to previous list
+ if visibility_type == 'basic':
+ continue
+
+ all_settings_in_this_type = []
+ not_valid_setting_by_order[visibility_type] = []
+
+ item = setting_visibility_items[visibility_type]
+ for category, category_settings in item.items():
+ all_settings_in_this_type.extend(category_settings)
+ for setting in visible_settings_order:
+ if setting not in all_settings_in_this_type:
+ not_valid_setting_by_order[visibility_type].append(setting)
+
+
+ # If any of the settings is defined not correctly then the test is failed
+ has_invalid_settings = False
+
+ for type, settings in not_valid_categories.items():
+ if len(settings) > 0:
+ has_invalid_settings = True
+ print("The following categories are defined incorrectly")
+ print(" Visibility type : '%s'" % (type))
+ print(" Incorrect categories : '%s'" % (settings))
+ print()
+
+
+
+ for type, settings in not_valid_setting_by_category.items():
+ if len(settings) > 0:
+ has_invalid_settings = True
+ print("The following settings do not exist anymore in fdmprinter definition or in wrong category")
+ print(" Visibility type : '%s'" % (type))
+ print(" Incorrect settings : '%s'" % (settings))
+ print()
+
+
+ for type, settings in not_valid_setting_by_order.items():
+ if len(settings) > 0:
+ has_invalid_settings = True
+ print("The following settings are defined in the incorrect order in setting visibility definitions")
+ print(" Visibility type : '%s'" % (type))
+ print(" Incorrect settings : '%s'" % (settings))
+
+ return has_invalid_settings
if __name__ == "__main__":
@@ -89,25 +168,13 @@ if __name__ == "__main__":
setting_visibility_items = {}
for file_path in all_setting_visibility_files:
- temp = inspector.getSettingsFromSettingVisibilityFile(all_setting_visibility_files[0])
+ temp = inspector.getSettingsFromSettingVisibilityFile(file_path)
base_name = os.path.basename(file_path)
visibility_type = base_name.split('.')[0]
setting_visibility_items[visibility_type] = temp
+ has_invalid_settings = inspector.validateSettingsVisibility(setting_visibility_items)
- inspector.validateSettingsVisibility(setting_visibility_items)
-
- found_error = False
- # Validate settings
- # for item in setting_visibility:
-
-
-
-
-
-
-
-
- sys.exit(0 if not found_error else 1)
+ sys.exit(0 if not has_invalid_settings else 1)