def __dictToActionBundle(self) -> ActionBundle: dataDict = self._source # We don't want to stall the app in case of missing/wrong directories/files. # So we just return an empty ActionBundle if for some reason there is no JSON data: if dataDict is None or not dataDict.get("actions") or len( dataDict.get("actions")) == 0: return ActionBundle.createNew() # Convert action: Action actions: [Action] = [] try: for actionDict in dataDict.get("actions"): action = DictActionConverter(source=actionDict, target=Action).getConverted() if isinstance(action, Action): actions.append(action) actionBundle = ActionBundle(name=dataDict['name'], actions=actions) return actionBundle except KeyError: logger.warning("Key of actionDict could not be mapped.", exc_info=True) return ActionBundle.createNew() except Exception as e: logger.error("Unexpected exception. %s", e, exc_info=True) raise
def __init__(self, *args, **kwargs): logger.debug("Initializing class %s", __class__.__name__) # Order of steps is important from here. # 1. Load UI file super(MainWindowController, self).__init__(*args, **kwargs) uic.loadUi("mainWindow.ui", self) # Loads all widgets of .ui into my instance # 2. Init priority properties # Set StoryLogHandler which is responsible for logging into a GUI-Widget self.storyLogHandler = StoryLogHandler() # Thread handling. We later need to access the worker while running, # to be able to force stop it. So preserve window lifecycle. self.storyWorker = None # Keep thread lifecycle, so we don't need to create any new as long as this window lives self.workerThread = QThread() # Bind GUI elements. self.defineConnections() # 3. Init general properties which may depend on step 2. self.storyData = ActionBundle.createNew() # 4. Init UI self.initView()
def test_createNew_shouldCreateValidActionBundle(self): # Given expectedName = "New" # When sut = ActionBundle.createNew() # Then self.assertEqual(expectedName, sut.name) self.assertEqual(0, len(sut.actions))