Skip to content

Commit 79a031d

Browse files
committed
Add logging test
1 parent 00a09b0 commit 79a031d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

phylib/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@
3939

4040

4141
class _Formatter(logging.Formatter):
42+
color_codes = {'L': '94', 'D': '90', 'I': '0', 'W': '33', 'E': '31'}
43+
4244
def format(self, record):
4345
# Only keep the first character in the level name.
4446
record.levelname = record.levelname[0]
4547
filename = op.splitext(op.basename(record.pathname))[0]
4648
record.caller = '{:s}:{:d}'.format(filename, record.lineno).ljust(20)
4749
message = super(_Formatter, self).format(record)
48-
color_code = {'D': '90', 'I': '0', 'W': '33', 'E': '31'}.get(record.levelname, '7')
50+
color_code = self.color_codes.get(record.levelname, '90')
4951
message = '\33[%sm%s\33[0m' % (color_code, message)
5052
return message
5153

phylib/utils/tests/test_testing.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,30 @@
1313

1414
from ..testing import captured_output, captured_logging, _assert_equal
1515

16+
logger = logging.getLogger('phylib')
17+
1618

1719
#------------------------------------------------------------------------------
1820
# Tests
1921
#------------------------------------------------------------------------------
2022

23+
def test_logging_1():
24+
print()
25+
logger.setLevel(5)
26+
logger.log(5, "level 5")
27+
logger.log(10, "debug")
28+
logger.log(20, "info")
29+
logger.log(30, "warning")
30+
logger.log(40, "error")
31+
32+
2133
def test_captured_output():
2234
with captured_output() as (out, err):
2335
print('Hello world!')
2436
assert out.getvalue().strip() == 'Hello world!'
2537

2638

2739
def test_captured_logging():
28-
logger = logging.getLogger('phylib')
2940
handlers = logger.handlers
3041
with captured_logging() as buf:
3142
logger.debug('Hello world!')

0 commit comments

Comments
 (0)