diff options
author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2022-08-01 16:53:02 +0200 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2022-08-01 16:53:02 +0200 |
commit | 0466c3406b2dc1e41fc32bfd77f1b8af22a5c69f (patch) | |
tree | 9e5d6d73095adec7d01ce13d924fa9d7c004e949 /hazwaz | |
parent | 7df64ba14453685ddd6940fd4e1d3f69c8db507f (diff) |
Add facilities to run self-tests from a command.
Diffstat (limited to 'hazwaz')
-rw-r--r-- | hazwaz/command.py | 3 | ||||
-rw-r--r-- | hazwaz/unittest.py | 25 |
2 files changed, 27 insertions, 1 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() |