From 37f0f37681a89ab6eaf60e8f0974b177fb9cee56 Mon Sep 17 00:00:00 2001
From: Oscar Gustafsson <oscar.gustafsson@gmail.com>
Date: Wed, 25 Jan 2023 13:01:16 +0100
Subject: [PATCH] Increase test coverage and fix issue with removing op from
 GUI dict

---
 b_asic/GUI/drag_button.py |  5 ++++-
 test/test_gui.py          | 29 +++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/b_asic/GUI/drag_button.py b/b_asic/GUI/drag_button.py
index 85cfd734..bbdcf8dd 100644
--- a/b_asic/GUI/drag_button.py
+++ b/b_asic/GUI/drag_button.py
@@ -222,5 +222,8 @@ class DragButton(QPushButton):
         if self in self._window.pressed_operations:
             self._window.pressed_operations.remove(self)
 
-        if self in self._window.dragOperationSceneDict.keys():
+        if self in self._window.dragOperationSceneDict:
             del self._window.dragOperationSceneDict[self]
+
+        if self.operation in self._window.operationDragDict:
+            del self._window.operationDragDict[self.operation]
diff --git a/test/test_gui.py b/test/test_gui.py
index ec977a0c..8f7f3989 100644
--- a/test/test_gui.py
+++ b/test/test_gui.py
@@ -23,3 +23,32 @@ def test_load(qtbot, datadir):
     assert not widget.sfg_dict
 
     widget.exit_app()
+
+
+def test_flip(qtbot, datadir):
+    widget = GUI.MainWindow()
+    qtbot.addWidget(widget)
+    widget._load_from_file(datadir.join('twotapfir.py'))
+    sfg = widget.sfg_dict['twotapfir']
+    op = sfg.find_by_name("cmul2")
+    dragbutton = widget.operationDragDict[op[0]]
+    assert not dragbutton.is_flipped()
+    dragbutton._flip()
+    assert dragbutton.is_flipped()
+
+    widget.exit_app()
+
+
+def test_sfg_invalidated_by_remove_of_operation(qtbot, datadir):
+    widget = GUI.MainWindow()
+    qtbot.addWidget(widget)
+    widget._load_from_file(datadir.join('twotapfir.py'))
+    sfg = widget.sfg_dict['twotapfir']
+    ops_before_remove = len(widget.operationDragDict)
+    op = sfg.find_by_name("cmul2")
+    dragbutton = widget.operationDragDict[op[0]]
+    dragbutton.remove()
+    assert not widget.sfg_dict
+    assert ops_before_remove -1 == len(widget.operationDragDict)
+
+    widget.exit_app()
-- 
GitLab