How to use get_param method in autotest

Best Python code snippet using autotest_python

params_basic.py

Source:params_basic.py Github

copy

Full Screen

...39import rostest40import rospkg41import rosgraph42master = rosgraph.Master('params_basic')43def get_param(*args):44 return master.getParam(*args)45 46## Test Roslaunch 'param' tags47class TestParamsBasic(unittest.TestCase):48 ## test primitive values49 def test_values(self):50 ## Test roslaunch string params51 self.assertEquals(get_param('stringempty'), '')52 print(get_param('stringbar'))53 self.assertEquals(get_param('stringbar'), 'bar')54 self.assertEquals(get_param('str10'), '10')55 self.assertEquals(get_param('string10'), '10') 56 self.assertEquals(get_param('stringentity'), '<stringentity/>') 57 ## Test roslaunch integer params58 self.assertEquals(get_param("integerneg1"), -1)59 self.assertEquals(get_param("integer0"), 0)60 self.assertEquals(get_param("integer1"), 1)61 self.assertEquals(get_param("integernoop1"), 1)62 self.assertEquals(get_param("integer12345"), 12345)63 ## Test roslaunch float params64 self.assertEquals(get_param("floatpi"),3.14159)65 self.assertEquals(get_param("floatnooppi"),3.14159)66 self.assertEquals(get_param("float3"),3.0)67 self.assertEquals(get_param("floatneg1"),-1.0)68 ## Test roslaunch boolean params69 for p in ['true', 'TRUE', 'True']:70 self.assertTrue(get_param(p), "[%s] is not false: %s"%(p, get_param(p)))71 for p in ['false', "FALSE", 'False']:72 self.assertFalse(get_param(p), "[%s] is not false: %s"%(p, get_param(p)))73 74 ## Test roslaunch ns attribute (namespace) on params75 def test_ns(self):76 self.assertEquals(get_param("/wg/childparam"),"wg")77 self.assertEquals(get_param("/wg2/childparam"),"wg2")78 self.assertEquals(get_param("/wg3/childparam"),"wg3")79 self.assertEquals(get_param("/wg/wg4/childparam"),"wg4")80 self.assertEquals(get_param("/wg/wg4/wg5/childparam"),"wg5") 81 ## Test roslaunch <group> tag with and without ns attribute82 self.assertEquals(get_param("/wga/wg/childparam"),"wg")83 self.assertEquals(get_param("/wga/wg2/childparam"),"wg2")84 self.assertEquals(get_param("/wga/wg3/childparam"),"wg3")85 self.assertEquals(get_param("/wga/wg/wg4/childparam"),"wg4")86 self.assertEquals(get_param("/wga/wg/wg4/wg5/childparam"),"wg5") 87 # test second-level group88 self.assertEquals(get_param("/wga/wgb/wg/childparam"),"bwg")89 self.assertEquals(get_param("/wga/wgb/wg2/childparam"),"bwg2")90 self.assertEquals(get_param("/wga/wgb/wg3/childparam"),"bwg3")91 self.assertEquals(get_param("/wga/wgb/wg/wg4/childparam"),"bwg4")92 self.assertEquals(get_param("/wga/wgb/wg/wg4/wg5/childparam"),"bwg5")93 # test unscoped group94 self.assertEquals(get_param("/wgc/childparam"),"wg")95 self.assertEquals(get_param("/wgc2/childparam"),"wg2")96 self.assertEquals(get_param("/wgc3/childparam"),"wg3")97 self.assertEquals(get_param("/wgc/wg4/childparam"),"wg4")98 self.assertEquals(get_param("/wgc/wg4/wg5/childparam"),"wg5") 99 100 ## test 'command' attribute101 def test_commandandfile(self):102 dir = rospkg.RosPack().get_path('roslaunch')103 with open(os.path.join(dir, 'resources', 'example.launch'), 'r') as f:104 text_data = f.read()105 with open(os.path.join(dir, 'resources', 'example.launch'), 'rb') as f:106 binary_data = f.read()107 self.assertEquals(get_param("commandoutput"), binary_data)108 self.assertEquals(get_param("textfile"), text_data)109 ## test 'binfile' attribute110 bindata = get_param("binaryfile")111 self.assertTrue(isinstance(bindata, Binary))112 self.assertEquals(bindata.data, binary_data)113 114if __name__ == '__main__':115 rostest.rosrun(PKG, sys.argv[0], TestParamsBasic, sys.argv)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful