Repository navigation
Add the TopDist lamp and strobe HIL cases - #349
Conversation
A dashboard left-turn command must flash PA1, and a BPS fault must flash PC2.
| def setUp(self): | ||
| import config | ||
| from gpioPins import reset_nucleo | ||
| config.read_in_nucleo_pinmaps("TopDist") | ||
| reset_nucleo() | ||
|
|
||
| def _bus(self): | ||
| from CANBus import CANBus, clear_receive_queue | ||
| bus = CANBus() | ||
| self.addCleanup(bus.close) | ||
| clear_receive_queue() | ||
| return bus | ||
|
|
||
| def test_dashboard_left_turn_flashes_pa1(self): | ||
| from CANMessage import CanMessage |
There was a problem hiding this comment.
Imports are repeated inside setUp, _bus, and each test. MotorBoard/tests/test.py:7-10 imports gpioPins, CANMessage, etc. once at the top of the file. Do the same here, so a new member sees the module's dependencies in one place. If they must be lazy (for example, config has to run before gpioPins loads), add a one-line why comment.
| def _edges(read, timeout: float) -> int: | ||
| previous = read() | ||
| count = 0 | ||
| start = time.time() | ||
| while time.time() - start < timeout: | ||
| current = read() | ||
| if current != previous: | ||
| count += 1 | ||
| previous = current | ||
| if count >= 2: | ||
| return count | ||
| time.sleep(0.05) | ||
| return count | ||
|
|
There was a problem hiding this comment.
_edges is hard to read cold. Name the 2 (for example MIN_EDGES = 2) and say why two edges means "flashing". Name the 5 s timeout (hardcoded in both tests) and the 0.05 poll interval. timeout should be timeout_s, since the repo names units. Add a short why comment on the lamp period, since it is the reason 5 s is enough. MotorBoard/tests/test.py comments its sleeps, for example "Allow time for PowerBoard to read voltage...".
| bus.sendMessage(CanMessage( | ||
| "DashboardCommands", 0x12C, {"left_turn_signal": 1}, time.time())) | ||
| lamp = DigitalInput("LEFT_TURN_EN") | ||
| self.assertGreaterEqual(_edges(lamp.read, 5), 2, "PA1 left turn did not flash") | ||
|
|
||
| def test_bps_fault_flashes_pc2(self): | ||
| from CANMessage import CanMessage | ||
| from gpioPins import DigitalInput |
There was a problem hiding this comment.
Two issues.
config.read_in_nucleo_pinmaps,reset_nucleo,CANBus,clear_receive_queueandPinValidateare not defined anywhere else in this repo.MotorBoard/tests/test.pyusesCANPi.writeOutandAnalogOutput("6"). Please confirm these names exist on the HIL server side. If they do not, every test fails with ImportError. The PR also says "Not run on the rack".DigitalInputis created aftersendMessage. The firstread()in_edgeshappens after the send, so any early edge is missed. Create the input before sending.
The same applies to the BPS test below.
Summary
The server discovers this file because TopDist is in
hil_config.json.Evidence
After: The module is the two lamp cases plus the unknown-pin case. Not run on the rack.
Merge Danger
Door: two-way
Revert deletes the suite.
Blast radius: tests
Only
TopDist/tests/test.py. The compile job does not execute it.Made with Cursor