Skip to content

Commit b1c9ca5

Browse files
committed
#15 add cli formatter tests
1 parent 2e4967d commit b1c9ca5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

coloredlogs/cli.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
# Modules included in our package.
5050
from coloredlogs.converter import capture, convert
5151
from coloredlogs.demo import demonstrate_colored_logging
52+
from coloredlogs.demo import demonstrate_colored_logging_with_different_formatters
5253

5354
# Initialize a logger for this module.
5455
logger = logging.getLogger(__name__)
@@ -60,7 +61,7 @@ def main():
6061
try:
6162
# Parse the command line arguments.
6263
options, arguments = getopt.getopt(sys.argv[1:], 'cdh', [
63-
'convert', 'to-html', 'demo', 'help',
64+
'convert', 'to-html', 'demo', 'demo-with-formatter', 'help',
6465
])
6566
# Map command line options to actions.
6667
for option, value in options:
@@ -69,6 +70,8 @@ def main():
6970
arguments = []
7071
elif option in ('-d', '--demo'):
7172
actions.append(demonstrate_colored_logging)
73+
elif option in ('-f', '--demo-with-formatter'):
74+
actions.append(demonstrate_colored_logging_with_different_formatters)
7275
elif option in ('-h', '--help'):
7376
usage(__doc__)
7477
return

coloredlogs/tests.py

+9
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,15 @@ def test_cli_demo(self):
380380
for name in 'debug', 'info', 'warning', 'error', 'critical':
381381
assert name.upper() in output
382382

383+
def test_cli_demo_with_formatters(self):
384+
"""Test the command line colored logging demonstration."""
385+
with CaptureOutput() as capturer:
386+
main('coloredlogs', '--demo-with-formatter')
387+
output = capturer.get_text()
388+
# Make sure the output contains all of the expected logging level names.
389+
for name in 'debug', 'info', 'error', 'critical':
390+
assert name.upper() in output
391+
383392
def test_cli_conversion(self):
384393
"""Test the command line HTML conversion."""
385394
output = main('coloredlogs', '--convert', 'coloredlogs', '--demo', capture=True)

0 commit comments

Comments
 (0)