Total Complexity | 5 |
Total Lines | 47 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import os |
||
2 | |||
3 | |||
4 | def get_test_files(): |
||
5 | """ |
||
6 | Create a list of test files in the test directory |
||
7 | excluding .pyc and __pycache__ |
||
8 | |||
9 | :return: list |
||
10 | """ |
||
11 | test_files = os.listdir('./test') |
||
12 | return [ |
||
13 | create_test_file_name(test_file) |
||
14 | for test_file in test_files |
||
15 | if is_valid_test_file(test_files) |
||
16 | ] |
||
17 | |||
18 | |||
19 | def is_valid_test_file(test_file): |
||
20 | """ |
||
21 | Checks if file is a .pyc or from __pycache__ |
||
22 | :param test_file: str |
||
23 | :return: str |
||
24 | """ |
||
25 | return '.pyc' not in test_file and '__pycache__' not in test_file |
||
26 | |||
27 | |||
28 | def create_test_file_name(test_file): |
||
29 | """ |
||
30 | Append `test.` over file names to run all tests via `unittest` |
||
31 | :param test_file: str |
||
32 | :return: str |
||
33 | """ |
||
34 | 'test.{}'.format(test_file.replace('.py', '')) |
||
35 | |||
36 | |||
37 | def test_command(source): |
||
38 | """ |
||
39 | Creates a command to be run via subprocess |
||
40 | :param source: str|None |
||
41 | :return: list |
||
42 | """ |
||
43 | test_files = get_test_files() |
||
44 | source_present_command = ['coverage', 'run', '--source', source, '-m', 'unittest'] + test_files |
||
45 | source_missing_command = ['coverage', 'run', '-m', 'unittest'] + test_files |
||
46 | return source_missing_command if source is None else source_present_command |
||
47 |