Go to the documentation of this file.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 import os
00035 import sys
00036 import struct
00037 import unittest
00038 import time
00039 import random
00040
00041 import rosunit
00042
00043 import rospy
00044
00045
00046 class TestRospyClient(unittest.TestCase):
00047
00048 def test_init_node(self):
00049 failed = True
00050 try:
00051
00052 rospy.init_node('ns/node')
00053 except ValueError:
00054 failed = False
00055 self.failIf(failed, "init_node allowed '/' in name")
00056
00057 def test_spin(self):
00058 failed = True
00059 try:
00060 rospy.spin()
00061 except rospy.ROSInitException:
00062 failed = False
00063 self.failIf(failed, "spin() should failed if not initialized")
00064
00065 def test_myargv(self):
00066 orig_argv = sys.argv
00067 try:
00068 from rospy.client import myargv
00069 args = myargv()
00070 self.assertEquals(args, sys.argv)
00071 self.assertEquals(['foo', 'bar', 'baz'], myargv(['foo','bar', 'baz']))
00072 self.assertEquals(['-foo', 'bar', '-baz'], myargv(['-foo','bar', '-baz']))
00073
00074 self.assertEquals(['foo'], myargv(['foo','bar:=baz']))
00075 self.assertEquals(['foo'], myargv(['foo','-bar:=baz']))
00076 finally:
00077 sys.argv = orig_argv
00078
00079 def test_load_command_line_node_params(self):
00080
00081 from rospy.client import load_command_line_node_params
00082
00083 assert {} == load_command_line_node_params([])
00084 assert {} == load_command_line_node_params(['a', 'b', 'c'])
00085 assert {} == load_command_line_node_params(['a:=b'])
00086 assert {'a': 'b'} == load_command_line_node_params(['_a:=b'])
00087 assert {'a': 'b', 'foo': 'bar'} == load_command_line_node_params(['_a:=b', 'blah', '_foo:=bar', 'baz'])
00088
00089 assert {'a': 1} == load_command_line_node_params(['_a:=1'])
00090 try:
00091 load_command_line_node_params(['_a:=b:=c'])
00092 except rospy.exceptions.ROSInitException:
00093 pass
00094
00095 if __name__ == '__main__':
00096 rosunit.unitrun('test_rospy', sys.argv[0], TestRospyClient, coverage_packages=['rospy.client'])