-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsyslogger-test.py
50 lines (39 loc) · 1.76 KB
/
syslogger-test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import unittest
from io import StringIO
import logging
from syslogger import Syslogger, SyslogFilter, SYSLOG_LEVELS
class SysloggerTestCase(unittest.TestCase):
def setUp(self):
self.stream = StringIO()
self.logger = Syslogger(name='test', stream=self.stream)
def tearDown(self):
self.stream.close()
def level_stoi(self, s):
""" Convert string level name to syslog number
"""
return SYSLOG_LEVELS.get(logging.getLevelName(s.upper()))
def test_message_prepender_debug(self):
self.logger.debug('hello')
logged = self.stream.getvalue()
self.assertEqual(logged, '<%s> hello\n' % SYSLOG_LEVELS.get(logging.DEBUG))
def test_message_prepender_info(self):
self.logger.info('hello')
logged = self.stream.getvalue()
self.assertEqual(logged, '<%s> hello\n' % SYSLOG_LEVELS.get(logging.INFO))
def test_message_prepender_warning(self):
self.logger.warning('hello')
logged = self.stream.getvalue()
self.assertEqual(logged, '<%s> hello\n' % SYSLOG_LEVELS.get(logging.WARNING))
def test_message_prepender_error(self):
self.logger.error('hello')
logged = self.stream.getvalue()
self.assertEqual(logged, '<%s> hello\n' % SYSLOG_LEVELS.get(logging.ERROR))
def test_message_prepender_critical(self):
self.logger.critical('hello')
logged = self.stream.getvalue()
self.assertEqual(logged, '<%s> hello\n' % SYSLOG_LEVELS.get(logging.CRITICAL))
def test_passes_level_kwarg_to_base_logger(self):
self.logger = Syslogger(name='test-custom', stream=self.stream, level=logging.CRITICAL)
self.logger.info('Hello world!')
logged = self.stream.getvalue().strip()
self.assertEqual(logged, '')