예제 #1
0
 def test_init(self, mock_logging):
     l = Loggable()
     l.set_logger(foo="foo", bar="bat")
     mock_logging.getLogger.assert_called_once_with(
         "malcolm.core.loggable.Loggable.bat.foo")
     filter = l.log.addFilter.call_args[0][0]
     assert filter.fields == dict(foo="foo", bar="bat")
 def test_calls_logger_function(self, mock_logging):
     l = Loggable()
     l.set_logger_name("bar")
     for n in "debug info warning error exception".split():
         m = getattr(l, "log_%s" % n)
         m("hello", n)
         getattr(l._logger, n).assert_called_once_with("hello", n)
예제 #3
0
 def test_init(self, mock_logging):
     loggable = Loggable()
     loggable.set_logger(foo="foo", bar="bat")
     mock_logging.getLogger.assert_called_once_with(
         "malcolm.core.loggable.Loggable.bat.foo")
     assert mock_logging.LoggerAdapter.call_args[1] == {
         "extra": {
             "foo": "foo",
             "bar": "bat"
         }
     }
예제 #4
0
 def test_call_method_no_log_name(self):
     l = Loggable()
     with self.assertRaises(AttributeError):
         l.log.debug("Something")
예제 #5
0
 def test_call_method_no_log_name(self, mock_logging):
     l = Loggable()
     l.log.debug("Something")
     mock_logging.getLogger.assert_called_once_with(
         "malcolm.core.loggable.Loggable")
     l.log.debug.assert_called_once_with("Something")
예제 #6
0
 def test_init(self, mock_logging):
     Loggable("foo")
     mock_logging.getLogger.assert_called_once_with("foo")
 def test_call_method_no_log_name(self, mock_logging):
     l = Loggable()
     self.assertRaises(ValueError, l.log_info, "msg")
 def test_init(self, mock_logging):
     l = Loggable()
     l.set_logger_name("foo")
     mock_logging.getLogger.assert_called_once_with("foo")