Skip to content

Commit f4a76af

Browse files
Edit menu for Tank Controller + test
(cherry picked from commit 96f561d)
1 parent 62238a2 commit f4a76af

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+964
-151
lines changed

test/ui_state/main_menu_test.py

Lines changed: 97 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
The file to test the MainMenu class
33
"""
4-
54
from unittest import mock
65
from unittest.mock import ANY
76

@@ -17,31 +16,92 @@ def test_handle_key(set_next_state_mock):
1716
"""
1817
main_menu = MainMenu(Titrator())
1918

20-
main_menu.handle_key("1")
19+
main_menu.handle_key("A")
2120
set_next_state_mock.assert_called_with(ANY, True)
22-
assert set_next_state_mock.call_args.args[0].name() == "SetupTitration"
21+
assert set_next_state_mock.call_args.args[0].name() == "SetPHTarget"
2322

24-
main_menu.handle_key("2")
23+
main_menu.handle_key("B")
2524
set_next_state_mock.assert_called_with(ANY, True)
26-
assert set_next_state_mock.call_args.args[0].name() == "SetupCalibration"
25+
assert set_next_state_mock.call_args.args[0].name() == "SetThermalTarget"
2726

28-
main_menu.handle_key("3")
29-
set_next_state_mock.assert_called_with(ANY, True)
30-
assert set_next_state_mock.call_args.args[0].name() == "PrimePump"
27+
main_menu.level1 = 2
28+
main_menu.level2 = 5
29+
main_menu.handle_key("D")
30+
assert main_menu.level1 == 0
31+
assert main_menu.level2 == -1
32+
33+
main_menu.level1 = 0
34+
main_menu.level2 = -1
35+
main_menu.handle_key("2")
36+
assert main_menu.level1 == 2
37+
assert main_menu.level2 == -1
38+
39+
main_menu.level1 = 1
40+
main_menu.level2 = 0
41+
main_menu.handle_key("2")
42+
assert main_menu.level2 == main_menu.view_command_count - 1
43+
44+
main_menu.level1 = 2
45+
main_menu.level2 = 0
46+
main_menu.handle_key("2")
47+
assert main_menu.level2 == main_menu.set_command_count - 1
48+
49+
main_menu.level1 = 1
50+
main_menu.level2 = -1
51+
main_menu.handle_key("4")
52+
assert main_menu.level1 == 0
53+
assert main_menu.level2 == -1
3154

55+
main_menu.level1 = 1
56+
main_menu.level2 = 0
3257
main_menu.handle_key("4")
33-
assert main_menu.substate == 2
58+
assert main_menu.level1 == 1
59+
assert main_menu.level2 == -1
3460

35-
main_menu.handle_key("1")
61+
main_menu.level1 = 2
62+
main_menu.level2 = 0
63+
main_menu.handle_key("4")
64+
assert main_menu.level1 == 2
65+
assert main_menu.level2 == -1
66+
67+
main_menu.level1 = 0
68+
main_menu.level2 = -1
69+
main_menu.handle_key("6")
70+
assert main_menu.level1 == 1
71+
assert main_menu.level2 == -1
72+
73+
main_menu.level1 = 1
74+
main_menu.level2 = -1
75+
main_menu.handle_key("6")
76+
assert main_menu.level2 == 0
77+
78+
main_menu.level1 = 1
79+
main_menu.level2 = 0
80+
main_menu.handle_key("6")
3681
set_next_state_mock.assert_called_with(ANY, True)
37-
assert set_next_state_mock.call_args.args[0].name() == "UpdateSettings"
82+
assert main_menu.level1 == 1
3883

39-
main_menu.handle_key("2")
84+
main_menu.level1 = 2
85+
main_menu.level2 = 0
86+
main_menu.handle_key("6")
4087
set_next_state_mock.assert_called_with(ANY, True)
41-
assert set_next_state_mock.call_args.args[0].name() == "DemoModeMenu"
88+
assert main_menu.level1 == 2
4289

43-
main_menu.handle_key("4")
44-
assert main_menu.substate == 1
90+
main_menu.level1 = 0
91+
main_menu.level2 = -1
92+
main_menu.handle_key("8")
93+
assert main_menu.level1 == 1
94+
assert main_menu.level2 == -1
95+
96+
main_menu.level1 = 1
97+
main_menu.level2 = 0
98+
main_menu.handle_key("8")
99+
assert main_menu.level2 == 1
100+
101+
main_menu.level1 = 2
102+
main_menu.level2 = 0
103+
main_menu.handle_key("8")
104+
assert main_menu.level2 == 1
45105

