Skip to content

Commit

Permalink
Fixed tests (although they are still very unstable)
Browse files Browse the repository at this point in the history
  • Loading branch information
gbiggs committed Aug 14, 2015
1 parent 17620d1 commit 13e6e47
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 45 deletions.
2 changes: 0 additions & 2 deletions rtshell/modmgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,13 @@ def _load_mod(self):
'''Loads the module object.'''
mod_list = self._name.split('.')
self._mod = self._recursive_load(mod_list[0], mod_list[1:], None)
print('Loaded module ' + str(self._mod))

def _recursive_load(self, head, rest, top_path):
'''Recurse through a dotted module path, loading each module.'''
f = None
try:
f, p, d = imp.find_module(head, top_path)
mod = imp.load_module(head, f, p, d)
print('Loaded parent module ' + str(mod))
finally:
if f:
f.close()
Expand Down
6 changes: 5 additions & 1 deletion rtshell/rtdis.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ def disconnect_ports(paths, options, tree=None):
conns = port_objs[0].get_connections_by_dests(port_objs[1:])

if not conns:
raise rts_exceptions.MultiConnectionNotFoundError
if options.id:
raise rts_exceptions.ConnectionIDNotFoundError(options.id,
cmd_paths[0])
else:
raise rts_exceptions.MultiConnectionNotFoundError
for c in conns:
c.disconnect()

Expand Down
4 changes: 2 additions & 2 deletions rtshell/rts_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,10 @@ def __init__(self, id, path):

