forked from uf-mil-archive/software-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DRIVERS: Add thruster communication unit tests
- Loading branch information
1 parent
b1180d7
commit 8991fb2
Showing
2 changed files
with
50 additions
and
1 deletion.
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
43 changes: 43 additions & 0 deletions
43
drivers/sub8_videoray_m5_thruster/test/test_thruster_comm.py
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,43 @@ | ||
#!/usr/bin/env python | ||
import unittest | ||
import numpy as np | ||
from sub8_thruster_comm import thruster_comm_factory, FakeThrusterPort | ||
|
||
class TestThrusterComm(unittest.TestCase): | ||
def setUp(self): | ||
port = '/dev/fake_port' | ||
node_id = 17 | ||
thruster_name = 'BRL' | ||
|
||
self.port_info = { | ||
'port': port, | ||
'thrusters': { | ||
'BRV': { | ||
'node_id': 16, | ||
}, | ||
thruster_name: { | ||
'node_id': node_id, | ||
} | ||
} | ||
} | ||
|
||
def test_thruster_comm_factory_fake(self): | ||
'''Test that the thruster factory returns a proper simulated FakeThrusterPort''' | ||
# This should succeed | ||
thrust_comm = thruster_comm_factory(self.port_info, fake=True) | ||
|
||
def test_fake_thruster_status(self): | ||
'''Test that the fake thruster status published is what we expect''' | ||
thrust_comm = FakeThrusterPort(self.port_info) | ||
fake_status = thrust_comm.command_thruster('BRV', 0.2) | ||
self.assertEqual(fake_status['bus_voltage'], 48) | ||
|
||
def test_thruster_comm_factory_real_fail(self): | ||
'''Test that the comm factory fails to create a ThrusterPort on a port that does not exist''' | ||
# This should fail | ||
with self.assertRaises(IOError): | ||
thrust_comm = thruster_comm_factory(self.port_info, fake=False) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |