00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 PKG = 'test_roslaunch'
00037 NAME = 'test_roslaunch_node_args'
00038
00039 import roslib; roslib.load_manifest(PKG)
00040
00041 import os
00042 import sys
00043 import unittest
00044
00045
00046 class TestNodeArgs(unittest.TestCase):
00047
00048 def test_create_local_process_env(self):
00049
00050
00051
00052
00053 from roslaunch.core import Node, Machine
00054 from roslaunch.node_args import create_local_process_env
00055 ros_root = '/ros/root1'
00056 rpp = '/rpp1'
00057 master_uri = 'http://masteruri:1234'
00058
00059 n = Node('nodepkg','nodetype')
00060 m = Machine('name1', ros_root, rpp, '1.2.3.4')
00061 d = create_local_process_env(n, m, master_uri)
00062 self.assertEquals(d['ROS_MASTER_URI'], master_uri)
00063 self.assertEquals(d['ROS_ROOT'], ros_root)
00064 self.assertEquals(d['PYTHONPATH'], os.path.join(ros_root, 'core', 'roslib', 'src'))
00065 self.assertEquals(d['ROS_PACKAGE_PATH'], rpp)
00066 for k in ['ROS_IP', 'ROS_NAMESPACE']:
00067 if k in d:
00068 self.fail('%s should not be set: %s'%(k,d[k]))
00069
00070
00071 env = os.environ.copy()
00072 env['PATH'] = '/some/path'
00073 env['FOO'] = 'foo'
00074 d = create_local_process_env(n, m, master_uri, env=env)
00075 self.assertEquals(d['FOO'], 'foo')
00076
00077
00078 os.environ['FOO'] = 'bar'
00079 d = create_local_process_env(n, m, master_uri)
00080 self.assertEquals(d['FOO'], 'bar')
00081
00082
00083 env = os.environ.copy()
00084 env['ROS_ROOT'] = '/not/ros/root/'
00085 env['PYTHONPATH'] = '/some/path'
00086 d = create_local_process_env(n, m, master_uri, env=env)
00087 self.assertEquals(d['ROS_ROOT'], ros_root)
00088 self.assertEquals(d['PYTHONPATH'], os.path.join(ros_root, 'core', 'roslib', 'src'))
00089
00090
00091 self.assertEquals(env['ROS_ROOT'], '/not/ros/root/')
00092 self.assertEquals(env['PYTHONPATH'], '/some/path')
00093
00094
00095 m = Machine('name1', '', '', '1.2.3.4')
00096 d = create_local_process_env(n, m, master_uri)
00097 val = os.environ['ROS_ROOT']
00098 self.assertEquals(d['ROS_ROOT'], val)
00099 self.assertEquals(d['PYTHONPATH'], os.path.join(val, 'core', 'roslib', 'src'))
00100 self.failIf('ROS_PACKAGE_PATH' in d, 'ROS_PACKAGE_PATH should not be set: %s'%d)
00101
00102
00103 m = Machine('name1', ros_root, rpp, '1.2.3.4', ros_ip="4.5.6.7")
00104 n = Node('nodepkg','nodetype', namespace="/ns1")
00105 d = create_local_process_env(n, m, master_uri)
00106 self.assertEquals(d['ROS_NAMESPACE'], "/ns1")
00107
00108 n = Node('nodepkg','nodetype', namespace="/ns2/")
00109 d = create_local_process_env(n, m, master_uri)
00110 self.assertEquals(d['ROS_NAMESPACE'], "/ns2")
00111
00112
00113 m = Machine('name1', ros_root, rpp, '1.2.3.4', ros_ip="4.5.6.7")
00114 d = create_local_process_env(n, m, master_uri)
00115 self.assertEquals(d['ROS_IP'], "4.5.6.7")
00116
00117
00118 n = Node('nodepkg','nodetype', env_args=[('NENV1', 'val1'), ('NENV2', 'val2'), ('ROS_ROOT', '/new/root')])
00119 d = create_local_process_env(n, m, master_uri)
00120 self.assertEquals(d['ROS_ROOT'], "/new/root")
00121 self.assertEquals(d['NENV1'], "val1")
00122 self.assertEquals(d['NENV2'], "val2")
00123
00124
00125 m = Machine('name1', ros_root, rpp, '1.2.3.4', ros_ip="4.5.6.7", env_args=[('MENV1', 'val1'), ('MENV2', 'val2'), ('ROS_ROOT', '/new/root2')])
00126 n = Node('nodepkg','nodetype')
00127 d = create_local_process_env(n, m, master_uri)
00128 self.assertEquals(d['ROS_ROOT'], "/new/root2")
00129 self.assertEquals(d['MENV1'], "val1")
00130 self.assertEquals(d['MENV2'], "val2")
00131
00132
00133 m = Machine('name1', ros_root, rpp, '1.2.3.4', ros_ip="4.5.6.7", env_args=[('MENV1', 'val1'), ('MENV2', 'val2')])
00134 n = Node('nodepkg','nodetype', env_args=[('MENV1', 'nodeval1')])
00135 d = create_local_process_env(n, m, master_uri)
00136 self.assertEquals(d['MENV1'], "nodeval1")
00137 self.assertEquals(d['MENV2'], "val2")
00138
00139 if __name__ == '__main__':
00140 import rostest
00141 rostest.unitrun('test_roslaunch', NAME, TestNodeArgs, coverage_packages=['roslaunch.node_args'])
00142