-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrun_tests.py
65 lines (58 loc) · 2.6 KB
/
run_tests.py
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
64
65
"""Helper script to run all unit tests"""
import os
import sys
import json
import argparse
import subprocess as sp
from colorama import Fore, Back, Style
import pytest
from functest.run_all import run_functests
def add_bool_arg(parser, name, default):
"""Add boolean option with mutually exclusive group"""
# cf. https://stackoverflow.com/a/31347222/3127098
dest = name.replace('-','_')
group = parser.add_mutually_exclusive_group(required=False)
group.add_argument('--' + name, dest=dest, action='store_true')
group.add_argument('--no-' + name, dest=dest, action='store_false')
parser.set_defaults(**{dest:default})
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Execute all unit tests')
parser.add_argument('--lmenv', type=str, help='Path to .lmenv file')
parser.add_argument('--output-dir', nargs='?', type=str, default='executed_functest', help='Output directory of executed notebooks')
add_bool_arg(parser, 'cpp-unit', True)
add_bool_arg(parser, 'python-unit', True)
add_bool_arg(parser, 'functest', False)
args = parser.parse_args()
# Read .lmeenv file
with open(args.lmenv) as f:
config = json.load(f)
# Set LD_LIBRARY_PATH for Linux environment
if sys.platform == 'linux':
env = os.environ.copy()
env['LD_LIBRARY_PATH'] = config['bin_path']
# Execute C++ tests
if args.cpp_unit:
print(Fore.GREEN + "------------------------" + Style.RESET_ALL)
print(Fore.GREEN + "Executing C++ unit tests" + Style.RESET_ALL)
print(Fore.GREEN + "------------------------" + Style.RESET_ALL, flush=True)
command = [os.path.join(config['bin_path'], 'lm_test')]
if sys.platform == 'linux':
sp.check_call(command, env=env)
else:
sp.check_call(command)
# Execute python tests
if args.python_unit:
print(Fore.GREEN + "---------------------------" + Style.RESET_ALL)
print(Fore.GREEN + "Executing Python unit tests" + Style.RESET_ALL)
print(Fore.GREEN + "---------------------------" + Style.RESET_ALL, flush=True)
base_path = os.path.dirname(os.path.realpath(__file__))
pytest.main([
os.path.join(base_path, 'pytest'),
'--lmenv', args.lmenv
])
# Execute functional tests
if args.functest:
print(Fore.GREEN + "--------------------------" + Style.RESET_ALL)
print(Fore.GREEN + "Executing functional tests" + Style.RESET_ALL)
print(Fore.GREEN + "--------------------------" + Style.RESET_ALL, flush=True)
run_functests(args.output_dir, args.lmenv)