Skip to content

Commit

Permalink
#15 add cli formatter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dhoomakethu committed Jun 22, 2017
1 parent 2e4967d commit b1c9ca5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion coloredlogs/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
# Modules included in our package.
from coloredlogs.converter import capture, convert
from coloredlogs.demo import demonstrate_colored_logging
from coloredlogs.demo import demonstrate_colored_logging_with_different_formatters

# Initialize a logger for this module.
logger = logging.getLogger(__name__)
Expand All @@ -60,7 +61,7 @@ def main():
try:
# Parse the command line arguments.
options, arguments = getopt.getopt(sys.argv[1:], 'cdh', [
'convert', 'to-html', 'demo', 'help',
'convert', 'to-html', 'demo', 'demo-with-formatter', 'help',
])
# Map command line options to actions.
for option, value in options:
Expand All @@ -69,6 +70,8 @@ def main():
arguments = []
elif option in ('-d', '--demo'):
actions.append(demonstrate_colored_logging)
elif option in ('-f', '--demo-with-formatter'):
actions.append(demonstrate_colored_logging_with_different_formatters)
elif option in ('-h', '--help'):
usage(__doc__)
return
Expand Down
9 changes: 9 additions & 0 deletions coloredlogs/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,15 @@ def test_cli_demo(self):
for name in 'debug', 'info', 'warning', 'error', 'critical':
assert name.upper() in output

def test_cli_demo_with_formatters(self):
"""Test the command line colored logging demonstration."""
with CaptureOutput() as capturer:
main('coloredlogs', '--demo-with-formatter')
output = capturer.get_text()
# Make sure the output contains all of the expected logging level names.
for name in 'debug', 'info', 'error', 'critical':
assert name.upper() in output

def test_cli_conversion(self):
"""Test the command line HTML conversion."""
output = main('coloredlogs', '--convert', 'coloredlogs', '--demo', capture=True)
Expand Down

0 comments on commit b1c9ca5

Please sign in to comment.