-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpyunit
More file actions
executable file
·63 lines (52 loc) · 1.95 KB
/
pyunit
File metadata and controls
executable file
·63 lines (52 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/python
"""
PyUnit - unittest test runner based on annotation.
Usage: pyunit COMMAND --OPTION <argument>
pyunit config init [--path=<path>]
pyunit run [--suites=<suites>]
pyunit (-h | --help)
pyunit --version
Commands:
config - Configuration sub-system
suites - Tests Suites sub-system
run - Test runner from CLI
Options:
-h --help Show this screen.
--version Show version.
"""
import sys
from importlib import import_module
from docopt import docopt
from pytheons.pyunit.user_interface.command_line_interface.output.logger import logger
class PyUnit:
def __init__(self) -> None:
super().__init__()
argv = None
if len(sys.argv) <= 1:
argv = ['-h']
docopt(__doc__, argv=argv, version='PyUnit 1.0.0')
try:
if len(sys.argv) > 1:
command: str = sys.argv[1]
command_module_name = command.replace('-', '_')
words = list(map(
lambda word: word.capitalize(),
command.replace('_', '-').split('-')
))
command_class_name = '{prefix}{suffix}'.format(prefix=''.join(words), suffix='Command')
load_module = 'pytheons.pyunit.user_interface.command_line_interface.command.{module}'.format(
module=command_module_name
)
logger.debug('<Module: %s>', load_module)
logger.debug('<Class: %s>', command_class_name)
try:
module = import_module(load_module)
options = sys.argv[2:]
command_class = getattr(module, command_class_name)
command_class(*options)
except ModuleNotFoundError:
logger.error('Command "{name}" not found!'.format(name=command))
except KeyboardInterrupt:
logger.debug("Interrupted")
if __name__ == "__main__":
PyUnit()