39 import roslib; roslib.load_manifest(PKG)
41 SRV_NAME =
'my_node/self_test' 47 from optparse
import OptionParser
49 from diagnostic_msgs.srv
import SelfTest, SelfTestRequest, SelfTestResponse
53 super(TestSelfTest, self).
__init__(*args)
55 parser = OptionParser(usage=
"usage ./%prog [options]", prog=
"test_selftest.py")
56 parser.add_option(
'--no-id', action=
"store_true",
57 dest=
"no_id", default=
False,
58 help=
"No ID expected from self test")
59 parser.add_option(
'--expect-fail', action=
"store_true",
60 dest=
"expect_fail", default=
False,
61 help=
"Self test should fail")
62 parser.add_option(
'--exception', action=
"store_true",
63 dest=
"exception", default=
False,
64 help=
"Self test should throw exception and we should get error message")
66 parser.add_option(
'--gtest_output', action=
"store",
69 options, args = parser.parse_args()
77 proxy = rospy.ServiceProxy(SRV_NAME, SelfTest)
80 rospy.wait_for_service(SRV_NAME, 15)
82 self.assert_(
False,
"Service %s did not respond. Unable to test self_test" % SRV_NAME)
88 self.assert_(
False,
"Error calling self_test service. Exception: %s" % traceback.format_exc())
91 self.assert_(res.id ==
'',
"Result had node ID even though ID was not expected. ID: %s" % res.id)
93 self.assert_(res.id !=
'',
"Result had no node ID")
96 self.assert_(res.passed == 0,
"Self test passed, but it shouldn't have. Result: %d" % res.passed)
99 for tst
in res.status:
100 max_val = max(max_val, tst.level)
102 self.assert_(max_val > 0,
"Self test failed, but no sub tests reported a failure or warning")
104 self.assert_(res.passed,
"Self test failed, but we expected a pass")
106 for tst
in res.status:
107 self.assert_(tst.level == 0,
"Self test subtest failed, but we marked it as a pass")
112 for tst
in res.status:
113 if tst.message.find(
'exception') > -1:
116 self.assert_(found_ex,
"Self test threw and exception, but we didn't catch it and report it")
119 if __name__ ==
'__main__':
120 rostest.run(PKG, sys.argv[0], TestSelfTest, sys.argv)