def test_log_wo_params(self, mocked_rospy, logm, rosm): name = 'foo' message = 'test message' log_message = '[{name}:{caller}] {message}'.format( name=name, caller=self.__class__.__name__ + '.' + sys._getframe().f_code.co_name, message=message, ) logger = getLogger(name) assert logger.name == name getattr(logger, logm)(message) getattr(mocked_rospy, rosm).assert_called_once_with(log_message)
def test_log_w_params(self, mocked_rospy, logm, rosm): name = 'foo' message = 'test message' arg0 = 'arg0' arg1 = 'arg1' kwargs0 = 'kwargs0' kwargs1 = 'kwargs1' log_message = '[{name}:{caller}] {message}, {arg1}, {kwargs0}, {arg0}, {kwargs1}'.format( name=name, caller=self.__class__.__name__ + '.' + sys._getframe().f_code.co_name, message=message, arg0=arg0, arg1=arg1, kwargs0=kwargs0, kwargs1=kwargs1, ) logger = getLogger(name) assert logger.name == name getattr(logger, logm)(message + ', {1}, {kwargs0}, {0}, {kwargs1}', arg0, arg1, kwargs1=kwargs1, kwargs0=kwargs0) getattr(mocked_rospy, rosm).assert_called_once_with(log_message)
# -*- coding: utf-8 -*- import datetime from threading import Lock import pytz import rospy from std_msgs.msg import String from sensor_msgs.msg import BatteryState from fiware_ros_msgs.msg import r_pos from fiware_ros_bridge.base import MQTTBase from fiware_ros_bridge.logging import getLogger logger = getLogger(__name__) POS_PAYLOAD_FMT = '{timestamp}|x|{x}|y|{y}|z|{z}|theta|{theta}|r_mode|{r_mode}' BATTERY_STATE_PAYLOAD_FMT = '{timestamp}|voltage|{voltage}|current|{current}|charge|{charge}|capacity|{capacity}|' \ 'design_capacity|{design_capacity}|percentage|{percentage}' class AttrsBridge(MQTTBase): def __init__(self): self.__params = rospy.get_param('~') super(AttrsBridge, self).__init__(self.__params) self.__r_mode = 'standby' rospy.Subscriber(self.__params['topics']['ros']['pos'], r_pos, self._on_receive_pos, queue_size=10)