46106

47107
@mock.patch.object(LiquidCrystal, "print")
@@ -52,77 +112,41 @@ def test_loop(print_mock):
52112
main_menu = MainMenu(Titrator())
53113

54114
main_menu.loop()
55-
print_mock.assert_has_calls(
56-
[
57-
mock.call("1: Run titration", line=1),
58-
mock.call("2: Calibrate sensors", line=2),
59-
mock.call("3: Prime pump", line=3),
60-
mock.call("4: Page 2", line=4),
61-
]
62-
)
115+
print_mock.assert_any_call("Idle Line 1", line=1)
116+
print_mock.assert_any_call("Idle Line 2", line=2)
117+
118+
print_mock.reset_mock()
63119

64-
main_menu.substate = 2
120+
main_menu.level1 = 1
121+
main_menu.level2 = -1
65122
main_menu.loop()
66123
print_mock.assert_has_calls(
67-
[
68-
mock.call("1: Update settings", line=1),
69-
mock.call("2: Test mode", line=2),
70-
mock.call("3: Exit", line=3),
71-
mock.call("4: Page 1", line=4),
72-
]
124+
[mock.call("View settings", line=1), mock.call("<4 ^2 8v 6>", line=2)]
73125
)
74126

127+
print_mock.reset_mock()
75128

76-
@mock.patch.object(LiquidCrystal, "print")
77-
@mock.patch.object(MainMenu, "_set_next_state")
78-
def test_main_menu(set_next_state_mock, print_mock):
79-
"""
80-
The function to test the entire use case of the MainMenu class
81-
"""
82-
main_menu = MainMenu(Titrator())
83-
129+
main_menu.level1 = 1
130+
main_menu.level2 = 2
84131
main_menu.loop()
85132
print_mock.assert_has_calls(
86-
[
87-
mock.call("1: Run titration", line=1),
88-
mock.call("2: Calibrate sensors", line=2),
89-
mock.call("3: Prime pump", line=3),
90-
mock.call("4: Page 2", line=4),
91-
]
133+
[mock.call(main_menu.view_menus[2], line=1), mock.call("<4 ^2 8v 6>", line=2)]
92134
)
93135

94-
main_menu.handle_key("1")
95-
set_next_state_mock.assert_called_with(ANY, True)
96-
assert set_next_state_mock.call_args.args[0].name() == "SetupTitration"
97-
98-
main_menu.handle_key("2")
99-
set_next_state_mock.assert_called_with(ANY, True)
100-
assert set_next_state_mock.call_args.args[0].name() == "SetupCalibration"
101-
102-
main_menu.handle_key("3")
103-
set_next_state_mock.assert_called_with(ANY, True)
104-
assert set_next_state_mock.call_args.args[0].name() == "PrimePump"
105-
106-
main_menu.handle_key("4")
107-
assert main_menu.substate == 2
136+
print_mock.reset_mock()
108137

138+
main_menu.level1 = 2
139+
main_menu.level2 = -1
109140
main_menu.loop()
110141
print_mock.assert_has_calls(
111-
[
112-
mock.call("1: Update settings", line=1),
113-
mock.call("2: Test mode", line=2),
114-
mock.call("3: Exit", line=3),
115-
mock.call("4: Page 1", line=4),
116-
]
142+
[mock.call("Change settings", line=1), mock.call("<4 ^2 8v 6>", line=2)]
117143
)
118144

119-
main_menu.handle_key("1")
120-
set_next_state_mock.assert_called_with(ANY, True)
121-
assert set_next_state_mock.call_args.args[0].name() == "UpdateSettings"
122-
123-
main_menu.handle_key("2")
124-
set_next_state_mock.assert_called_with(ANY, True)
125-
assert set_next_state_mock.call_args.args[0].name() == "DemoModeMenu"
145+
print_mock.reset_mock()
126146

127-
main_menu.handle_key("4")
128-
assert main_menu.substate == 1
147+
main_menu.level1 = 2
148+
main_menu.level2 = 3
149+
main_menu.loop()
150+
print_mock.assert_has_calls(
151+
[mock.call(main_menu.set_menus[3], line=1), mock.call("<4 ^2 8v 6>", line=2)]
152+
)

