def test_info(self): log.log_message(log.INFO, 'message', logger=self.logger, show_stack=False) self.assertEqual(self.out.getvalue(), '{}: message\n'.format(self._level(log.INFO)))
def test_stacklevel(self): with mock.patch('logging.log') as mocklog: log.log_stack(log.INFO, 'message', stacklevel=1) tb = traceback.extract_stack()[1:-1] mocklog.assert_called_once_with(log.INFO, 'message', extra={ 'full_stack': tb, 'show_stack': True }) with mock.patch('logging.log') as mocklog: log.log_message(log.INFO, 'foo', 1, Path('path'), 'bar', stacklevel=1) tb = traceback.extract_stack()[1:-1] mocklog.assert_called_once_with(log.INFO, 'foo 1 ' + repr(Path('path')) + ' bar', extra={ 'full_stack': tb, 'show_stack': True })
def test_hide_stack(self): with mock.patch('logging.log') as mocklog: log.log_stack(log.INFO, 'message', show_stack=False) tb = traceback.extract_stack()[1:] tb[-1].lineno -= 1 mocklog.assert_called_once_with(log.INFO, 'message', extra={ 'full_stack': tb, 'show_stack': False }) with mock.patch('logging.log') as mocklog: log.log_message(log.INFO, 'foo', 1, Path('path'), 'bar', show_stack=False) tb = traceback.extract_stack()[1:] tb[-1].lineno -= 1 mocklog.assert_called_once_with(log.INFO, 'foo 1 ' + repr(Path('path')) + ' bar', extra={ 'full_stack': tb, 'show_stack': False })
def test_hide_stack(self): with mock.patch('logging.log') as mocklog: log.log_stack(log.INFO, 'message', show_stack=False) tb = traceback.extract_stack()[1:] tb[-1].lineno -= 1 mocklog.assert_called_once_with(log.INFO, 'message', extra={ 'full_stack': tb, 'show_stack': False }) with mock.patch('logging.log') as mocklog: # Make sure the log_message call is all on one line to avoid # differences in how stacks for multi-line statements are handled # on various Python versions. args = (log.INFO, 'foo', 1, Path('path'), 'bar') log.log_message(*args, show_stack=False) tb = traceback.extract_stack()[1:] tb[-1].lineno -= 1 mocklog.assert_called_once_with(log.INFO, 'foo 1 ' + repr(Path('path')) + ' bar', extra={ 'full_stack': tb, 'show_stack': False })