diff options
-rw-r--r-- | hazwaz/command.py | 3 | ||||
-rw-r--r-- | hazwaz/unittest.py | 25 | ||||
-rw-r--r-- | tests/test_command.py | 3 |
3 files changed, 28 insertions, 3 deletions
diff --git a/hazwaz/command.py b/hazwaz/command.py index 185070f..1faf0fa 100644 --- a/hazwaz/command.py +++ b/hazwaz/command.py @@ -1,5 +1,6 @@ import argparse import logging +import typing logger = logging.getLogger(__name__) @@ -128,7 +129,7 @@ class Command: the :py:attr:`MainCommand.subcommands`. """ - name = None + name: typing.Optional[str] = None """ The name used to call this subcommand from the command line. diff --git a/hazwaz/unittest.py b/hazwaz/unittest.py index 96689d5..0092899 100644 --- a/hazwaz/unittest.py +++ b/hazwaz/unittest.py @@ -4,6 +4,8 @@ import sys import typing import unittest +from .command import Command + class HazwazTestCase(unittest.TestCase): def run_with_argv( @@ -30,3 +32,26 @@ class HazwazTestCase(unittest.TestCase): cmd.run() sys.argv = old_argv return stream + + +class TestCommand(Command): + """ + Run unittests. + """ + name = "test" + + def __init__(self, test_cases: typing.Iterable[unittest.TestCase]): + self.test_cases = test_cases + super().__init__() + + def main(self): + suite = unittest.TestSuite() + for test_case in self.test_cases: + suite.addTests( + unittest.TestLoader().loadTestsFromTestCase(test_case) + ) + unittest.TextTestRunner(verbosity=1).run(suite) + + +def main(): + unittest.main() diff --git a/tests/test_command.py b/tests/test_command.py index 96b36de..1d1402c 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -1,5 +1,4 @@ import logging -import unittest import hazwaz import hazwaz.unittest @@ -190,4 +189,4 @@ class testCommand(hazwaz.unittest.HazwazTestCase): if __name__ == '__main__': - unittest.main() + hazwaz.unittest.main() |