Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
HEV - High Energy Ventilator
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
5
Issues
5
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
HEV - High Energy Ventilator
Commits
c7e30913
Commit
c7e30913
authored
Jun 25, 2021
by
Benjamin Mummery
💻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Integration testing for personal and battery display
parent
a6f1d21c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
136 additions
and
4 deletions
+136
-4
battery_handler.py
NativeUI/handler_library/battery_handler.py
+4
-3
test_widget_displays.py
NativeUI/tests/integration/test_widget_displays.py
+131
-0
batterySample.json
NativeUI/tests/unittests/fixtures/batterySample.json
+1
-1
No files found.
NativeUI/handler_library/battery_handler.py
View file @
c7e30913
...
...
@@ -35,10 +35,11 @@ class BatteryHandler(PayloadHandler):
except
KeyError
:
logging
.
debug
(
"Keyerror in battery payload: 'bat85'"
)
try
:
if
bool
(
battery_data
[
"prob_elec"
]):
new_status
[
"electrical_problem"
]
=
"ERROR ELEC."
else
:
if
battery_data
[
"prob_elec"
]
==
0
:
new_status
[
"electrical_problem"
]
=
None
else
:
new_status
[
"electrical_problem"
]
=
"ERROR ELEC."
except
KeyError
:
logging
.
debug
(
"Keyerror in battery payload: 'prob_elec'"
)
...
...
NativeUI/tests/integration/test_widget_displays.py
0 → 100644
View file @
c7e30913
import
os
import
tempfile
import
pytest
import
hevclient
from
tests.integration.integration_utils
import
start_background_arduinosim_hevserver
,
\
kill_process_group
,
assert_posix
,
assert_pythonpath
from
NativeUI
import
set_window_size
,
interpret_resolution
from
NativeUI
import
NativeUI
import
json
hevclient
.
mmFileName
=
tempfile
.
gettempdir
()
+
os
.
path
.
sep
+
"HEVCLIENT_last_Data.mmap"
PERSONAL_JSON
=
json
.
load
(
open
(
os
.
environ
[
"PYTHONPATH"
]
.
split
(
os
.
pathsep
)[
0
]
+
"/tests/unittests/fixtures/personalSample.json"
)
)
BATTERY_JSON
=
json
.
load
(
open
(
os
.
environ
[
"PYTHONPATH"
]
.
split
(
os
.
pathsep
)[
0
]
+
"/tests/unittests/fixtures/batterySample.json"
)
)
@
pytest
.
fixture
(
scope
=
"class"
)
def
background_procs
():
"""
Fixutre to start the Arduino emulator and hevserver as background
processes and kill the processes after the test.
"""
background_processes
=
start_background_arduinosim_hevserver
()
yield
background_processes
if
background_processes
is
not
None
:
for
proc
in
background_processes
:
kill_process_group
(
proc
.
pid
)
@
pytest
.
fixture
()
def
native_ui
(
qtbot
):
"""
Fixture to inject the NativeUI. Fixture waits until GUI is shown.
"""
native_gui
=
NativeUI
()
set_window_size
(
native_gui
,
windowed
=
False
,
)
qtbot
.
addWidget
(
native_gui
)
native_gui
.
show
()
qtbot
.
waitExposed
(
native_gui
)
return
native_gui
class
TestPersonalDisplay
:
def
test_personal_handler_correct_initial_text
(
background_procs
,
native_ui
,
qtbot
):
"""
Create the NativeUI with background processes in play. Manually send a personal
payload to the NativeUI get_updates method and confirm that the display updates
accordingly.
"""
assert_posix
()
assert_pythonpath
()
assert
str
(
native_ui
.
widgets
.
personal_display
.
info_label
.
text
())
==
"No personal information set"
def
test_personal_handler_correct_initial_text
(
background_procs
,
native_ui
,
qtbot
):
"""
Create the NativeUI with background processes in play. Manually send a personal
payload to the NativeUI get_updates method and confirm that the display updates
accordingly.
"""
assert_posix
()
assert_pythonpath
()
native_ui
.
get_updates
(
PERSONAL_JSON
)
assert
str
(
native_ui
.
widgets
.
personal_display
.
info_label
.
text
())
==
"Justin Atest, 1.77m"
class
TestBatteryDisplay
:
def
test_battery_display_correct_initial_text
(
background_procs
,
native_ui
,
qtbot
):
assert_posix
()
assert_pythonpath
()
assert
native_ui
.
widgets
.
battery_display
.
status
==
{
"on_mains_power"
:
False
,
"on_battery_power"
:
True
,
"battery_percent"
:
0
,
"electrical_problem"
:
"No Battery Info"
,
}
assert
str
(
native_ui
.
widgets
.
battery_display
.
text_display
.
text
())
==
"No Battery Info"
def
test_battery_display_updates_on_battery_payload_mains
(
background_procs
,
native_ui
,
qtbot
):
assert_posix
()
assert_pythonpath
()
native_ui
.
get_updates
(
BATTERY_JSON
)
assert
native_ui
.
widgets
.
battery_display
.
status
==
{
"on_mains_power"
:
True
,
"on_battery_power"
:
False
,
"battery_percent"
:
85
,
"electrical_problem"
:
None
}
assert
str
(
native_ui
.
widgets
.
battery_display
.
text_display
.
text
())
==
""
def
test_battery_display_updates_on_battery_payload_bat
(
background_procs
,
native_ui
,
qtbot
):
assert_posix
()
assert_pythonpath
()
native_ui
.
get_updates
(
{
"type"
:
"BATTERY"
,
"BATTERY"
:{
"version"
:
182
,
"timestamp"
:
0
,
"type"
:
"BATTERY"
,
"bat"
:
1
,
"ok"
:
0
,
"alarm"
:
0
,
"rdy2buf"
:
0
,
"bat85"
:
1
,
"prob_elec"
:
0
,
"dummy"
:
False
},
"alarms"
:[]
}
)
assert
native_ui
.
widgets
.
battery_display
.
status
==
{
"on_mains_power"
:
False
,
"on_battery_power"
:
True
,
"battery_percent"
:
85
,
"electrical_problem"
:
None
}
assert
str
(
native_ui
.
widgets
.
battery_display
.
text_display
.
text
())
==
"85.0
%
"
NativeUI/tests/unittests/fixtures/batterySample.json
View file @
c7e30913
...
...
@@ -5,7 +5,7 @@
"timestamp"
:
0
,
"type"
:
"BATTERY"
,
"bat"
:
0
,
"ok"
:
0
,
"ok"
:
1
,
"alarm"
:
0
,
"rdy2buf"
:
0
,
"bat85"
:
1
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment