Пример #1
0
 def test_bind(self):
     logger = self.logger.bind(name='my.logger')
     logger.debug('foo')
     self.logger.debug('bar')
     self.check(
         Event(name='my.logger', level='debug', message='foo'),
         Event(level='debug', message='bar'),
     )
Пример #2
0
 def test_alter(self):
     self.logger.info('foo')
     self.logger.alter(name='my.logger')
     self.logger.info('bar')
     self.check(
         Event(level='info', message='foo'),
         Event(name='my.logger', level='info', message='bar'),
     )
Пример #3
0
 def test_nested_bind(self):
     log = self.logger.bind(keep=1, replace=2)
     log.info(event='first bind')
     log = log.bind(replace=3, new=4)
     log.info(event='second bind')
     self.check(
         Event(level='info', event='first bind', keep=1, replace=2),
         Event(level='info', event='second bind', keep=1, replace=3, new=4),
     )
Пример #4
0
 def test_stack_info(self):
     if PY2:
         return
     event = Event(message='foo', stack_info=True)
     self.target(event)
     self.capture.check(('root', 'INFO', 'foo', event))
     compare('Stack (most recent call last):',
             actual=self.capture.records[-1].stack_info.split('\n')[0])
Пример #5
0
 def test_stack_info(self):
     if PY2:
         return
     logger.info('foo', stack_info=True)
     self.capture.check(('root', 'INFO', 'foo',
                         Event(message='foo', stack_info=True,
                               level='info')))
     compare('Stack (most recent call last):',
             actual=self.capture.records[-1].stack_info.split('\n')[0])
Пример #6
0
 def test_exc_info(self):
     bad = Exception('bad')
     try:
         raise bad
     except:
         event = Event(level='error', message='foo', exc_info=True)
         self.target(event)
     self.capture.check(('root', 'ERROR', 'foo', event))
     compare(bad, actual=self.capture.records[-1].exc_info[1])
Пример #7
0
 def test_includes_magic_vars(self):
     # built-in wins!
     self.logger.debug('foo', 'bar', 'baz', message='bob', args='er?')
     with ShouldRaise(TypeError):
         self.logger.log(42,
                         'foo',
                         'bar',
                         'baz',
                         message='bob',
                         args='er?',
                         level=50)
     self.check(Event(level='debug', message='foo', args=('bar', 'baz')), )
Пример #8
0
 def test_minimal(self):
     self.logger.debug(event='foo')
     self.logger.info(event='foo')
     self.logger.warning(event='foo')
     self.logger.warn(event='foo')
     self.logger.error(event='foo')
     self.logger.exception(event='foo')
     self.logger.critical(event='foo')
     self.logger.fatal(event='foo')
     self.logger.log(level=42, event='foo')
     self.check(
         Event(level='debug', event='foo'),
         Event(level='info', event='foo'),
         Event(level='warning', event='foo'),
         Event(level='warning', event='foo'),
         Event(level='error', event='foo'),
         Event(level='error', event='foo', exc_info=True),
         Event(level='critical', event='foo'),
         Event(level='critical', event='foo'),
         Event(level=42, event='foo'),
     )
Пример #9
0
 def test_simple(self):
     self.logger.debug('foo')
     self.logger.info('foo')
     self.logger.warning('foo')
     self.logger.warn('foo')
     self.logger.error('foo')
     self.logger.exception('foo')
     self.logger.critical('foo')
     self.logger.fatal('foo')
     self.check(
         Event(level='debug', message='foo'),
         Event(level='info', message='foo'),
         Event(level='warning', message='foo'),
         Event(level='warning', message='foo'),
         Event(level='error', message='foo'),
         Event(level='error', message='foo', exc_info=True),
         Event(level='critical', message='foo'),
         Event(level='critical', message='foo'),
     )
Пример #10
0
 def test_level(self):
     logger.warning(event='test')
     self.capture.check(
         ('root', 'WARNING', '', Event(event='test', level='warning')))
Пример #11
0
 def test_sub_args(self):
     logger.info('foo %s', 'bar')
     self.capture.check(('root', 'INFO', 'foo bar',
                         Event(message='foo %s',
                               args=('bar', ),
                               level='info')))
Пример #12
0
 def test_minimal(self):
     logger.info(event='test')
     self.capture.check(
         ('root', 'INFO', '', Event(event='test', level='info')))
Пример #13
0
 def test_named_logger(self):
     logger = get_logger('foo')
     logger.info(event='test')
     self.capture.check(
         ('foo', 'INFO', '', Event(event='test', logger='foo',
                                   level='info')))
Пример #14
0
 def test_str_kw_ordered(self):
     compare(str(Event(x=1, y=2)), expected="Event(x=1, y=2)")
Пример #15
0
 def test_stdlib(self):
     self.logger.debug('foo %s',
                       'bar',
                       exc_info=None,
                       extra=None,
                       stack_info=False)
     self.logger.info('foo %s',
                      'bar',
                      exc_info=None,
                      extra=None,
                      stack_info=False)
     self.logger.warning('foo %s',
                         'bar',
                         exc_info=None,
                         extra=None,
                         stack_info=False)
     self.logger.warn('foo %s',
                      'bar',
                      exc_info=None,
                      extra=None,
                      stack_info=False)
     self.logger.error('foo %s',
                       'bar',
                       exc_info=None,
                       extra=None,
                       stack_info=False)
     self.logger.exception('foo %s',
                           'bar',
                           exc_info=None,
                           extra=None,
                           stack_info=False)
     self.logger.critical('foo %s',
                          'bar',
                          exc_info=None,
                          extra=None,
                          stack_info=False)
     self.logger.fatal('foo %s',
                       'bar',
                       exc_info=None,
                       extra=None,
                       stack_info=False)
     self.logger.log(42,
                     'foo %s',
                     'bar',
                     exc_info=None,
                     extra=None,
                     stack_info=False)
     self.check(
         Event(level='debug',
               message='foo %s',
               args=('bar', ),
               exc_info=None,
               extra=None,
               stack_info=False),
         Event(level='info',
               message='foo %s',
               args=('bar', ),
               exc_info=None,
               extra=None,
               stack_info=False),
         Event(level='warning',
               message='foo %s',
               args=('bar', ),
               exc_info=None,
               extra=None,
               stack_info=False),
         Event(level='warning',
               message='foo %s',
               args=('bar', ),
               exc_info=None,
               extra=None,
               stack_info=False),
         Event(level='error',
               message='foo %s',
               args=('bar', ),
               exc_info=None,
               extra=None,
               stack_info=False),
         Event(level='error',
               message='foo %s',
               args=('bar', ),
               exc_info=True,
               extra=None,
               stack_info=False),
         Event(level='critical',
               message='foo %s',
               args=('bar', ),
               exc_info=None,
               extra=None,
               stack_info=False),
         Event(level='critical',
               message='foo %s',
               args=('bar', ),
               exc_info=None,
               extra=None,
               stack_info=False),
         Event(level=42,
               message='foo %s',
               args=('bar', ),
               exc_info=None,
               extra=None,
               stack_info=False),
     )
Пример #16
0
 def test_minimal(self):
     event = Event(event='test')
     self.target(event)
     self.capture.check(('root', 'INFO', '', event))
Пример #17
0
 def test_repr(self):
     compare(repr(Event([('x', '2'), ('y', 1)])),
             expected="Event(x='2', y=1)")
Пример #18
0
 def test_named_logger(self):
     event = Event(event='test', logger='foo')
     self.target(event)
     self.capture.check(('foo', 'INFO', '', event))
Пример #19
0
 def test_specifify_default_level(self):
     target = StandardLibraryTarget(default_level=WARNING)
     event = Event(event='test')
     target(event)
     self.capture.check(('root', 'WARNING', '', event))
Пример #20
0
 def test_repr_kw_ordered(self):
     compare(repr(Event(x='2', y=1)), expected="Event(x='2', y=1)")
Пример #21
0
 def test_numeric_level(self):
     event = Event(event='test', level=WARNING)
     self.target(event)
     self.capture.check(('root', 'WARNING', '', event))
Пример #22
0
 def test_string_level(self):
     event = Event(event='test', level='warning')
     self.target(event)
     self.capture.check(('root', 'WARNING', '', event))
Пример #23
0
 def test_sub_args(self):
     event = Event(message='foo %s', args=('bar', ))
     self.target(event)
     self.capture.check(('root', 'INFO', 'foo bar', event))
Пример #24
0
 def test_unknown_string_level(self):
     event = Event(event='test', level='yuhwut?')
     self.target(event)
     self.capture.check(('root', 'INFO', '', event))
Пример #25
0
 def test_default_logger(self):
     from shoehorn import logger
     logger.info('er hi')
     self.capture.check(
         ('root', 'INFO', 'er hi', Event(message='er hi', level='info')))
Пример #26
0
 def test_str(self):
     compare(str(Event([('x', 1), ('y', 2)])), expected="Event(x=1, y=2)")