test_urdf.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 
18 import sys
19 import os
20 import unittest
21 import subprocess
22 
23 import rosunit
24 
25 ## A sample python unit test
26 class TestUrdf(unittest.TestCase):
27 
29  print(sys.argv)
30  print(len(sys.argv))
31 
32  if len(sys.argv) < 2:
33  self.fail("no urdf file given, usage: " + os.path.basename(sys.argv[0]) + " file.urdf.xacro. \ninput parameters are: " + str(sys.argv))
34 
35  file_to_test = sys.argv[1]
36  print("testing " + file_to_test)
37 
38  # check if file exists
39  if not os.path.exists(file_to_test):
40  self.fail('file "' + file_to_test + '" not found')
41 
42  # check if xacro can be converted
43  xacro_args = '--inorder' if (os.environ['ROS_DISTRO'] < 'melodic') else ''
44  p = subprocess.Popen("xacro " + xacro_args + " " + file_to_test + " > /tmp/test.urdf", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
45  (out,err) = p.communicate()
46  if p.returncode != 0 and p.returncode != None:
47  self.fail("cannot convert xacro. file: " + file_to_test + "\nOutput: " + out + "\nError: " + err)
48 
49  # check if urdf is correct
50  p = subprocess.Popen("check_urdf /tmp/test.urdf", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
51  if p.returncode != 0 and p.returncode != None:
52  self.fail("urdf not correct. file: " + file_to_test + "\n" + p.stderr.read())
53 
54 if __name__ == '__main__':
55  rosunit.unitrun('cob_description', 'test_urdf', TestUrdf)
def test_correct_format(self)
Definition: test_urdf.py:28
A sample python unit test.
Definition: test_urdf.py:26


cob_description
Author(s): Nadia Hammoudeh Garcia , Florian Weisshardt , Felix Messmer
autogenerated on Sun Nov 22 2020 03:10:30