test_rosout_error.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 import rostest
5 import sys
6 import unittest
7 from rosgraph_msgs.msg import Log
8 
9 class TestRosoutOutput(unittest.TestCase):
10 
11  def setUp(self):
12  rospy.init_node('test_rosout_output', anonymous=True)
13  self.received_error_msg = None
14  rospy.Subscriber('/rosout', Log, self.callback)
15 
16  def callback(self, msg):
17  print("received rosout message with level = {}".format(msg.level))
18  if msg.level == Log.ERROR or msg.level == Log.FATAL:
19  self.received_error_msg = msg.msg
20 
21  def test_rosout_output(self):
22  rospy.wait_for_message('/rosout', Log, timeout=5) # Wait for a message
23  wait_time = float(rospy.get_param('~wait_time', 10.))
24  start_time = rospy.Time.now()
25  while not rospy.is_shutdown() and (rospy.Time.now() - start_time).to_sec() < wait_time:
26  rospy.sleep(1.0)
27  self.assertIsNone(self.received_error_msg, "Error message received!") # if not equal, then error
28 
29 if __name__ == '__main__':
30  rostest.run('smach_viewer', 'test_rosout_output', TestRosoutOutput, sys.argv)
test_rosout_error.TestRosoutOutput
Definition: test_rosout_error.py:9
test_rosout_error.TestRosoutOutput.test_rosout_output
def test_rosout_output(self)
Definition: test_rosout_error.py:21
test_rosout_error.TestRosoutOutput.callback
def callback(self, msg)
Definition: test_rosout_error.py:16
test_rosout_error.TestRosoutOutput.setUp
def setUp(self)
Definition: test_rosout_error.py:11
test_rosout_error.TestRosoutOutput.received_error_msg
received_error_msg
Definition: test_rosout_error.py:13


smach_viewer
Author(s): Jonathan Bohren
autogenerated on Thu Feb 20 2025 03:09:09