def test_no_differences(self): users_options_dict = self.default_dict assert merge_dict(self.default_dict, users_options_dict) == self.default_dict users_options_dict = {} assert merge_dict(self.default_dict, users_options_dict) == self.default_dict
def test_add_filepicker_default_to_plugins(self): users_options_dict = { "export_plugins": { "Text": ["txt", "mslib.plugins.io.text", "save_to_txt"] } } changed_dict = merge_dict(self.default_dict, users_options_dict) assert changed_dict["export_plugins"]["Text"] == [ "txt", "mslib.plugins.io.text", "save_to_txt", "default" ]
def test_user_option_changed(self): users_options_dict = { "new_flighttrack_template": ["Kona", "Anchorage"], "new_flighttrack_flightlevel": 350, } assert self.default_dict["num_interpolation_points"] == 201 assert self.default_dict["new_flighttrack_template"] == [ 'Nagpur', 'Delhi' ] assert self.default_dict["new_flighttrack_flightlevel"] == 0 changed_dict = merge_dict(self.default_dict, users_options_dict) assert changed_dict["num_interpolation_points"] == 201 assert changed_dict["new_flighttrack_template"] == [ "Kona", "Anchorage" ] assert changed_dict["new_flighttrack_flightlevel"] == 350
def import_config(self): file_path = get_open_filename( self, "Import config", "", ";;".join(["JSON Files (*.json)", "All Files (*.*)"])) if not file_path: return # load data from selected file dir_name, file_name = fs.path.split(file_path) with fs.open_fs(dir_name) as _fs: if _fs.exists(file_name): file_content = _fs.readtext(file_name) try: json_file_data = json.loads( file_content, object_pairs_hook=dict_raise_on_duplicates_empty) except json.JSONDecodeError as e: show_popup(self, "Error while loading file", e) logging.error(f"Error while loading json file {e}") return except ValueError as e: show_popup(self, "Invalid keys detected", e) logging.error(f"Error while loading json file {e}") return if json_file_data: json_model_data = self.json_model.serialize() options = merge_dict(copy.deepcopy(json_model_data), json_file_data) if options == json_model_data: self.statusbar.showMessage("No option with new values found") return # replace existing data with new data self.json_model.init(options, editable_keys=True, editable_values=True) self.view.setColumnWidth(0, self.view.width() // 2) self.set_noneditable_items(QtCore.QModelIndex()) self.update_view() self.statusbar.showMessage("Successfully imported config") logging.debug("Imported new config data from file") else: self.statusbar.showMessage("No data found in the file") logging.debug("No data found in the file, using existing settings")
def test_user_unknown_option(self): users_options_dict = {"unknown_option": 1} changed_dict = merge_dict(self.default_dict, users_options_dict) assert changed_dict.get("num_interpolation_points") == 201 assert changed_dict.get("unknown_option", None) is None