diff options
| author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2022-08-02 09:52:40 +0200 | 
|---|---|---|
| committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2022-08-02 09:52:40 +0200 | 
| commit | 5c71e321b4d168444721cced85e7a86c9bacb5ad (patch) | |
| tree | 659f9e1796539279599c822f002ea17cdcda6f98 /tests | |
| parent | bd5340fa8195c41caeaaa539d49ebfdeeae3a8df (diff) | |
Add optional support for coloredlogs
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_command.py | 44 | 
1 files changed, 41 insertions, 3 deletions
| diff --git a/tests/test_command.py b/tests/test_command.py index 1d1402c..667fef6 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -155,8 +155,9 @@ class testCommand(hazwaz.unittest.HazwazTestCase):          stream = self.run_with_argv(cmd, ["mycommand"])          self.assertEqual(stream["stdout"].getvalue(), cmd_help) -    def test_logging_regular(self): +    def test_logging_regular_coloredlogs(self):          cmd = MyCommand() +        cmd.coloredlogs = True          with self.assertLogs():              stream = self.run_with_argv(cmd, [                  "mycommand", @@ -165,8 +166,9 @@ class testCommand(hazwaz.unittest.HazwazTestCase):          log_lines = stream["stderr"].getvalue().strip().split("\n")          self.assertEqual(len(log_lines), 1) -    def test_logging_verbose(self): +    def test_logging_verbose_coloredlogs(self):          cmd = MyCommand() +        cmd.coloredlogs = True          with self.assertLogs():              stream = self.run_with_argv(cmd, [                  "mycommand", @@ -176,8 +178,44 @@ class testCommand(hazwaz.unittest.HazwazTestCase):          log_lines = stream["stderr"].getvalue().strip().split("\n")          self.assertEqual(len(log_lines), 2) -    def test_logging_debug(self): +    def test_logging_debug_coloredlogs(self):          cmd = MyCommand() +        cmd.coloredlogs = True +        with self.assertLogs(): +            stream = self.run_with_argv(cmd, [ +                "mycommand", +                "--debug", +                "loggingsubcommand", +            ]) +        log_lines = stream["stderr"].getvalue().strip().split("\n") +        self.assertEqual(len(log_lines), 3) + +    def test_logging_regular_no_coloredlogs(self): +        cmd = MyCommand() +        cmd.coloredlogs = False +        with self.assertLogs(): +            stream = self.run_with_argv(cmd, [ +                "mycommand", +                "loggingsubcommand", +            ]) +        log_lines = stream["stderr"].getvalue().strip().split("\n") +        self.assertEqual(len(log_lines), 1) + +    def test_logging_verbose_no_coloredlogs(self): +        cmd = MyCommand() +        cmd.coloredlogs = False +        with self.assertLogs(): +            stream = self.run_with_argv(cmd, [ +                "mycommand", +                "--verbose", +                "loggingsubcommand", +            ]) +        log_lines = stream["stderr"].getvalue().strip().split("\n") +        self.assertEqual(len(log_lines), 2) + +    def test_logging_debug_no_coloredlogs(self): +        cmd = MyCommand() +        cmd.coloredlogs = False          with self.assertLogs():              stream = self.run_with_argv(cmd, [                  "mycommand", | 
