test_log_utils.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 
00004 from mock import patch
00005 from nose.tools import assert_equal
00006 import unittest
00007 
00008 from jsk_topic_tools.log_utils import _log_msg_with_called_location
00009 from jsk_topic_tools.log_utils import jsk_logdebug
00010 from jsk_topic_tools.log_utils import jsk_loginfo
00011 from jsk_topic_tools.log_utils import jsk_logwarn
00012 from jsk_topic_tools.log_utils import jsk_logerr
00013 from jsk_topic_tools.log_utils import jsk_logfatal
00014 from jsk_topic_tools.log_utils import warn_no_remap
00015 
00016 
00017 @patch('rospy.get_name')
00018 def test__log_msg_with_called_location(mock_get_name):
00019     mock_get_name.return_value = '/spam'
00020     msg = _log_msg_with_called_location('spam')
00021     assert_equal(msg, '[/spam] [patched] spam')
00022 
00023 
00024 class TestJSKLogXXX(unittest.TestCase):
00025 
00026     @patch('rospy.logdebug')
00027     @patch('rospy.get_name')
00028     def test_jsk_logdebug(self, mock_get_name, mock_log):
00029         mock_get_name.return_value = '/spam'
00030         jsk_logdebug('spam')
00031         mock_log.assert_called_with('[/spam] [TestJSKLogXXX::test_jsk_logdebug] spam')
00032 
00033     @patch('rospy.loginfo')
00034     @patch('rospy.get_name')
00035     def test_jsk_loginfo(self, mock_get_name, mock_log):
00036         mock_get_name.return_value = '/spam'
00037         jsk_loginfo('spam')
00038         mock_log.assert_called_with('[/spam] [TestJSKLogXXX::test_jsk_loginfo] spam')
00039 
00040     @patch('rospy.logwarn')
00041     @patch('rospy.get_name')
00042     def test_jsk_logwarn(self, mock_get_name, mock_log):
00043         mock_get_name.return_value = '/spam'
00044         jsk_logwarn('spam')
00045         mock_log.assert_called_with('[/spam] [TestJSKLogXXX::test_jsk_logwarn] spam')
00046 
00047     @patch('rospy.logerr')
00048     @patch('rospy.get_name')
00049     def test_jsk_logerr(self, mock_get_name, mock_log):
00050         mock_get_name.return_value = '/spam'
00051         jsk_logerr('spam')
00052         mock_log.assert_called_with('[/spam] [TestJSKLogXXX::test_jsk_logerr] spam')
00053 
00054     @patch('rospy.logfatal')
00055     @patch('rospy.get_name')
00056     def test_jsk_logfatal(self, mock_get_name, mock_log):
00057         mock_get_name.return_value = '/spam'
00058         jsk_logfatal('spam')
00059         mock_log.assert_called_with('[/spam] [TestJSKLogXXX::test_jsk_logfatal] spam')
00060 
00061 
00062 @patch('rospy.logwarn')
00063 @patch('rospy.names.get_resolved_mappings')
00064 @patch('rosgraph.names.resolve_name')
00065 @patch('rospy.get_name')
00066 def test_warn_no_remap(mock_get_name, mock_resolve_name,
00067                        mock_get_resolved_mappings, mock_log):
00068     mock_get_name.return_value = '/spam'
00069     mock_resolve_name.return_value = '/spam/input'
00070     mock_get_resolved_mappings.return_value = {}
00071     warn_no_remap('~input')
00072     mock_log.assert_called_with("[/spam] '~input' has not been remapped.")


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