test_python_log_utils.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 from __future__ import print_function
00004 
00005 import cStringIO as StringIO
00006 import sys
00007 import unittest
00008 
00009 from jsk_topic_tools.log_utils import LoggingThrottle
00010 import rospy
00011 
00012 
00013 PKG = 'jsk_topic_tools'
00014 NAME = 'test_python_log_utils'
00015 
00016 
00017 class TestPythonLogUtils(unittest.TestCase):
00018 
00019     def setUp(self):
00020         rospy.init_node(NAME)
00021         self.logging_throttle = LoggingThrottle()
00022 
00023     def _check(self, no_logging=False):
00024         sys.stdout = f = StringIO.StringIO()
00025         self.logging_throttle(id='a', logging_func=print, period=3, msg='spam')
00026         sys.stdout = sys.__stdout__
00027         if no_logging:
00028             self.assertFalse(f.getvalue(), 'spam\n')
00029         else:
00030             self.assertEqual(f.getvalue(), 'spam\n')
00031 
00032     def test_LoggingThrottle(self):
00033         self._check()
00034         self._check(no_logging=True)
00035         rospy.sleep(rospy.Duration(3))
00036         self._check()
00037 
00038 
00039 if __name__ == '__main__':
00040     import rostest
00041     rostest.rosrun(PKG, NAME, TestPythonLogUtils)


jsk_topic_tools
Author(s): Kei Okada , Yusuke Furuta
autogenerated on Fri Sep 8 2017 03:38:56