test_defaults.py
Go to the documentation of this file.
00001 import unittest
00002 from rosparam_handler.param.DefaultsParameters import DefaultsParameters
00003 import rospy
00004 
00005 
00006 class TestDefaults(unittest.TestCase):
00007     def test_defaults(self):
00008         """
00009         tests defaults on server
00010         :return:
00011         """
00012         params = DefaultsParameters()
00013         self.assertEqual(params.int_param_w_default, 1)
00014         self.assertAlmostEqual(params.double_param_w_default, 1.1)
00015         self.assertEqual(params.str_param_w_default, "Hello World")
00016         self.assertEqual(params.bool_param_w_default, True)
00017 
00018         self.assertEqual(params.vector_int_param_w_default, [1, 2, 3])
00019         self.assertEqual(params.vector_double_param_w_default, [1.1, 1.2, 1.3])
00020         self.assertEqual(params.vector_string_param_w_default, ["Hello", "World"])
00021 
00022         self.assertEqual(params.map_param_w_default, {"Hello": "World"})
00023         self.assertEqual(params.enum_param_w_default, 1)
00024 
00025     def test_defaults_on_server(self):
00026         params = DefaultsParameters()
00027         # now all parameters should be set on param server
00028         self.assertEqual(params.int_param_w_default, rospy.get_param("~int_param_w_default"))
00029         self.assertAlmostEqual(params.double_param_w_default, rospy.get_param("~double_param_w_default"))
00030         self.assertEqual(params.str_param_w_default, rospy.get_param("~str_param_w_default"))
00031         self.assertEqual(params.bool_param_w_default, rospy.get_param("~bool_param_w_default"))
00032 
00033         self.assertEqual(params.vector_int_param_w_default, rospy.get_param("~vector_int_param_w_default"))
00034         self.assertEqual(params.vector_double_param_w_default, rospy.get_param("~vector_double_param_w_default"))
00035         self.assertEqual(params.vector_string_param_w_default, rospy.get_param("~vector_string_param_w_default"))
00036 
00037         self.assertEqual(params.map_param_w_default, rospy.get_param("~map_param_w_default"))
00038         self.assertEqual(params.enum_param_w_default, rospy.get_param("~enum_param_w_default"))
00039 
00040     def test_set_parameters_on_server(self):
00041         params = DefaultsParameters()
00042 
00043         params.int_param_w_default = 2
00044         params.double_param_w_default = 2.2
00045         params.str_param_w_default = "World Hello"
00046         params.bool_param_w_default = False
00047         params.vector_int_param_w_default = [3, 2, 1];
00048         params.vector_double_param_w_default = [1.3, 1.2, 1.2];
00049         params.vector_bool_param_w_default = [True, False];
00050         params.vector_string_param_w_default = ["World", "Hello"];
00051         params.map_param_w_default = {"World": "Hello"};
00052         params.enum_param_w_default = 2;
00053 
00054         # Upload parameters
00055         params.to_param_server()
00056 
00057         # now all parameters should be set on param server
00058         self.assertEqual(params.int_param_w_default, rospy.get_param("~int_param_w_default"))
00059         self.assertAlmostEqual(params.double_param_w_default, rospy.get_param("~double_param_w_default"))
00060         self.assertEqual(params.str_param_w_default, rospy.get_param("~str_param_w_default"))
00061         self.assertEqual(params.bool_param_w_default, rospy.get_param("~bool_param_w_default"))
00062 
00063         self.assertEqual(params.vector_int_param_w_default, rospy.get_param("~vector_int_param_w_default"))
00064         self.assertEqual(params.vector_double_param_w_default, rospy.get_param("~vector_double_param_w_default"))
00065         self.assertEqual(params.vector_string_param_w_default, rospy.get_param("~vector_string_param_w_default"))
00066 
00067         self.assertEqual(params.map_param_w_default, rospy.get_param("~map_param_w_default"))
00068         self.assertEqual(params.enum_param_w_default, rospy.get_param("~enum_param_w_default"))


rosparam_handler
Author(s): Claudio Bandera
autogenerated on Sat Jun 8 2019 20:21:53