38 from __future__
import print_function
40 PKG =
'rospy_tutorials' 41 NAME =
'add_two_ints_test' 53 rospy.wait_for_service(
'add_two_ints')
54 s = rospy.ServiceProxy(
'add_two_ints', AddTwoInts)
55 tests = [(1, 2), (0, 0), (-1, -2), (12312, 980123), (sys.maxsize, -sys.maxsize), (sys.maxsize, -1), (sys.maxsize, 0)]
57 print(
"Requesting %s+%s" % (x, y))
60 resp2 = s.call(AddTwoIntsRequest(x, y))
61 self.assertEquals(resp.sum,resp2.sum)
62 print(
"%s+%s = %s" % (x, y, resp.sum))
63 self.assertEquals(resp.sum,(x + y),
"integration failure, returned sum was %s vs. %s"%(resp.sum, (x+y)))
66 rospy.wait_for_service(
'add_two_ints')
68 s = rospy.ServiceProxy(
'add_two_ints', BadTwoInts)
70 self.fail(
"service call should have failed with exception but instead returned 1+2=%s"%resp.sum)
71 except rospy.ServiceException
as e:
72 print(
"success -- ros exception was thrown: %s" % e)
73 s = rospy.ServiceProxy(
'add_two_ints', AddTwoInts)
74 resp = s.call(AddTwoIntsRequest(1, 2))
75 self.assertEquals(3,resp.sum)
79 rospy.wait_for_service(
'add_two_ints')
80 s = rospy.ServiceProxy(
'add_two_ints', BadTwoInts)
81 tests = [(1, 2), (0, 0), (-1, -2), (12312, 980123), (sys.maxsize, -sys.maxsize), (sys.maxsize, -1), (sys.maxsize, 0)]
83 print(
"Requesting %s+%s" % (x, y))
88 self.fail(
"call 1 with bad type failed: the server appears to be incorrectly deserialing the packet as it returned: %s"%resp.sum)
90 self.fail(
"call 1 with bad type failed to throw exception: %s"%resp.sum)
91 except rospy.ServiceException
as e:
92 print(
"success -- ros exception was thrown: %s" % e)
94 resp = s.call(BadTwoIntsRequest(x, y))
96 self.fail(
"call 2 with bad type failed: the server appears to be incorrectly deserialing the packet as it returned: %s"%resp.sum)
98 self.fail(
"call 2 with bad type failed to throw exception: %s"%resp.sum)
99 except rospy.ServiceException
as e:
100 print(
"success -- ros exception was thrown: %s" % e)
102 if __name__ ==
'__main__':
103 rostest.rosrun(PKG, NAME, TestAddTwoInts, sys.argv)
def test_add_two_ints(self)
def test_add_two_ints_bad_type(self)
def test_add_two_ints_bad_then_good(self)