run.py 2.34 KB
Newer Older
1
2
#!/usr/bin/python

3
4
"""Runs the dhparser test-suite with several installed interpreters"""

5
import concurrent.futures
6
import doctest
7
import multiprocessing
8
9
import os
import platform
10
import sys
11
import time
12
import threading
13

14
15
16
scriptdir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(scriptdir, '../'))

17
lock = threading.Lock()
18

19

20
def run_doctests(module):
21
22
23
24
25
26
27
    with lock:
        namespace = {}
        print('DOCTEST ' + module)
        exec('import DHParser.' + module, namespace)
        mod = getattr(namespace['DHParser'], module)
        result = doctest.testmod(mod)
        return result.failed
28

29
30
31
32
33
34
35

# def run_unittests(command):
#     args = command.split(' ')
#     filename = args[1]
#     print('\nUNITTEST ' + filename)
#     subprocess.run(args)

36

37
if __name__ == "__main__":
eckhart's avatar
eckhart committed
38
    if platform.system() != "Windows":
39
        interpreters = ['pypy3 ', 'python3 ']
eckhart's avatar
eckhart committed
40
    else:
41
        interpreters = ['python.exe ']
42

eckhart's avatar
eckhart committed
43
    cwd = os.getcwd()
44
    os.chdir(os.path.join(scriptdir, '..'))
45

46
47
    timestamp = time.time()

48
49
    run_doctests('toolkit')

50
    with concurrent.futures.ProcessPoolExecutor(multiprocessing.cpu_count()) as pool:
51
        results = []
eckhart's avatar
eckhart committed
52

53
54
55
56
57
58
        # doctests
        for filename in os.listdir('DHParser'):
            if filename.endswith('.py') and filename not in \
                    ("foreign_typing.py", "shadow_cython.py", "versionnumber.py",
                     "__init__.py"):
                results.append(pool.submit(run_doctests, filename[:-3]))
59

60
61
62
        # unit tests
        for interpreter in interpreters:
            os.system(interpreter + '--version')
63
64
65
66
67
            # for filename in os.listdir('test'):
            #     if filename.startswith('test_'):
            #         command = interpreter + os.path.join('test', filename)
            #         results.append(pool.submit(run_unittests, command))
            os.system(' '.join([interpreter, '-c',
68
69
70
71
                                '''"import sys; '''
                                '''sys.path.extend(['DHParser']);''' 
                                '''import testing; testing.run_path('%s')"''' %
                                scriptdir.replace('\\', '\\\\'),
72
                            os.path.join(os.getcwd(), 'test')]))
73

74
        concurrent.futures.wait(results)
eckhart's avatar
eckhart committed
75

76
77
78
    elapsed = time.time() - timestamp
    print('\n Test-Duration: %.2f seconds' % elapsed)

eckhart's avatar
eckhart committed
79
    os.chdir(cwd)