-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Unit Test for Motor Cruise Control Toggle Functionality (#23)
* Write test for battery relay status * Added unit test for motor cruise control * Apply setUp and tearDown * added check for OFF state when array relay not held and cruise control toggled off * Make tests functional --------- Co-authored-by: Juho Kim <[email protected]> Co-authored-by: alexlewis9 <[email protected]>
- Loading branch information
1 parent
dc446db
commit 8ace232
Showing
2 changed files
with
118 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
from dataclasses import replace | ||
from threading import Thread | ||
from time import sleep | ||
from typing import ClassVar | ||
from unittest import TestCase, main | ||
|
||
from door.threading2 import AcquirableDoor | ||
|
||
from revolution.driver import Driver | ||
from revolution.environment import Environment, Header, Message | ||
from revolution.tests import configurations | ||
|
||
|
||
class DriverTestCase(TestCase): | ||
TIMEOUT: ClassVar[float] = 0.1 | ||
|
||
def setUp(self) -> None: | ||
self.environment: Environment = Environment( | ||
AcquirableDoor(replace(configurations.CONTEXTS)), | ||
replace(configurations.PERIPHERIES), | ||
replace(configurations.SETTINGS), | ||
) | ||
self.driver_thread: Thread = Thread( | ||
target=Driver.main, | ||
args=(self.environment,), | ||
) | ||
|
||
self.driver_thread.start() | ||
sleep(self.TIMEOUT) | ||
|
||
def tearDown(self) -> None: | ||
self.environment.send_all(Message(Header.STOP)) | ||
self.driver_thread.join() | ||
|
||
def test_array_relay_status(self) -> None: | ||
with self.environment.contexts() as contexts: | ||
self.assertFalse(contexts.power_array_relay_status_input) | ||
|
||
( | ||
configurations # type: ignore[method-assign] | ||
.STEERING_WHEEL_MCP23S17 | ||
.read_register | ||
) = lambda *_: [0] | ||
|
||
sleep(self.TIMEOUT) | ||
|
||
with self.environment.contexts() as contexts: | ||
self.assertTrue(contexts.power_array_relay_status_input) | ||
|
||
( | ||
configurations # type: ignore[method-assign] | ||
.STEERING_WHEEL_MCP23S17 | ||
.read_register | ||
) = lambda *_: [0xFF] | ||
|
||
sleep(self.TIMEOUT) | ||
|
||
with self.environment.contexts() as contexts: | ||
self.assertFalse(contexts.power_array_relay_status_input) | ||
|
||
def test_motor_cruise_control_status(self) -> None: | ||
with self.environment.contexts() as contexts: | ||
self.assertFalse(contexts.motor_cruise_control_status_input) | ||
|
||
( | ||
configurations # type: ignore[method-assign] | ||
.STEERING_WHEEL_MCP23S17 | ||
.read_register | ||
) = lambda *_: [0] | ||
|
||
sleep(self.TIMEOUT) | ||
|
||
with self.environment.contexts() as contexts: | ||
self.assertTrue(contexts.motor_cruise_control_status_input) | ||
|
||
( | ||
configurations # type: ignore[method-assign] | ||
.STEERING_WHEEL_MCP23S17 | ||
.read_register | ||
) = lambda *_: [0xFF] | ||
|
||
sleep(self.TIMEOUT) | ||
|
||
with self.environment.contexts() as contexts: | ||
self.assertTrue(contexts.motor_cruise_control_status_input) | ||
|
||
( | ||
configurations # type: ignore[method-assign] | ||
.STEERING_WHEEL_MCP23S17 | ||
.read_register | ||
) = lambda *_: [0] | ||
|
||
sleep(self.TIMEOUT) | ||
|
||
with self.environment.contexts() as contexts: | ||
self.assertFalse(contexts.motor_cruise_control_status_input) | ||
|
||
( | ||
configurations # type: ignore[method-assign] | ||
.STEERING_WHEEL_MCP23S17 | ||
.read_register | ||
) = lambda *_: [0xFF] | ||
|
||
sleep(self.TIMEOUT) | ||
|
||
with self.environment.contexts() as contexts: | ||
self.assertFalse(contexts.motor_cruise_control_status_input) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() # pragma: no cover |