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 import sys
00019 import os
00020 import unittest
00021 import subprocess
00022
00023 import rosunit
00024
00025
00026 class TestUrdf(unittest.TestCase):
00027
00028 def test_correct_format(self):
00029 print sys.argv
00030 print len(sys.argv)
00031
00032 if len(sys.argv) < 2:
00033 self.fail("no urdf file given, usage: " + os.path.basename(sys.argv[0]) + " file.urdf.xacro. \ninput parameters are: " + str(sys.argv))
00034
00035 file_to_test = sys.argv[1]
00036 print "testing " + file_to_test
00037
00038
00039 if not os.path.exists(file_to_test):
00040 self.fail('file "' + file_to_test + '" not found')
00041
00042
00043 p = subprocess.Popen("rosrun xacro xacro --inorder " + file_to_test + " > /tmp/test.urdf", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
00044 (out,err) = p.communicate()
00045 if p.returncode != 0 and p.returncode != None:
00046 self.fail("cannot convert xacro. file: " + file_to_test + "\nOutput: " + out + "\nError: " + err)
00047
00048
00049 p = subprocess.Popen("check_urdf /tmp/test.urdf", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
00050 if p.returncode != 0 and p.returncode != None:
00051 self.fail("urdf not correct. file: " + file_to_test + "\n" + p.stderr.read())
00052
00053 if __name__ == '__main__':
00054 rosunit.unitrun('cob_description', 'test_urdf', TestUrdf)