test_urdf.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00004 #
00005 # Licensed under the Apache License, Version 2.0 (the "License");
00006 # you may not use this file except in compliance with the License.
00007 # You may obtain a copy of the License at
00008 #
00009 #   http://www.apache.org/licenses/LICENSE-2.0
00010 #
00011 # Unless required by applicable law or agreed to in writing, software
00012 # distributed under the License is distributed on an "AS IS" BASIS,
00013 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014 # See the License for the specific language governing permissions and
00015 # limitations under the License.
00016 
00017 
00018 import sys
00019 import os
00020 import unittest
00021 import subprocess
00022 
00023 import rosunit
00024 
00025 ## A sample python unit test
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                 # check if file exists
00039                 if not os.path.exists(file_to_test):
00040                         self.fail('file "' + file_to_test + '" not found')
00041 
00042                 # check if xacro can be converted
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                 # check if urdf is correct
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)


cob_description
Author(s): Nadia Hammoudeh Garcia , Florian Weisshardt , Felix Messmer
autogenerated on Thu Jun 6 2019 18:23:45