$search
00001 #!/usr/bin/env python 00002 ################################################################# 00003 ##\file 00004 # 00005 # \note 00006 # Copyright (c) 2011-2012 \n 00007 # Fraunhofer Institute for Manufacturing Engineering 00008 # and Automation (IPA) \n\n 00009 # 00010 ################################################################# 00011 # 00012 # \note 00013 # Project name: care-o-bot 00014 # \note 00015 # ROS stack name: cob_calibration 00016 # \note 00017 # ROS package name: cob_robot_calibration 00018 # 00019 # \author 00020 # Author: Sebastian Haug, email:sebhaug@gmail.com 00021 # \author 00022 # Supervised by: Florian Weisshardt, email:florian.weisshardt@ipa.fhg.de 00023 # 00024 # \date Date of creation: January 2012 00025 # 00026 ################################################################# 00027 # 00028 # Redistribution and use in source and binary forms, with or without 00029 # modification, are permitted provided that the following conditions are met: 00030 # 00031 # - Redistributions of source code must retain the above copyright 00032 # notice, this list of conditions and the following disclaimer. \n 00033 # - Redistributions in binary form must reproduce the above copyright 00034 # notice, this list of conditions and the following disclaimer in the 00035 # documentation and/or other materials provided with the distribution. \n 00036 # - Neither the name of the Fraunhofer Institute for Manufacturing 00037 # Engineering and Automation (IPA) nor the names of its 00038 # contributors may be used to endorse or promote products derived from 00039 # this software without specific prior written permission. \n 00040 # 00041 # This program is free software: you can redistribute it and/or modify 00042 # it under the terms of the GNU Lesser General Public License LGPL as 00043 # published by the Free Software Foundation, either version 3 of the 00044 # License, or (at your option) any later version. 00045 # 00046 # This program is distributed in the hope that it will be useful, 00047 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00048 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00049 # GNU Lesser General Public License LGPL for more details. 00050 # 00051 # You should have received a copy of the GNU Lesser General Public 00052 # License LGPL along with this program. 00053 # If not, see <http://www.gnu.org/licenses/>. 00054 # 00055 ################################################################# 00056 PKG = 'cob_robot_calibration' 00057 import roslib; roslib.load_manifest(PKG) 00058 import unittest 00059 00060 from cob_robot_calibration import calibration_urdf_updater 00061 00062 FILE_IN = "test/data/test_calibration.urdf.xacro" 00063 FILE_OUT1 = "/tmp/test_calibration.urdf.xacro_out1" 00064 FILE_OUT2 = "/tmp/test_calibration.urdf.xacro_out2" 00065 FILE_OUT_RES1 = "test/data/test_calibration.urdf.xacro_corr-result1" 00066 FILE_OUT_RES2 = "test/data/test_calibration.urdf.xacro_corr-result2" 00067 00068 class TestCalibrationUrdfUpdater(unittest.TestCase): 00069 def test_update_one_param(self): 00070 # define params to update 00071 attributes2update = {'a': 1.0} 00072 00073 # do update 00074 updater = calibration_urdf_updater.CalibrationUrdfUpdater(FILE_IN, FILE_OUT1) 00075 updater.update(attributes2update) 00076 00077 # compare with correct results 00078 self.assertTrue(self._cmp_files(FILE_OUT1, FILE_OUT_RES1)) 00079 00080 def test_update_one_param_string(self): 00081 # define params to update 00082 attributes2update = {'a': "1.0"} 00083 00084 # do update 00085 updater = calibration_urdf_updater.CalibrationUrdfUpdater(FILE_IN, FILE_OUT1) 00086 updater.update(attributes2update) 00087 00088 # compare with correct results 00089 self.assertTrue(self._cmp_files(FILE_OUT1, FILE_OUT_RES1)) 00090 00091 def test_update_all_params(self): 00092 # define params to update 00093 attributes2update = {'a': 1.0} 00094 attributes2update = {'b': 2.0} 00095 attributes2update = {'c': 3.0} 00096 00097 # do update 00098 updater = calibration_urdf_updater.CalibrationUrdfUpdater(FILE_IN, FILE_OUT2) 00099 updater.update(attributes2update) 00100 00101 # compare with correct results 00102 self.assertTrue(self._cmp_files(FILE_OUT2, FILE_OUT_RES2)) 00103 00104 def test_update_all_params_string(self): 00105 # define params to update 00106 attributes2update = {'a': "1.0"} 00107 attributes2update = {'b': "2.0"} 00108 attributes2update = {'c': "3.0"} 00109 00110 # do update 00111 updater = calibration_urdf_updater.CalibrationUrdfUpdater(FILE_IN, FILE_OUT2) 00112 updater.update(attributes2update) 00113 00114 # compare with correct results 00115 self.assertTrue(self._cmp_files(FILE_OUT2, FILE_OUT_RES2)) 00116 00117 def _cmp_files(self, f1, f2): 00118 return open(f1).read() == open(f2).read() 00119 00120 if __name__ == '__main__': 00121 import rosunit 00122 rosunit.unitrun(PKG, 'TestCalibrationUrdfUpdater', TestCalibrationUrdfUpdater)