00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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'])