diff options
Diffstat (limited to 'tests/test_command.py')
-rw-r--r-- | tests/test_command.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/test_command.py b/tests/test_command.py index 2f9850d..cc64b8f 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -1,5 +1,6 @@ import contextlib import io +import logging import sys import unittest @@ -25,6 +26,17 @@ class MySubCommand(hazwaz.Command): print("Hello World") +class LoggingSubCommand(hazwaz.Command): + """ + A subcommand that logs on various levels. + """ + + def main(self): + logging.debug("This is a DEBUG message") + logging.info("This is an INFO message") + logging.warning("This is a WARNING message") + + class MyCommand(hazwaz.MainCommand): """ A command that does things. @@ -33,6 +45,7 @@ class MyCommand(hazwaz.MainCommand): """ commands = ( MySubCommand(), + LoggingSubCommand(), ) def add_arguments(self, parser): @@ -158,6 +171,35 @@ class testCommand(unittest.TestCase): stream = self._run_with_argv(cmd, ["mycommand"]) self.assertEqual(stream["stdout"].getvalue(), cmd_help) + def test_logging_regular(self): + cmd = MyCommand() + with self.assertLogs() as cm: + self._run_with_argv(cmd, [ + "mycommand", + "loggingsubcommand", + ]) + self.assertEqual(len(cm.output), 1) + + def test_logging_verbose(self): + cmd = MyCommand() + with self.assertLogs() as cm: + self._run_with_argv(cmd, [ + "mycommand", + "--verbose", + "loggingsubcommand", + ]) + self.assertEqual(len(cm.output), 2) + + def test_logging_debug(self): + cmd = MyCommand() + with self.assertLogs() as cm: + self._run_with_argv(cmd, [ + "mycommand", + "--debug", + "loggingsubcommand", + ]) + self.assertEqual(len(cm.output), 3) + if __name__ == '__main__': unittest.main() |