test_python_log_utils.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from __future__ import print_function
4 
5 import cStringIO as StringIO
6 import sys
7 import unittest
8 
9 from jsk_topic_tools.log_utils import LoggingThrottle
10 import rospy
11 
12 
13 PKG = 'jsk_topic_tools'
14 NAME = 'test_python_log_utils'
15 
16 
17 class TestPythonLogUtils(unittest.TestCase):
18 
19  def setUp(self):
20  rospy.init_node(NAME)
22 
23  def _check(self, no_logging=False):
24  sys.stdout = f = StringIO.StringIO()
25  self.logging_throttle(id='a', logging_func=print, period=3, msg='spam')
26  sys.stdout = sys.__stdout__
27  if no_logging:
28  self.assertFalse(f.getvalue(), 'spam\n')
29  else:
30  self.assertEqual(f.getvalue(), 'spam\n')
31 
33  self._check()
34  self._check(no_logging=True)
35  rospy.sleep(rospy.Duration(3))
36  self._check()
37 
38 
39 if __name__ == '__main__':
40  import rostest
41  rostest.rosrun(PKG, NAME, TestPythonLogUtils)


jsk_topic_tools
Author(s): Kei Okada , Yusuke Furuta
autogenerated on Tue Feb 6 2018 03:45:19