diff options
author | Frederick Muriuki Muriithi | 2022-02-12 07:33:42 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2022-02-12 07:33:42 +0300 |
commit | 00cd52204646f283cfaf413e67755cd9f0acfff0 (patch) | |
tree | 9d9459b70f23b4042ea609a0ca35638af8afad84 /setup_commands | |
parent | d0c7631276223aae6954f7643abac262aa080e50 (diff) | |
download | genenetwork3-00cd52204646f283cfaf413e67755cd9f0acfff0.tar.gz |
Provide custom class to run tests
Diffstat (limited to 'setup_commands')
-rw-r--r-- | setup_commands/__init__.py | 3 | ||||
-rw-r--r-- | setup_commands/run_tests.py | 41 |
2 files changed, 44 insertions, 0 deletions
diff --git a/setup_commands/__init__.py b/setup_commands/__init__.py new file mode 100644 index 0000000..967bb11 --- /dev/null +++ b/setup_commands/__init__.py @@ -0,0 +1,3 @@ +"""Module for custom setup commands.""" + +from .run_tests import RunTests diff --git a/setup_commands/run_tests.py b/setup_commands/run_tests.py new file mode 100644 index 0000000..9a2c9ad --- /dev/null +++ b/setup_commands/run_tests.py @@ -0,0 +1,41 @@ +import os +import sys +from distutils.core import Command + +class RunTests(Command): + """ + A custom command to run tests. + """ + description = "Run the tests" + commands = { + "all": "pytest", + "unit": "pytest tests/unit", + "integration": "pytest tests/integration", + "performance": "pytest tests/performance", + } + user_options = [ + ("type=", None, + f"""Specify the type of tests to run. + Valid types are {tuple(commands.keys())}. + Default is `all`.""")] + + def __init__(self, dist): + """Initialise the command.""" + super().__init__(dist) + + def initialize_options(self): + """Initialise the default values of all the options.""" + self.type = "all" + + def finalize_options(self): + """Set final value of all the options once they are processed.""" + if self.type not in RunTests.commands.keys(): + raise Exception(f""" + Invalid test type (self.type) requested! + Valid types are + {tuple(RunTests.commands.keys())}""") + + def run(self): + """Run the chosen tests""" + print(f"Running {self.type} tests") + os.system(RunTests.commands[self.type]) |