titration/ui_state/calibration/calibrate_temp.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
The file for the CalibrateTemp class
33
"""
4-
54
from titration.ui_state.ui_state import UIState
65
from titration.ui_state.user_value.reference_temperature import (
76
ReferenceTemperature,

titration/ui_state/calibration/setup_calibration.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
The file for the SetupCalibration class
33
"""
4-
54
from titration.devices.library import Keypad
65
from titration.ui_state.calibration.calibrate_ph import CalibratePh
76
from titration.ui_state.calibration.calibrate_temp import CalibrateTemp
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
The file to hold the Set Chill or Heat class
3+
"""
4+
from titration.devices.library import Keypad
5+
from titration.ui_state.ui_state import UIState
6+
7+
8+
class SetChillOrHeat(UIState):
9+
"""
10+
This is a class for the SetChillOrHeat state of the Tank Controller
11+
"""
12+
def __init__(self, titrator, previous_state=None):
13+
super().__init__(titrator)
14+
self.previous_state = previous_state
15+
# Add any initialization logic here
16+
17+
def loop(self):
18+
# Add main logic for this state
19+
pass
20+
21+
def handle_key(self, key):
22+
# Handle key input for this state
23+
if key == Keypad.KEY_4: # Left key
24+
self._set_next_state(self.previous_state, True)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
The file to hold the Set Google Sheet Interval class
3+
"""
4+
from titration.devices.library import Keypad
5+
from titration.ui_state.ui_state import UIState
6+
7+
8+
class SetGoogleSheetInterval(UIState):
9+
"""
10+
This is a class for the SetGoogleSheetInterval state of the Tank Controller
11+
"""
12+
def __init__(self, titrator, previous_state=None):
13+
super().__init__(titrator)
14+
self.previous_state = previous_state
15+
# Add any initialization logic here
16+
17+
def loop(self):
18+
# Add main logic for this state
19+
pass
20+
21+
def handle_key(self, key):
22+
# Handle key input for this state
23+
if key == Keypad.KEY_4: # Left key
24+
self._set_next_state(self.previous_state, True)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
The file to hold the Set KD class
3+
"""
4+
from titration.devices.library import Keypad
5+
from titration.ui_state.ui_state import UIState
6+
7+
8+
class SetKD(UIState):
9+
"""
10+
This is a class for the SetKD state of the Tank Controller
11+
"""
12+
def __init__(self, titrator, previous_state=None):
13+
super().__init__(titrator)
14+
self.previous_state = previous_state
15+
# Add any initialization logic here
16+
17+
def loop(self):
18+
# Add main logic for this state
19+
pass
20+
21+
def handle_key(self, key):
22+
# Handle key input for this state
23+
if key == Keypad.KEY_4: # Left key
24+
self._set_next_state(self.previous_state, True)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
The file to hold the Set KI class
3+
"""
4+
from titration.devices.library import Keypad
5+
from titration.ui_state.ui_state import UIState
6+
7+
8+
class SetKI(UIState):
9+
"""
10+
This is a class for the SetKI state of the Tank Controller
11+
"""
12+
def __init__(self, titrator, previous_state=None):
13+
super().__init__(titrator)
14+
self.previous_state = previous_state
15+
# Add any initialization logic here
16+
17+
def loop(self):
18+
# Add main logic for this state
19+
pass
20+
21+
def handle_key(self, key):
22+
# Handle key input for this state
23+
if key == Keypad.KEY_4: # Left key
24+
self._set_next_state(self.previous_state, True)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
The file to hold the Set KP class
3+
"""
4+
from titration.devices.library import Keypad
5+
from titration.ui_state.ui_state import UIState
6+
7+
8+
class SetKP(UIState):
9+
"""
10+
This is a class for the SetKP state of the Tank Controller
11+
"""
12+
def __init__(self, titrator, previous_state=None):
13+
super().__init__(titrator)
14+
self.previous_state = previous_state
15+
# Add any initialization logic here
16+
17+
def loop(self):
18+
# Add main logic for this state
19+
pass
20+
21+
def handle_key(self, key):
22+
# Handle key input for this state
23+
if key == Keypad.KEY_4: # Left key
24+
self._set_next_state(self.previous_state, True)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
The file to hold the PHCalibration class
3+
"""
4+
from titration.devices.library import Keypad
5+
from titration.ui_state.ui_state import UIState
6+
7+
8+
class PHCalibration(UIState):
9+
"""
10+
This is a class for the PHCalibration state of the Tank Controller
11+
"""
12+
def __init__(self, titrator, previous_state=None):
13+
super().__init__(titrator)
14+
self.previous_state = previous_state
15+
# Add any initialization logic here
16+
17+
def loop(self):
18+
# Add main logic for this state
19+
pass
20+
21+
def handle_key(self, key):
22+
# Handle key input for this state
23+
if key == Keypad.KEY_4: # Left key
24+
self._set_next_state(self.previous_state, True)

0 commit comments

Comments
 (0)