From 4fe9abdf2e11f5a1ef8eded2258004702b800d81 Mon Sep 17 00:00:00 2001 From: Eric Blevins Date: Wed, 19 Jun 2024 20:55:43 -0400 Subject: [PATCH 01/15] Improved button tests --- conftest.py | 3 ++ tests/data/buttons/simple.yaml | 2 + tests/data/buttons/toggle2.yaml | 36 ++++++++++++++++ tests/instruments/button/test_button.py | 57 +++++++++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 tests/data/buttons/toggle2.yaml diff --git a/conftest.py b/conftest.py index aef751d5..8db78553 100644 --- a/conftest.py +++ b/conftest.py @@ -366,4 +366,7 @@ def create_numbers(key, value, old=False, bad=False, fail=False, annunciate=Fals fix.db.get_item("BARO").bad = False fix.db.get_item("BARO").fail = False + fix.db.define_item("INT", "Testing key", "int", 0, 100, "", 50000, "") + fix.db.set_value("INT", 29) + return fix diff --git a/tests/data/buttons/simple.yaml b/tests/data/buttons/simple.yaml index 47af1316..133ac5d2 100644 --- a/tests/data/buttons/simple.yaml +++ b/tests/data/buttons/simple.yaml @@ -4,6 +4,8 @@ dbkey: TSBTN{id}0 hover_show: True condition_keys: - HIDEBUTTON +- INT +- NUMOK conditions: - when: "HIDEBUTTON" actions: diff --git a/tests/data/buttons/toggle2.yaml b/tests/data/buttons/toggle2.yaml new file mode 100644 index 00000000..3fdb1747 --- /dev/null +++ b/tests/data/buttons/toggle2.yaml @@ -0,0 +1,36 @@ +type: toggle +text: "Test" +dbkey: TSBTN{id}3 +condition_keys: + - MAVMODE + - MAVSTATE + - MAVADJ +conditions: + - when: "MAVMODE eq 'checked'" + actions: + - button: checked + - set bg color: blue + - when: "MAVMODE eq 'unchecked'" + actions: + - button: unchecked + - set bg color: orange + - when: True + actions: + - set text: "True" + continue: true + - when: True + actions: + - set bg color: green + - set fg color: white + - when: False + actions: + - set text: "False" + continue: true + - when: False + actions: + - set bg color: red + - when: "MAVMODE eq 'checked'" + actions: + - button: checked + - set bg color: blue + - unknown: diff --git a/tests/instruments/button/test_button.py b/tests/instruments/button/test_button.py index 90d85808..c53c7d4f 100644 --- a/tests/instruments/button/test_button.py +++ b/tests/instruments/button/test_button.py @@ -52,6 +52,30 @@ def test_simple_button(fix,mock_parent_widget,qtbot): assert widget._buttonhide == True widget.enterEvent(None) assert fix.db.get_item("HIDEBUTTON").value == False + fix.db.get_item("INT").old = True + assert widget._db_data["INT.old"] == True + fix.db.get_item("INT").bad = False + assert widget._db_data["INT.bad"] == False + fix.db.get_item("TSBTN10").bad = True + fix.db.get_item("TSBTN10").value = True + assert widget._dbkey.bad == True + widget.hide() + fix.db.get_item("TSBTN10").bad = False + fix.db.get_item("TSBTN10").value = False + assert widget.isVisible() == False + widget.show() + fix.db.get_item("INT").fail = False + assert widget._db_data["INT.fail"] == False + fix.db.get_item("INT").annunciate = True + assert widget._db_data["INT.annunciate"] == True + fix.db.get_item("NUMOK").set_aux_value("highAlarm", 95) + assert widget._db_data["NUMOK.aux.highAlarm"] == 95 + assert widget.getTitle() == widget._title + fix.db.set_value("TSBTN10", True) + fix.db.set_value("TSBTN10", True) + assert fix.db.get_item("TSBTN10").value == False + assert widget._dbkey.value == False + widget.dbkeyChanged(False) #qtbot.wait(2000) @@ -83,9 +107,42 @@ def test_toggle_button(fix,mock_parent_widget,qtbot): widget.enc_highlight(False) assert widget._style['bg_override'] == None assert widget.enc_selectable() == True + assert widget._button.isChecked() == True + fix.db.set_value('TSBTN12', True) + assert widget._dbkey.value == True + # Test that when already set true, setting True does nothing + widget._db_data['CLICKED'] = False + widget._button.setChecked(False) + widget.dbkeyChanged(True) + assert widget._db_data['CLICKED'] == True + widget._db_data['CLICKED'] = False + widget.dbkeyChanged(True) + assert widget._db_data['CLICKED'] == False + # End already set test + #fix.db.set_value('TSBTN12', True) #qtbot.wait(2000) +def test_toggle_button2(fix,mock_parent_widget,qtbot): + hmi.initialize({}) + widget = button.Button(mock_parent_widget, config_file="tests/data/buttons/toggle2.yaml") + qtbot.addWidget(mock_parent_widget) + qtbot.addWidget(widget) + mock_parent_widget.resize(200,200) + mock_parent_widget.show() + widget.resize(100,80) + widget.show() + qtbot.waitExposed(widget) + assert widget._title == "False" + fix.db.set_value("TSBTN13", True) + assert widget._title == "True" + fix.db.set_value("TSBTN13", False) + fix.db.set_value("MAVMODE", "checked") + assert widget._button.isChecked() + fix.db.set_value("MAVMODE", "unchecked") + assert widget._button.isChecked() == False + #qtbot.wait(2000) + def test_repeat_button(fix,mock_parent_widget,qtbot): hmi.initialize({}) widget = button.Button(mock_parent_widget, config_file="tests/data/buttons/repeat.yaml") From 01e6a639dad6c2d8ef0dc9b09405becfb44ca8f0 Mon Sep 17 00:00:00 2001 From: Eric Blevins Date: Wed, 19 Jun 2024 20:56:46 -0400 Subject: [PATCH 02/15] Simplify logic by blocking signals --- src/pyefis/instruments/button/__init__.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/pyefis/instruments/button/__init__.py b/src/pyefis/instruments/button/__init__.py index e97f6872..336be2fe 100644 --- a/src/pyefis/instruments/button/__init__.py +++ b/src/pyefis/instruments/button/__init__.py @@ -67,7 +67,6 @@ def __init__(self, parent=None, config_file=None, font_family="DejaVu Sans Conde #self._dbkey.valueChanged[bool].connect(self.dbkeyChanged) self._repeat = False - self.simple_state = False if self.config['type'] == 'toggle': self._toggle = True self._button.setCheckable(True) @@ -213,25 +212,17 @@ def dbkeyChanged(self,data): else: logger.debug(f"{self._button.text()}:toggled:data={data}:self._button.isChecked({self._button.isChecked()})") if not self._repeat and not self._toggle: - # A simple button - # The logic in here is for dealing with physical buttons # Only take action if changing from False to True if not self._dbkey.value: logger.debug(f"Data is: {data}") - # Always save current state when it is false - self.simple_state = False return # Only take action if we are visible if not self.isVisible(): return logger.debug(f"data:{data} self._dbkey.value:{self._dbkey.value}") - # If we are already True, nothing new to do, we need to become false before performing another action. - if self.simple_state: return - # Save current state - self.simple_state = self._dbkey.value - # Set value back to false to prevent recursive calls - # Physical buttons should not repeat sending True for simple buttons - self._dbkey.value = False + # Block signal to prevent recursive call + with QSignalBlocker(self._dbkey): + self._dbkey.value = False self._button.setChecked(self._dbkey.value) self.processConditions(True) if self._repeat: From 111b2b5272d5121a1132afc28366f358810c249b Mon Sep 17 00:00:00 2001 From: Eric Blevins Date: Wed, 19 Jun 2024 21:05:57 -0400 Subject: [PATCH 03/15] Simplify button logic by blocking signals --- src/pyefis/instruments/button/__init__.py | 37 ++++++++--------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/src/pyefis/instruments/button/__init__.py b/src/pyefis/instruments/button/__init__.py index 336be2fe..af308d42 100644 --- a/src/pyefis/instruments/button/__init__.py +++ b/src/pyefis/instruments/button/__init__.py @@ -60,7 +60,6 @@ def __init__(self, parent=None, config_file=None, font_family="DejaVu Sans Conde # button names per node without having # to duplicate all buttons. self._dbkey = fix.db.get_item(self.config['dbkey'].replace('{id}', str(self.parent.parent.nodeID))) - self.block_data = False time.sleep(0.01) #self._button.setChecked(self._dbkey.value) @@ -177,14 +176,11 @@ def buttonToggled(self): # Toggle button toggled if self._toggle and self._button.isChecked() != self._dbkey.value: - self.block_data = True - fix.db.set_value(self._dbkey.key, self._button.isChecked()) - #self._dbkey.set_value = self._button.isChecked() - self._dbkey.output_value() - self.block_data = False + with QSignalBlocker(self._dbkey): + fix.db.set_value(self._dbkey.key, self._button.isChecked()) + self._dbkey.output_value() # Now we evaluate conditions and update the button style/text/state self.processConditions(True) - #fix.db.set_value(self._dbkey.key, self._button.isChecked()) elif not self._toggle: # Simple button @@ -192,9 +188,6 @@ def buttonToggled(self): def dbkeyChanged(self,data): - if self.block_data: - logger.debug(f"{self._button.text()}:dbkeyChanged:data={data}:self._button.isChecked({self._button.isChecked()}) - processing blocked!") - return if self._dbkey.bad: return # The same button configuration might be used on multiple screens @@ -277,21 +270,15 @@ def processConditions(self,clicked=False): def processActions(self,actions): for act in actions: for action,args in act.items(): - set_block = False - if action == 'set value': - args_data = args.split(',') - if args_data[0] in self._db or args_data[0] == self._dbkey.key: - self.block_data = True - set_block = True - try: - logger.debug(f"{self.parent.parent.getRunningScreen()}:{self._dbkey.key}:HMI:{action}:{args} Tried") - hmi.actions.trigger(action, args) - logger.debug(f"{self.parent.parent.getRunningScreen()}:{self._dbkey.key}:HMI:{action}:{args} Success") - except: - self.setStyle(action,args) - logger.debug(f"{self.parent.parent.getRunningScreen()}:{self._dbkey.key}:STYLE:{action}:{args}") - if set_block: - self.block_data = False + # Prevent recursive calls to self + with QSignalBlocker(self._dbkey): + try: + logger.debug(f"{self.parent.parent.getRunningScreen()}:{self._dbkey.key}:HMI:{action}:{args} Tried") + hmi.actions.trigger(action, args) + logger.debug(f"{self.parent.parent.getRunningScreen()}:{self._dbkey.key}:HMI:{action}:{args} Success") + except: + self.setStyle(action,args) + logger.debug(f"{self.parent.parent.getRunningScreen()}:{self._dbkey.key}:STYLE:{action}:{args}") def setStyle(self,action='',args=None): From 3ea8bb4c40549515aa1e8b608b034dd5afd9b3ae Mon Sep 17 00:00:00 2001 From: Eric Blevins Date: Wed, 19 Jun 2024 21:09:26 -0400 Subject: [PATCH 04/15] Change version to 2.0.23 --- src/pyefis/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pyefis/__init__.py b/src/pyefis/__init__.py index fc6cb763..808c318b 100644 --- a/src/pyefis/__init__.py +++ b/src/pyefis/__init__.py @@ -1,2 +1,2 @@ -__version__ = "2.0.22" +__version__ = "2.0.23" From 572a90c1daddd1e8d709acf2608c9cc46289abeb Mon Sep 17 00:00:00 2001 From: Eric Blevins Date: Wed, 19 Jun 2024 21:53:54 -0400 Subject: [PATCH 05/15] More improvements to button tests --- src/pyefis/instruments/button/__init__.py | 17 ++++++++++++----- tests/instruments/button/test_button.py | 13 +++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/pyefis/instruments/button/__init__.py b/src/pyefis/instruments/button/__init__.py index af308d42..71194f51 100644 --- a/src/pyefis/instruments/button/__init__.py +++ b/src/pyefis/instruments/button/__init__.py @@ -84,7 +84,8 @@ def __init__(self, parent=None, config_file=None, font_family="DejaVu Sans Conde self._button.setAutoRepeat(True) self._button.setAutoRepeatInterval(self.config.get('repeat_interval', 300)) self._button.setAutoRepeatDelay(self.config.get('repeat_delay', 300)) - + else: + raise SyntaxError(f"Unknown button type '{self.config['type']}'") self._button.setEnabled(True) #self._dbkey = fix.db.get_item(self.config['dbkey']) #self._dbkey.valueChanged[bool].connect(self.dbkeyChanged) @@ -149,6 +150,8 @@ def dataChanged(self,key=None,signal=None): elif signal == 'aux': for aux in self._db[key].aux: self._db_data[f"{key}.aux.{aux}"] = self._db[key].aux[aux] + else: + pass self.processConditions() def resizeEvent(self,event): @@ -209,8 +212,6 @@ def dbkeyChanged(self,data): if not self._dbkey.value: logger.debug(f"Data is: {data}") return - # Only take action if we are visible - if not self.isVisible(): return logger.debug(f"data:{data} self._dbkey.value:{self._dbkey.value}") # Block signal to prevent recursive call @@ -265,8 +266,12 @@ def processConditions(self,clicked=False): if not self._button.isChecked(): self.processActions(cond['actions']) if not cond.get('continue', False): return - - + else: # pragma: no cover + pass + else: # pragma: no cover + pass + else: # pragma: no cover + pass def processActions(self,actions): for act in actions: for action,args in act.items(): @@ -312,6 +317,8 @@ def setStyle(self,action='',args=None): if self.font_mask: if not self.font_size: self.font_size = helpers.fit_to_mask(self.width()-(self._style['border_size']*2.5),self.height()-(self._style['border_size']*2.5),self.font_mask,self.font_family) + else: # pragma: no cover + pass self.font.setPointSizeF(self.font_size) else: self.font.setPixelSize(qRound(self.height() * 38/100)) diff --git a/tests/instruments/button/test_button.py b/tests/instruments/button/test_button.py index c53c7d4f..060d21f5 100644 --- a/tests/instruments/button/test_button.py +++ b/tests/instruments/button/test_button.py @@ -76,6 +76,9 @@ def test_simple_button(fix,mock_parent_widget,qtbot): assert fix.db.get_item("TSBTN10").value == False assert widget._dbkey.value == False widget.dbkeyChanged(False) + widget.font_mask = "XXXX" + fix.db.set_value("TSBTN10", True) + assert widget.font_size != None #qtbot.wait(2000) @@ -141,6 +144,10 @@ def test_toggle_button2(fix,mock_parent_widget,qtbot): assert widget._button.isChecked() fix.db.set_value("MAVMODE", "unchecked") assert widget._button.isChecked() == False + widget.hide() + fix.db.set_value("TSBTN13", True) + widget.buttonToggled() + assert widget.isVisible() == False #qtbot.wait(2000) def test_repeat_button(fix,mock_parent_widget,qtbot): @@ -169,4 +176,10 @@ def test_repeat_button(fix,mock_parent_widget,qtbot): #qtbot.wait(1000) fix.db.get_item("TSBTN13").value = False assert round(baro.value,2) >= round(before + 0.03,2) + widget.dataChanged("t","unknown") + +def test_unknown_button_type(fix,mock_parent_widget,qtbot): + hmi.initialize({}) + with pytest.raises(SyntaxError): + widget = button.Button(mock_parent_widget, config_file="tests/data/buttons/unknown.yaml") From d170e4417ac4e7d32c192b41a285a852da327fbc Mon Sep 17 00:00:00 2001 From: Eric Blevins Date: Thu, 20 Jun 2024 16:59:19 -0400 Subject: [PATCH 06/15] Added missing unknown.yaml file --- tests/data/buttons/unknown.yaml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/data/buttons/unknown.yaml diff --git a/tests/data/buttons/unknown.yaml b/tests/data/buttons/unknown.yaml new file mode 100644 index 00000000..cb551271 --- /dev/null +++ b/tests/data/buttons/unknown.yaml @@ -0,0 +1,32 @@ +type: unknown +text: "Units" +dbkey: TSBTN{id}0 +hover_show: True +condition_keys: +- HIDEBUTTON +- INT +- NUMOK +conditions: + - when: "HIDEBUTTON" + actions: + #- button: disable + - set text: "Show\nMenu" + #- set bg color: "#00000000" + #- set fg color: "#00000000" + continue: true + - when: "not HIDEBUTTON" + actions: + #- button: enable + - set text: "Units" + #- set bg color: lightgray + #- set fg color: black + continue: true + - when: "CLICKED eq true and HIDEBUTTON" + actions: + - set text: Units + - set value: HIDEBUTTON,False + - when: "CLICKED eq true and not HIDEBUTTON" + actions: + - Set Instrument Units: "OAT,OILT1,Temperature,Pressure,Altitude:Toggle" + - set value: HIDEBUTTON,False + From 5551bc11a4b1ac3f5a85aa1f35c904bbd887cade Mon Sep 17 00:00:00 2001 From: Eric Blevins Date: Thu, 20 Jun 2024 17:11:53 -0400 Subject: [PATCH 07/15] 100% coverage for button --- tests/instruments/button/test_button.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/instruments/button/test_button.py b/tests/instruments/button/test_button.py index 060d21f5..b59e61be 100644 --- a/tests/instruments/button/test_button.py +++ b/tests/instruments/button/test_button.py @@ -56,6 +56,8 @@ def test_simple_button(fix,mock_parent_widget,qtbot): assert widget._db_data["INT.old"] == True fix.db.get_item("INT").bad = False assert widget._db_data["INT.bad"] == False + fix.db.get_item("INT").value = 66 + assert widget._db_data["INT"] == 66 fix.db.get_item("TSBTN10").bad = True fix.db.get_item("TSBTN10").value = True assert widget._dbkey.bad == True @@ -71,6 +73,8 @@ def test_simple_button(fix,mock_parent_widget,qtbot): fix.db.get_item("NUMOK").set_aux_value("highAlarm", 95) assert widget._db_data["NUMOK.aux.highAlarm"] == 95 assert widget.getTitle() == widget._title + fix.db.get_item("NUMOK").value = 33.3 + assert widget._db_data["NUMOK"] == 33.3 fix.db.set_value("TSBTN10", True) fix.db.set_value("TSBTN10", True) assert fix.db.get_item("TSBTN10").value == False From 61608677703d293d717cfcdeeefb67b8ea857bcb Mon Sep 17 00:00:00 2001 From: Eric Blevins Date: Thu, 20 Jun 2024 17:32:13 -0400 Subject: [PATCH 08/15] Remove some branches from coverage report --- src/pyefis/instruments/ai/VirtualVfr.py | 2 ++ src/pyefis/instruments/airspeed/__init__.py | 2 ++ src/pyefis/instruments/altimeter/__init__.py | 2 ++ src/pyefis/instruments/gauges/arc.py | 3 ++- src/pyefis/instruments/gauges/numeric.py | 2 ++ src/pyefis/instruments/gauges/verticalBar.py | 3 ++- src/pyefis/instruments/misc/__init__.py | 2 ++ 7 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/pyefis/instruments/ai/VirtualVfr.py b/src/pyefis/instruments/ai/VirtualVfr.py index c26fb46e..8a3a1d22 100644 --- a/src/pyefis/instruments/ai/VirtualVfr.py +++ b/src/pyefis/instruments/ai/VirtualVfr.py @@ -190,6 +190,8 @@ def resizeEvent(self, event): if not self.rendering_prohibited(): self.pov.render(self) + else: # pragma: no cover + pass def get_largest_font_size(self, width): max_size = self.height() * 0.08 #25 diff --git a/src/pyefis/instruments/airspeed/__init__.py b/src/pyefis/instruments/airspeed/__init__.py index d5a87b16..39e359f2 100644 --- a/src/pyefis/instruments/airspeed/__init__.py +++ b/src/pyefis/instruments/airspeed/__init__.py @@ -216,6 +216,8 @@ def setAirspeed(self, airspeed): if airspeed != self._airspeed: self._airspeed = airspeed self.update() + else: # pragma: no cover + pass airspeed = property(getAirspeed, setAirspeed) diff --git a/src/pyefis/instruments/altimeter/__init__.py b/src/pyefis/instruments/altimeter/__init__.py index 4399b136..568289d7 100644 --- a/src/pyefis/instruments/altimeter/__init__.py +++ b/src/pyefis/instruments/altimeter/__init__.py @@ -381,6 +381,8 @@ def setUnitSwitching(self): hmi.actions.setInstUnits.connect(self.setUnits) if self.isVisible(): self.update() + else: # pragma: no cover + pass def setUnits(self, args): x = args.split(":") diff --git a/src/pyefis/instruments/gauges/arc.py b/src/pyefis/instruments/gauges/arc.py index 6a0f1668..e12abae6 100644 --- a/src/pyefis/instruments/gauges/arc.py +++ b/src/pyefis/instruments/gauges/arc.py @@ -93,7 +93,8 @@ def resizeEvent(self, event): self.nameFontSize = helpers.fit_to_mask(self.r_width / 6, (self.r_height / 2.8)/2, self.name_font_mask, self.font_family) elif self.name_location == 'right': self.nameFontSize = helpers.fit_to_mask(self.r_width / 2.1, (self.r_height / 2.8)/2, self.name_font_mask, self.font_family) - + else: # pragma: no cover + pass def paintEvent(self, e): start = self.startAngle diff --git a/src/pyefis/instruments/gauges/numeric.py b/src/pyefis/instruments/gauges/numeric.py index 1deb0ecb..0a05481b 100644 --- a/src/pyefis/instruments/gauges/numeric.py +++ b/src/pyefis/instruments/gauges/numeric.py @@ -92,3 +92,5 @@ def paintEvent(self, event): pen.setColor(self.textColor) p.setPen(pen) p.drawText(self.unitsTextRect, self.units, opt) + else: # pragma: no cover + pass diff --git a/src/pyefis/instruments/gauges/verticalBar.py b/src/pyefis/instruments/gauges/verticalBar.py index 5c1fb12d..f1e23700 100644 --- a/src/pyefis/instruments/gauges/verticalBar.py +++ b/src/pyefis/instruments/gauges/verticalBar.py @@ -99,7 +99,8 @@ def setMode(self, args): elif args.lower() == "normal": self.normalizeMode = False self.peakMode = False - + else: # pragma: no cover + pass def resizeEvent(self, event): diff --git a/src/pyefis/instruments/misc/__init__.py b/src/pyefis/instruments/misc/__init__.py index 1de2ca73..bcaf5bc4 100644 --- a/src/pyefis/instruments/misc/__init__.py +++ b/src/pyefis/instruments/misc/__init__.py @@ -172,6 +172,8 @@ def setValue(self, value): self._value = cvalue self.setColors() self.update() + else: # pragma: no cover + pass value = property(getValue, setValue) From 5b2ead9fff1c57b5bee870f8d601475f8e1c3ad4 Mon Sep 17 00:00:00 2001 From: Eric Blevins Date: Thu, 20 Jun 2024 18:01:15 -0400 Subject: [PATCH 09/15] removed no cover and tested properly in airspeed --- src/pyefis/instruments/airspeed/__init__.py | 2 -- tests/instruments/airspeed/test_airspeed.py | 10 +++++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/pyefis/instruments/airspeed/__init__.py b/src/pyefis/instruments/airspeed/__init__.py index 39e359f2..d5a87b16 100644 --- a/src/pyefis/instruments/airspeed/__init__.py +++ b/src/pyefis/instruments/airspeed/__init__.py @@ -216,8 +216,6 @@ def setAirspeed(self, airspeed): if airspeed != self._airspeed: self._airspeed = airspeed self.update() - else: # pragma: no cover - pass airspeed = property(getAirspeed, setAirspeed) diff --git a/tests/instruments/airspeed/test_airspeed.py b/tests/instruments/airspeed/test_airspeed.py index 9e5965b3..abfb5201 100644 --- a/tests/instruments/airspeed/test_airspeed.py +++ b/tests/instruments/airspeed/test_airspeed.py @@ -59,6 +59,10 @@ def test_numerical_airspeed(fix, qtbot): widget.setAsBad(True) widget.setAsFail(True) assert widget.getAirspeed() == 20 + # Test branch + widget.setAirspeed(20) + widget.setAirspeed(41) + assert widget._airspeed == 41 qtbot.wait(200) @@ -75,7 +79,11 @@ def test_numerical_airspeed_tape(qtbot): widget.setAirspeed(40) # redraw() widget.keyPressEvent(None) widget.wheelEvent(None) - + assert widget._airspeed == 40 + # Test branch + widget.setAirspeed(40) + widget.setAirspeed(41) + assert widget._airspeed == 41 def test_numerical_airspeed_box(fix, qtbot): hmi.initialize({}) From 2379a14b0099194ef118a321c7ccb0586af09eb8 Mon Sep 17 00:00:00 2001 From: Eric Blevins Date: Thu, 20 Jun 2024 19:21:24 -0400 Subject: [PATCH 10/15] Fixed from branch tests --- src/pyefis/instruments/altimeter/__init__.py | 2 -- src/pyefis/instruments/gauges/arc.py | 6 ++---- src/pyefis/instruments/gauges/numeric.py | 2 -- src/pyefis/instruments/misc/__init__.py | 2 -- tests/instruments/altimeter/test_altimeter.py | 4 ++-- tests/instruments/gauges/test_arc.py | 18 +++++++++++++++++- tests/instruments/gauges/test_numeric.py | 3 +++ tests/instruments/gauges/test_verticalBar.py | 17 +++++++++++++++++ tests/instruments/misc/test_misc.py | 13 ++++++++++++- 9 files changed, 53 insertions(+), 14 deletions(-) diff --git a/src/pyefis/instruments/altimeter/__init__.py b/src/pyefis/instruments/altimeter/__init__.py index 568289d7..4399b136 100644 --- a/src/pyefis/instruments/altimeter/__init__.py +++ b/src/pyefis/instruments/altimeter/__init__.py @@ -381,8 +381,6 @@ def setUnitSwitching(self): hmi.actions.setInstUnits.connect(self.setUnits) if self.isVisible(): self.update() - else: # pragma: no cover - pass def setUnits(self, args): x = args.split(":") diff --git a/src/pyefis/instruments/gauges/arc.py b/src/pyefis/instruments/gauges/arc.py index e12abae6..c5b9b8a6 100644 --- a/src/pyefis/instruments/gauges/arc.py +++ b/src/pyefis/instruments/gauges/arc.py @@ -52,9 +52,6 @@ def resizeEvent(self, event): if self.width() < self.height(): self.r_height = self.get_height(self.width()) self.r_width = self.width() - if self.height() < self.r_height: - self.r_height = self.height() - self.r_width = self.get_width(self.height()) else: self.r_width = self.get_width(self.height()) self.r_height = self.height() @@ -245,7 +242,8 @@ def paintEvent(self, e): #p.drawText(QPointF( self.lrcx - x, self.lrcy - (y/1.2) ), self.name) else: p.drawText(QPointF( self.lrcx - x, self.lrcy - (y/1.1) ), self.name) - + else: # pragma: no cover + pass # Main value text if self.font_mask: opt = QTextOption(Qt.AlignRight) diff --git a/src/pyefis/instruments/gauges/numeric.py b/src/pyefis/instruments/gauges/numeric.py index 0a05481b..1deb0ecb 100644 --- a/src/pyefis/instruments/gauges/numeric.py +++ b/src/pyefis/instruments/gauges/numeric.py @@ -92,5 +92,3 @@ def paintEvent(self, event): pen.setColor(self.textColor) p.setPen(pen) p.drawText(self.unitsTextRect, self.units, opt) - else: # pragma: no cover - pass diff --git a/src/pyefis/instruments/misc/__init__.py b/src/pyefis/instruments/misc/__init__.py index bcaf5bc4..1de2ca73 100644 --- a/src/pyefis/instruments/misc/__init__.py +++ b/src/pyefis/instruments/misc/__init__.py @@ -172,8 +172,6 @@ def setValue(self, value): self._value = cvalue self.setColors() self.update() - else: # pragma: no cover - pass value = property(getValue, setValue) diff --git a/tests/instruments/altimeter/test_altimeter.py b/tests/instruments/altimeter/test_altimeter.py index e490f4e6..61f4b0fd 100644 --- a/tests/instruments/altimeter/test_altimeter.py +++ b/tests/instruments/altimeter/test_altimeter.py @@ -89,7 +89,6 @@ def test_altimeter_tape(fix,qtbot): qtbot.waitExposed(widget) widget.font_mask = None widget.resize(90,200) - #widget.paintEvent(None) @@ -127,4 +126,5 @@ def test_altimeter_tape_unit_switching(fix,qtbot): widget.setUnitSwitching() widget.keyPressEvent(None) widget.wheelEvent(None) - + widget.hide() + widget.setUnitSwitching() diff --git a/tests/instruments/gauges/test_arc.py b/tests/instruments/gauges/test_arc.py index af8bfad1..21504a54 100644 --- a/tests/instruments/gauges/test_arc.py +++ b/tests/instruments/gauges/test_arc.py @@ -17,7 +17,7 @@ def app(qtbot): def test_arc_gauge(fix,qtbot): - widget = gauges.ArcGauge() + widget = gauges.ArcGauge(min_size=True) assert widget.getRatio() == 2 # Test with no aux data first @@ -96,3 +96,19 @@ def test_arc_gauge(fix,qtbot): widget.font_ghost_mask = "0000" widget.paintEvent(None) assert tracker2.was_called_with("setAlpha", widget.font_ghost_alpha) + + +def test_arc_gauge_branches(fix,qtbot): + widget = gauges.ArcGauge(min_size=False) + assert widget.getRatio() == 2 + + # Test with no aux data first + widget.setDbkey("NUM") + widget.setupGauge() + qtbot.addWidget(widget) + widget.name_location = 'top' + widget.name_font_mask = 'XXXX' + widget.resize(100, 101) + widget.show() + qtbot.waitExposed(widget) + qtbot.wait(2000) diff --git a/tests/instruments/gauges/test_numeric.py b/tests/instruments/gauges/test_numeric.py index 62ab4fed..51b0e32a 100644 --- a/tests/instruments/gauges/test_numeric.py +++ b/tests/instruments/gauges/test_numeric.py @@ -42,3 +42,6 @@ def test_numeric_gauge(fix,qtbot): widget.units_font_ghost_mask = "0000" widget.paintEvent(None) assert tracker.was_called_with("setAlpha", widget.font_ghost_alpha) + widget.show_units = False + widget.paintEvent(None) + diff --git a/tests/instruments/gauges/test_verticalBar.py b/tests/instruments/gauges/test_verticalBar.py index 49716078..1832fb66 100644 --- a/tests/instruments/gauges/test_verticalBar.py +++ b/tests/instruments/gauges/test_verticalBar.py @@ -121,3 +121,20 @@ def test_vertical_bar_gauge(fix,qtbot): widget.paintEvent(None) widget.normalize_range = 400 widget.paintEvent(None) + +def test_vertical_bar_gauge_min_size_false(fix,qtbot): + widget = gauges.VerticalBar(min_size=False) + assert widget.getRatio() == 0.35 + widget.setDbkey("NUM") + widget.setupGauge() + qtbot.addWidget(widget) + widget.resize(300, 200) + widget.show() + qtbot.waitExposed(widget) + widget.resizeEvent(None) + widget.show_value = False + widget.resizeEvent(None) + widget.show_units = False + widget.resizeEvent(None) + widget.paintEvent(None) + diff --git a/tests/instruments/misc/test_misc.py b/tests/instruments/misc/test_misc.py index 5b9eaba3..6fce76ff 100644 --- a/tests/instruments/misc/test_misc.py +++ b/tests/instruments/misc/test_misc.py @@ -102,7 +102,18 @@ def test_value_display_set_value(fix, qtbot): fix.db.set_value("TEST",3.14) assert widget.getValue() == 3.14 - + widget.setValue(20) + assert widget._value == 20 + widget.conversionFunction = lambda x: x*2 + widget.setValue(10) + assert widget._value == 20 + widget.font_ghost_mask = None + widget.resize(100,100) + widget.show() + widget.paintEvent(None) + widget.font_ghost_mask = "XXXX" + widget.paintEvent(None) + qtbot.waitExposed(widget) #@mock.patch("pyefis.instruments.misc.fix") #def test_value_display_flags(mock_fix, qtbot): From c0dc997e699c9cbfd576964134bf20411a839b36 Mon Sep 17 00:00:00 2001 From: Eric Blevins Date: Thu, 20 Jun 2024 19:37:47 -0400 Subject: [PATCH 11/15] More test fixes --- src/pyefis/instruments/NumericalDisplay/__init__.py | 2 +- src/pyefis/instruments/ai/VirtualVfr.py | 2 -- src/pyefis/instruments/button/__init__.py | 12 ++++-------- tests/instruments/button/test_button.py | 10 ++++++++++ tests/instruments/test_numerical_display.py | 13 +++++++++++-- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/pyefis/instruments/NumericalDisplay/__init__.py b/src/pyefis/instruments/NumericalDisplay/__init__.py index d8ab50de..5fff121d 100644 --- a/src/pyefis/instruments/NumericalDisplay/__init__.py +++ b/src/pyefis/instruments/NumericalDisplay/__init__.py @@ -287,7 +287,7 @@ def redraw(self): self.centerOn(self.width() / 2, self.y_offset(scroll_value)) def getValue(self): - return self._value + return self._value # pragma: no cover def setValue(self, val): self._value = val diff --git a/src/pyefis/instruments/ai/VirtualVfr.py b/src/pyefis/instruments/ai/VirtualVfr.py index 8a3a1d22..c26fb46e 100644 --- a/src/pyefis/instruments/ai/VirtualVfr.py +++ b/src/pyefis/instruments/ai/VirtualVfr.py @@ -190,8 +190,6 @@ def resizeEvent(self, event): if not self.rendering_prohibited(): self.pov.render(self) - else: # pragma: no cover - pass def get_largest_font_size(self, width): max_size = self.height() * 0.08 #25 diff --git a/src/pyefis/instruments/button/__init__.py b/src/pyefis/instruments/button/__init__.py index 71194f51..5b5fe1d6 100644 --- a/src/pyefis/instruments/button/__init__.py +++ b/src/pyefis/instruments/button/__init__.py @@ -266,12 +266,10 @@ def processConditions(self,clicked=False): if not self._button.isChecked(): self.processActions(cond['actions']) if not cond.get('continue', False): return - else: # pragma: no cover - pass - else: # pragma: no cover - pass - else: # pragma: no cover - pass + else: + raise SyntaxError(f"condition must be a string or boolean, not: {cond['when']}") + else: + raise SyntaxError(f"Unknown confition: {cond}") def processActions(self,actions): for act in actions: for action,args in act.items(): @@ -317,8 +315,6 @@ def setStyle(self,action='',args=None): if self.font_mask: if not self.font_size: self.font_size = helpers.fit_to_mask(self.width()-(self._style['border_size']*2.5),self.height()-(self._style['border_size']*2.5),self.font_mask,self.font_family) - else: # pragma: no cover - pass self.font.setPointSizeF(self.font_size) else: self.font.setPixelSize(qRound(self.height() * 38/100)) diff --git a/tests/instruments/button/test_button.py b/tests/instruments/button/test_button.py index b59e61be..233d8d35 100644 --- a/tests/instruments/button/test_button.py +++ b/tests/instruments/button/test_button.py @@ -187,3 +187,13 @@ def test_unknown_button_type(fix,mock_parent_widget,qtbot): with pytest.raises(SyntaxError): widget = button.Button(mock_parent_widget, config_file="tests/data/buttons/unknown.yaml") +def test_unknown_button_condition(fix,mock_parent_widget,qtbot): + hmi.initialize({}) + with pytest.raises(SyntaxError): + widget = button.Button(mock_parent_widget, config_file="tests/data/buttons/unknown_condition.yaml") + +def test_unknown_button_condition2(fix,mock_parent_widget,qtbot): + hmi.initialize({}) + with pytest.raises(SyntaxError): + widget = button.Button(mock_parent_widget, config_file="tests/data/buttons/unknown_condition2.yaml") + diff --git a/tests/instruments/test_numerical_display.py b/tests/instruments/test_numerical_display.py index 2c4fa560..ee1c4d1f 100644 --- a/tests/instruments/test_numerical_display.py +++ b/tests/instruments/test_numerical_display.py @@ -15,15 +15,24 @@ def app(qtbot): def test_numerical_display_default(qtbot): - widget = NumericalDisplay(total_decimals=4, scroll_decimal=2) + widget = NumericalDisplay(total_decimals=4, scroll_decimal=0) qtbot.addWidget(widget) assert widget.total_decimals == 4 - assert widget.scroll_decimal == 2 + assert widget.scroll_decimal == 0 assert widget._bad == False assert widget.value == 0 widget.show() + widget.resize(100,400) + widget.redraw() qtbot.waitExposed(widget) assert widget.isVisible() + widget.setFail(True) + widget.setFail(True) + widget.setBad(True) + widget.setBad(True) + widget.setOld(True) + widget.setOld(True) + def test_numerical_display_decimals(qtbot): From 6a62b0a871071fe3ebe0e6df4f02dd41139c1660 Mon Sep 17 00:00:00 2001 From: Eric Blevins Date: Thu, 20 Jun 2024 19:42:19 -0400 Subject: [PATCH 12/15] added needed test files and removed no cover on arc gauge --- src/pyefis/instruments/gauges/arc.py | 8 +++--- tests/data/buttons/unknown_condition.yaml | 32 ++++++++++++++++++++++ tests/data/buttons/unknown_condition2.yaml | 32 ++++++++++++++++++++++ 3 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 tests/data/buttons/unknown_condition.yaml create mode 100644 tests/data/buttons/unknown_condition2.yaml diff --git a/src/pyefis/instruments/gauges/arc.py b/src/pyefis/instruments/gauges/arc.py index c5b9b8a6..15127808 100644 --- a/src/pyefis/instruments/gauges/arc.py +++ b/src/pyefis/instruments/gauges/arc.py @@ -90,8 +90,8 @@ def resizeEvent(self, event): self.nameFontSize = helpers.fit_to_mask(self.r_width / 6, (self.r_height / 2.8)/2, self.name_font_mask, self.font_family) elif self.name_location == 'right': self.nameFontSize = helpers.fit_to_mask(self.r_width / 2.1, (self.r_height / 2.8)/2, self.name_font_mask, self.font_family) - else: # pragma: no cover - pass + else: + raise SyntaxError(f"Unknown location: {self.name_location}") def paintEvent(self, e): start = self.startAngle @@ -242,8 +242,8 @@ def paintEvent(self, e): #p.drawText(QPointF( self.lrcx - x, self.lrcy - (y/1.2) ), self.name) else: p.drawText(QPointF( self.lrcx - x, self.lrcy - (y/1.1) ), self.name) - else: # pragma: no cover - pass + else: + raise SyntaxError(f"Unknown location: {self.name_location}") # Main value text if self.font_mask: opt = QTextOption(Qt.AlignRight) diff --git a/tests/data/buttons/unknown_condition.yaml b/tests/data/buttons/unknown_condition.yaml new file mode 100644 index 00000000..8e9b61e0 --- /dev/null +++ b/tests/data/buttons/unknown_condition.yaml @@ -0,0 +1,32 @@ +type: simple +text: "Units" +dbkey: TSBTN{id}0 +hover_show: True +condition_keys: +- HIDEBUTTON +- INT +- NUMOK +conditions: + - badsyntax: "HIDEBUTTON" + actions: + #- button: disable + - set text: "Show\nMenu" + #- set bg color: "#00000000" + #- set fg color: "#00000000" + continue: true + - when: "not HIDEBUTTON" + actions: + #- button: enable + - set text: "Units" + #- set bg color: lightgray + #- set fg color: black + continue: true + - when: "CLICKED eq true and HIDEBUTTON" + actions: + - set text: Units + - set value: HIDEBUTTON,False + - when: "CLICKED eq true and not HIDEBUTTON" + actions: + - Set Instrument Units: "OAT,OILT1,Temperature,Pressure,Altitude:Toggle" + - set value: HIDEBUTTON,False + diff --git a/tests/data/buttons/unknown_condition2.yaml b/tests/data/buttons/unknown_condition2.yaml new file mode 100644 index 00000000..44e59f7c --- /dev/null +++ b/tests/data/buttons/unknown_condition2.yaml @@ -0,0 +1,32 @@ +type: simple +text: "Units" +dbkey: TSBTN{id}0 +hover_show: True +condition_keys: +- HIDEBUTTON +- INT +- NUMOK +conditions: + - when: 100 + actions: + #- button: disable + - set text: "Show\nMenu" + #- set bg color: "#00000000" + #- set fg color: "#00000000" + continue: true + - when: "not HIDEBUTTON" + actions: + #- button: enable + - set text: "Units" + #- set bg color: lightgray + #- set fg color: black + continue: true + - when: "CLICKED eq true and HIDEBUTTON" + actions: + - set text: Units + - set value: HIDEBUTTON,False + - when: "CLICKED eq true and not HIDEBUTTON" + actions: + - Set Instrument Units: "OAT,OILT1,Temperature,Pressure,Altitude:Toggle" + - set value: HIDEBUTTON,False + From 840f02e58df7477671d245be0b22d89be1180e0b Mon Sep 17 00:00:00 2001 From: Eric Blevins Date: Thu, 20 Jun 2024 19:51:09 -0400 Subject: [PATCH 13/15] improve airspeed tests --- tests/instruments/airspeed/test_airspeed.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/instruments/airspeed/test_airspeed.py b/tests/instruments/airspeed/test_airspeed.py index abfb5201..15626871 100644 --- a/tests/instruments/airspeed/test_airspeed.py +++ b/tests/instruments/airspeed/test_airspeed.py @@ -48,6 +48,8 @@ def test_numerical_airspeed(fix, qtbot): widget.show() qtbot.waitExposed(widget) qtbot.wait(500) + widget.resize(200, 201) + widget.paintEvent(None) assert widget.item.key == "IAS" assert widget.Vs == 45 fix.db.get_item("IAS").fail = True @@ -55,6 +57,7 @@ def test_numerical_airspeed(fix, qtbot): fix.db.get_item("IAS").old = True fix.db.get_item("IAS").old = False fix.db.set_value("IAS", "20") + widget.paintEvent(None) widget.setAsOld(True) widget.setAsBad(True) widget.setAsFail(True) From c7ce18b134cbd75e4854c3dc6c20d98205581b71 Mon Sep 17 00:00:00 2001 From: Eric Blevins Date: Thu, 20 Jun 2024 19:58:59 -0400 Subject: [PATCH 14/15] Updated airspeed tests --- tests/instruments/airspeed/test_airspeed.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/instruments/airspeed/test_airspeed.py b/tests/instruments/airspeed/test_airspeed.py index 15626871..b6ea70cd 100644 --- a/tests/instruments/airspeed/test_airspeed.py +++ b/tests/instruments/airspeed/test_airspeed.py @@ -110,7 +110,13 @@ def test_numerical_airspeed_box(fix, qtbot): assert widget.valueText == "140" widget.setMode("") assert widget._modeIndicator == 0 - + widget.setMode("") + assert widget._modeIndicator == 1 + widget.setMode("") + assert widget._modeIndicator == 2 + widget.setMode("") + assert widget._modeIndicator == 0 + widget.setMode(0) fix.db.get_item("TAS").fail = True fix.db.set_value("TAS", 101) assert widget.valueText == "XXX" From 1eabaab4ea8a2ae6195869688043cb9d32c59e4e Mon Sep 17 00:00:00 2001 From: Eric Blevins Date: Thu, 20 Jun 2024 20:20:33 -0400 Subject: [PATCH 15/15] Fixed arc gauge tests --- src/pyefis/instruments/gauges/arc.py | 6 ++++-- tests/instruments/gauges/test_arc.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/pyefis/instruments/gauges/arc.py b/src/pyefis/instruments/gauges/arc.py index 15127808..35f3a765 100644 --- a/src/pyefis/instruments/gauges/arc.py +++ b/src/pyefis/instruments/gauges/arc.py @@ -91,7 +91,8 @@ def resizeEvent(self, event): elif self.name_location == 'right': self.nameFontSize = helpers.fit_to_mask(self.r_width / 2.1, (self.r_height / 2.8)/2, self.name_font_mask, self.font_family) else: - raise SyntaxError(f"Unknown location: {self.name_location}") + # Should we throw exception or log error here? + pass def paintEvent(self, e): start = self.startAngle @@ -243,7 +244,8 @@ def paintEvent(self, e): else: p.drawText(QPointF( self.lrcx - x, self.lrcy - (y/1.1) ), self.name) else: - raise SyntaxError(f"Unknown location: {self.name_location}") + # Should we throw exception or log error here? + pass # Main value text if self.font_mask: opt = QTextOption(Qt.AlignRight) diff --git a/tests/instruments/gauges/test_arc.py b/tests/instruments/gauges/test_arc.py index 21504a54..0820b623 100644 --- a/tests/instruments/gauges/test_arc.py +++ b/tests/instruments/gauges/test_arc.py @@ -112,3 +112,17 @@ def test_arc_gauge_branches(fix,qtbot): widget.show() qtbot.waitExposed(widget) qtbot.wait(2000) + + +def test_unknown_location(fix,qtbot): + widget = gauges.ArcGauge(min_size=False) + assert widget.getRatio() == 2 + widget.setDbkey("NUM") + widget.setupGauge() + qtbot.addWidget(widget) + widget.name_location = 'unknown' + widget.name_font_mask = "XXX" + hmi.initialize({}) + widget.resize(100,100) + widget.show() + widget.paintEvent(None)