def __str__(self):
if type(self._path) == tuple:
return 'No connection from {0} with ID {1}.'.format(
return 'No connection from {0} with ID {1}'.format(
rtctree.path.format_path(self._path), self._id)
elif type(self._path) == list:
return 'No connection from {0} with ID {1}.'.format(
return 'No connection from {0} with ID {1}'.format(
rtctree.path.format_path((self._path, None)), self._id)
else:
return 'No connection from {0} with ID {1}'.format(self._path,
Expand Down
76 changes: 36 additions & 40 deletions test/test_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def start_process(args):
def find_omninames():
# If on Windows, ...
# Else use ps
procs, stderr, ret_code = call_process(['ps', '-e'])
procs, stderr, ret_code = call_process(['ps', '-aux'])
for p in procs.split('\n'):
if 'omniNames' in p:
return p.split()[0]
Expand All @@ -86,6 +86,10 @@ def start_ns():
# Check if omniNames is running
pid = find_omninames()
if pid:
# Print a warning about possibly not being able to kill the name server
print("A name server is already running. If this is a system name "
"server, tests will not be able to stop and restart it. "
"This may pollute the results of subsequent tests.")
# Kill the name server to get a clean one for the test
call_process(['killall', 'omniNames'])
# Start omniNames and return the PID
Expand Down Expand Up @@ -124,15 +128,18 @@ def launch_manager(tries=40, res=0.01):
#subprocess.call(['killall', 'rtcd'])
p = start_process(['rtcd', '-d', '-f', './test/rtc.conf'])
while tries > 0:
stdout, stderr, ret = call_process(['./rtls',
'/localhost/local.host_cxt/manager.mgr'])
if stdout == '' and stderr == '':
stdout, stderr, ret = call_process(['./rtfind', '.', '-t', 'm'])
if stdout != '' and \
'/localhost/local.host_cxt/manager.mgr' in stdout and \
stderr == '':
return p
tries -= 1
time.sleep(res)
print 'Manager launch output:'
print 'stdout:', stdout
print 'stderr:', stderr
#print '-----\nManager launch failure output:'
#print 'stdout: ', stdout
#print 'stderr: ', stderr
#print 'retcode:', ret
#print '-----'
raise RTCLaunchFailedError


Expand Down Expand Up @@ -1676,9 +1683,8 @@ def test_disconnect_not_connected(self):
'/localhost/local.host_cxt/Output0.rtc:out',
'/localhost/local.host_cxt/Std0.rtc:in',])
self.assertEqual(stdout, '')
self.assertEqual(stderr, 'rtdis: No connection from '
'/localhost/local.host_cxt/Output0.rtc:out to '
'/localhost/local.host_cxt/Std0.rtc:in')
self.assertEqual(stderr, 'rtdis: No connection found involving the '
'specified ports.')
self.assertEqual(ret, 1)
stdout, stderr, ret = call_process(['./rtcat', '-l',
'/localhost/local.host_cxt/Output0.rtc:out'])
Expand All @@ -1698,22 +1704,15 @@ def test_disconnect_bad_id(self):
self.assert_('/localhost/local.host_cxt/Err0.rtc:in' in stdout)

def test_no_source_port(self):
test_sourceportnotfound(self, 'rtdis', obj1='Std0.rtc',
test_notaport(self, 'rtdis', obj1='Std0.rtc',
obj2='Output0.rtc:out')
test_sourceportnotfound(self, 'rtdis', obj1='Output0.rtc',
test_notaport(self, 'rtdis', obj1='Output0.rtc',
obj2='Std0.rtc:in')

def test_too_many_targets(self):
stdout, stderr, ret = call_process(['./rtdis', 'Std0.rtc:in',
'Output0.rtc:out', 'Err0.rtc:in'])
self.assertEqual(stdout, '')
self.assert_('Usage:' in stderr)
self.assertEqual(ret, 1)

def test_no_dest_port(self):
test_destportnotfound(self, 'rtdis', obj1='Std0.rtc:in',
test_notaport2(self, 'rtdis', obj1='Std0.rtc:in',
obj2='Output0.rtc')
test_destportnotfound(self, 'rtdis', obj1='Output0.rtc:out',
test_notaport2(self, 'rtdis', obj1='Output0.rtc:out',
obj2='Std0.rtc')

def test_bad_source_port(self):
Expand All @@ -1723,9 +1722,9 @@ def test_bad_source_port(self):
obj2='Std0.rtc:in')

def test_bad_source_rtc(self):
test_sourceportnotfound(self, 'rtdis', obj1='',
test_notaport(self, 'rtdis', obj1='',
obj2='Output0.rtc:out')
test_noobject(self, 'rtdis', obj1='Std0.rtc/:in',
test_notaport(self, 'rtdis', obj1='Std0.rtc/:in',
obj2='Output0.rtc:out')
test_noobject(self, 'rtdis', obj1='NotAComp0.rtc:in',
obj2='Output0.rtc:out')
Expand All @@ -1748,8 +1747,8 @@ def test_bad_dest_rtc(self):
obj2='NotAComp0.rtc:in')

def test_context(self):
test_noobject(self, 'rtdis', obj1=':port', obj2='Output0.rtc:out')
test_noobject2(self, 'rtdis', obj1='Std0.rtc:in', obj2=':port')
test_notaport(self, 'rtdis', obj1=':port', obj2='Output0.rtc:out')
test_notaport2(self, 'rtdis', obj1='Std0.rtc:in', obj2=':port')

def test_manager(self):
test_notacomp(self, 'rtdis', obj1='manager.mgr:port',
Expand Down Expand Up @@ -1782,7 +1781,6 @@ def tearDown(self):
stop_ns(self._ns)

def _check_stdout(self, stdout, title):
self.assert_(title in stdout)
self.assert_('Documentation component' in stdout)
self.assert_('Geoffrey Biggs' in stdout)
self.assert_('test' in stdout)
Expand All @@ -1804,33 +1802,33 @@ def test_doc(self):
'/localhost/local.host_cxt/Doc0.rtc'])
self.assertEqual(stderr, ''),
self.assertEqual(ret, 0)
self._check_stdout(stdout, 'Doc0.rtc')
self._check_stdout(stdout, 'Doc')

def test_doc_rst(self):
stdout, stderr, ret = call_process(['./rtdoc',
'/localhost/local.host_cxt/Doc0.rtc', '-f', 'rst'])
self.assertEqual(stderr, ''),
self.assertEqual(ret, 0)
self._check_stdout(stdout, 'Doc0.rtc')
self._check_stdout(stdout, 'Doc')

def test_doc_html(self):
stdout, stderr, ret = call_process(['./rtdoc',
'/localhost/local.host_cxt/Doc0.rtc', '-f', 'html'])
self.assertEqual(stderr, ''),
self.assertEqual(ret, 0)
self._check_stdout(stdout, 'Doc0.rtc')
self._check_stdout(stdout, 'Doc')

def test_doc_latex(self):
stdout, stderr, ret = call_process(['./rtdoc',
'/localhost/local.host_cxt/Doc0.rtc', '-f', 'latex'])
self.assertEqual(stderr, ''),
self.assertEqual(ret, 0)
self._check_stdout(stdout, 'Doc0.rtc')
self._check_stdout(stdout, 'Doc')

def test_no_doc(self):
stdout, stderr, ret = call_process(['./rtdoc',
'/localhost/local.host_cxt/Std0.rtc', '-f', 'rst'])
self.assert_(stdout.startswith('Std0.rtc\n'))
self.assert_(stdout.startswith('Std\n'))
self.assert_('Introduction' not in stdout)
self.assert_('Requirements' not in stdout)
self.assert_('Installation' not in stdout)
Expand All @@ -1841,7 +1839,7 @@ def test_no_doc(self):
def test_no_ports_config(self):
stdout, stderr, ret = call_process(['./rtdoc',
'/localhost/local.host_cxt/Doc20.rtc', '-f', 'rst'])
self.assert_(stdout.startswith('Doc20.rtc\n'))
self.assert_(stdout.startswith('Doc2\n'))
self.assert_('Ports' not in stdout)
self.assert_('Configuration parameters' not in stdout)
self.assertEqual(stderr, ''),
Expand Down Expand Up @@ -2365,8 +2363,6 @@ def _test_record(self):
time.sleep(1)
logger.terminate()
stdout, stderr = logger.communicate()
print(stdout)
print(stderr)
self.assertEqual(stdout, '')
self.assertEqual(stderr, '')
self.assertEqual(logger.returncode, -15)
Expand Down Expand Up @@ -2510,18 +2506,18 @@ def tearDown(self):
def _load_mgr(self):
stdout, stderr, ret = call_process(['./rtmgr',
'/localhost/local.host_cxt/manager.mgr', '-l',
os.path.join(COMP_LIB_PATH, 'Controller.so'), '-i',
'ControllerInit', '-c', 'Controller'])
os.path.join(COMP_LIB_PATH, 'Controller.so:ControllerInit'),
'-c', 'Controller'])
self.assertEqual(ret, 0)
stdout, stderr, ret = call_process(['./rtmgr',
'/localhost/local.host_cxt/manager.mgr', '-l',
os.path.join(COMP_LIB_PATH, 'Sensor.so'), '-i',
'SensorInit', '-c', 'Sensor'])
os.path.join(COMP_LIB_PATH, 'Sensor.so:SensorInit'),
'-c', 'Sensor'])
self.assertEqual(ret, 0)
stdout, stderr, ret = call_process(['./rtmgr',
'/localhost/local.host_cxt/manager.mgr', '-l',
os.path.join(COMP_LIB_PATH, 'Motor.so'), '-i',
'MotorInit', '-c', 'Motor'])
os.path.join(COMP_LIB_PATH, 'Motor.so:MotorInit'),
'-c', 'Motor'])
self.assertEqual(ret, 0)

def test_ls_nothing(self):
Expand Down

0 comments on commit 13e6e47

Please sign in to comment.