$search
00001 #!/usr/bin/env python 00002 # Software License Agreement (BSD License) 00003 # 00004 # Copyright (c) 2008, Willow Garage, Inc. 00005 # All rights reserved. 00006 # 00007 # Redistribution and use in source and binary forms, with or without 00008 # modification, are permitted provided that the following conditions 00009 # are met: 00010 # 00011 # * Redistributions of source code must retain the above copyright 00012 # notice, this list of conditions and the following disclaimer. 00013 # * Redistributions in binary form must reproduce the above 00014 # copyright notice, this list of conditions and the following 00015 # disclaimer in the documentation and/or other materials provided 00016 # with the distribution. 00017 # * Neither the name of Willow Garage, Inc. nor the names of its 00018 # contributors may be used to endorse or promote products derived 00019 # from this software without specific prior written permission. 00020 # 00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 # POSSIBILITY OF SUCH DAMAGE. 00033 00034 import roslib; roslib.load_manifest('pr2_calibration_propagation') 00035 00036 import sys 00037 import unittest 00038 00039 import pr2_calibration_propagation.update_joint as update_joint 00040 00041 class TestUpdateJoint(unittest.TestCase): 00042 def test_easy1(self): 00043 str_in = '''<joint name="joint1"><calibration rising="123"/></joint>''' 00044 cl = update_joint.update_joint(str_in, 'joint1', ref_shift=1) 00045 self.assertEqual(len(cl), 1) 00046 self.assertEqual(cl[0][0], (42, 45)) 00047 self.assertAlmostEqual(float(cl[0][1]), 124, 5) 00048 00049 class TestUpdateTransmission(unittest.TestCase): 00050 def test_easy1(self): 00051 str_in = '''<transmission name="trans1"><mechanicalReduction>2</mechanicalReduction></transmission>''' 00052 cl = update_joint.update_transmission(str_in, 'trans1', 3) 00053 self.assertEqual(len(cl), 1) 00054 self.assertEqual(cl[0][0], (49, 50)) 00055 self.assertAlmostEqual(float(cl[0][1]), 6, 5) 00056 00057 def test_easy2(self): 00058 str_in = '''<transmission name="trans2"></transmission><transmission name="trans1"><mechanicalReduction>2</mechanicalReduction></transmission>''' 00059 cl = update_joint.update_transmission(str_in, 'trans1', 3) 00060 self.assertEqual(len(cl), 1) 00061 self.assertEqual(cl[0][0], (92, 93)) 00062 self.assertAlmostEqual(float(cl[0][1]), 6, 5) 00063 00064 class TestAttr(unittest.TestCase): 00065 def test_easy1(self): 00066 str_in = '''a="123" b="456"''' 00067 span = update_joint.find_attr_span(str_in, 'a') 00068 self.assertEqual(span, (3,6)) 00069 00070 def test_easy2(self): 00071 str_in = '''a = "123" b="456"''' 00072 span = update_joint.find_attr_span(str_in, 'a') 00073 self.assertEqual(span, (5,8)) 00074 00075 def test_easy3(self): 00076 str_in = '''a="123" b ="456"''' 00077 span = update_joint.find_attr_span(str_in, 'b') 00078 self.assertEqual(span, (12,15)) 00079 00080 def test_easy4(self): 00081 str_in = '''a="123" b= "456"''' 00082 span = update_joint.find_attr_span(str_in, 'b') 00083 self.assertEqual(span, (12,15)) 00084 00085 def test_not_found(self): 00086 str_in = '''a="123" b="456"''' 00087 span = update_joint.find_attr_span(str_in, 'c') 00088 self.assertEqual(span, None) 00089 00090 class TestSplitElem(unittest.TestCase): 00091 def test_easy1(self): 00092 str_in = '''<tag1/><tag2/><target name="blah"></target>''' 00093 span = update_joint.find_split_elem_span(str_in, 'target', 'blah') 00094 self.assertEqual(span, (14,43)) 00095 00096 def test_duplicate_elem(self): 00097 str_in = '''<tag1/><tag2/><target name="blah2"></target><target name="blah"></target>''' 00098 span = update_joint.find_split_elem_span(str_in, 'target', 'blah') 00099 self.assertEqual(span, (44,73)) 00100 00101 class TestAtomicElem(unittest.TestCase): 00102 def test_easy1(self): 00103 str_in = '''<tag1/><target/><tag2></tag2>''' 00104 span = update_joint.find_atomic_elem_span(str_in, 'target') 00105 self.assertEqual(span, (7,16)) 00106 00107 def test_boundary(self): 00108 str_in = '''<target/>''' 00109 span = update_joint.find_atomic_elem_span(str_in, 'target') 00110 self.assertEqual(span, (0,9)) 00111 00112 def test_not_found(self): 00113 str_in = '''<target/>''' 00114 span = update_joint.find_atomic_elem_span(str_in, 'target2') 00115 self.assertEqual(span, None) 00116 00117 class TestSplitInternals(unittest.TestCase): 00118 def test_easy1(self): 00119 str_in = '''<tag1>123</tag1>''' 00120 span = update_joint.find_split_internals(str_in) 00121 self.assertEqual(span, (6,9)) 00122 00123 if __name__ == '__main__': 00124 import rostest 00125 rostest.unitrun('pr2_calibration_propagation', 'test_split_elem', TestSplitElem, coverage_packages=['pr2_calibration_propagation.update_joint']) 00126 rostest.unitrun('pr2_calibration_propagation', 'test_atomic_elem', TestAtomicElem, coverage_packages=['pr2_calibration_propagation.update_joint']) 00127 rostest.unitrun('pr2_calibration_propagation', 'test_attr', TestAttr, coverage_packages=['pr2_calibration_propagation.update_joint']) 00128 rostest.unitrun('pr2_calibration_propagation', 'test_update_joint', TestUpdateJoint, coverage_packages=['pr2_calibration_propagation.update_joint']) 00129 rostest.unitrun('pr2_calibration_propagation', 'test_split_internals', TestSplitInternals, coverage_packages=['pr2_calibration_propagation.update_joint']) 00130 rostest.unitrun('pr2_calibration_propagation', 'test_update_transmission', TestUpdateTransmission, coverage_packages=['pr2_calibration_propagation.update_joint'])