Skip to content

Commit

Permalink
DRIVERS: Add thruster communication unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jpanikulam committed Sep 12, 2015
1 parent b1180d7 commit 8991fb2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
8 changes: 7 additions & 1 deletion drivers/sub8_videoray_m5_thruster/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ catkin_python_setup()
catkin_package()
include_directories(
${catkin_INCLUDE_DIRS}
)
)

# Add folders to be run by python nosetests
if(CATKIN_ENABLE_TESTING)
catkin_add_nosetests(test)
endif()

43 changes: 43 additions & 0 deletions drivers/sub8_videoray_m5_thruster/test/test_thruster_comm.py
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()

0 comments on commit 8991fb2

Please sign in to comment.