Skip to content

Commit

Permalink
Merge pull request #238 from e100/more_tests_and_ci_fixes
Browse files Browse the repository at this point in the history
Improving tests
  • Loading branch information
e100 authored Jun 21, 2024
2 parents ae15f4a + 1eabaab commit 6f23bee
Show file tree
Hide file tree
Showing 19 changed files with 349 additions and 58 deletions.
3 changes: 3 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/pyefis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "2.0.22"
__version__ = "2.0.23"

2 changes: 1 addition & 1 deletion src/pyefis/instruments/NumericalDisplay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
65 changes: 23 additions & 42 deletions src/pyefis/instruments/button/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,12 @@ 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)

#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)
Expand All @@ -86,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)
Expand Down Expand Up @@ -151,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):
Expand Down Expand Up @@ -178,24 +179,18 @@ 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
self.processConditions(True)


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
Expand All @@ -213,25 +208,15 @@ 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:
Expand Down Expand Up @@ -281,26 +266,22 @@ def processConditions(self,clicked=False):
if not self._button.isChecked():
self.processActions(cond['actions'])
if not cond.get('continue', False): return


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():
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):

Expand Down
11 changes: 6 additions & 5 deletions src/pyefis/instruments/gauges/arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -93,7 +90,9 @@ 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:
# Should we throw exception or log error here?
pass

def paintEvent(self, e):
start = self.startAngle
Expand Down Expand Up @@ -244,7 +243,9 @@ 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:
# Should we throw exception or log error here?
pass
# Main value text
if self.font_mask:
opt = QTextOption(Qt.AlignRight)
Expand Down
3 changes: 2 additions & 1 deletion src/pyefis/instruments/gauges/verticalBar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions tests/data/buttons/simple.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ dbkey: TSBTN{id}0
hover_show: True
condition_keys:
- HIDEBUTTON
- INT
- NUMOK
conditions:
- when: "HIDEBUTTON"
actions:
Expand Down
36 changes: 36 additions & 0 deletions tests/data/buttons/toggle2.yaml
Original file line number Diff line number Diff line change
@@ -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:
32 changes: 32 additions & 0 deletions tests/data/buttons/unknown.yaml
Original file line number Diff line number Diff line change
@@ -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

32 changes: 32 additions & 0 deletions tests/data/buttons/unknown_condition.yaml
Original file line number Diff line number Diff line change
@@ -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

32 changes: 32 additions & 0 deletions tests/data/buttons/unknown_condition2.yaml
Original file line number Diff line number Diff line change
@@ -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

21 changes: 19 additions & 2 deletions tests/instruments/airspeed/test_airspeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,24 @@ 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
fix.db.get_item("IAS").fail = False
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)
assert widget.getAirspeed() == 20
# Test branch
widget.setAirspeed(20)
widget.setAirspeed(41)
assert widget._airspeed == 41
qtbot.wait(200)


Expand All @@ -75,7 +82,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({})
Expand All @@ -99,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"
Expand Down
Loading

0 comments on commit 6f23bee

Please sign in to comment.