run.py 1.62 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 multiprocessing
7
8
import os
import platform
9
10
import time

11

12
13
def run_tests(command):
    testtype = 'DOCTEST' if command.find('doctest') >= 0 else 'UNITTEST'
14
15
16
17
18
    filename = command[command.rfind(' ')+1:]
    print('\n' + testtype + ' ' + filename)
    os.system(command)


19
if __name__ == "__main__":
eckhart's avatar
eckhart committed
20
    scriptdir = os.path.dirname(os.path.realpath(__file__))
21

22
23
24
25
    # if os.getcwd().endswith('test'):
    #     os.chdir('..')
    # print("Running nosetests:")
    # os.system("nosetests test")
eckhart's avatar
eckhart committed
26
    if platform.system() != "Windows":
27
        interpreters = ['pypy3 ', 'python3 ']
eckhart's avatar
eckhart committed
28
    else:
29
        interpreters = ['python.exe ']
30

eckhart's avatar
eckhart committed
31
    cwd = os.getcwd()
32
    os.chdir(scriptdir + '/..')
33

34
35
    timestamp = time.time()

36
    with concurrent.futures.ProcessPoolExecutor(multiprocessing.cpu_count()) as pool:
37
38
        for interpreter in interpreters:
            os.system(interpreter + '--version')
eckhart's avatar
eckhart committed
39

40
41
42
43
            # doctests
            commands = [interpreter + ' -m doctest ' + os.path.join('DHParser', filename)
                        for filename in os.listdir('DHParser') if filename.endswith('.py')
                        and filename not in ["foreign_typing.py", "stringview.py", "__init__.py"]]
44
45
46
47
48
49

            # unit tests
            commands += [interpreter + os.path.join('test', filename)
                         for filename in os.listdir('test') if filename.startswith('test_')]

            pool.map(run_tests, commands)
eckhart's avatar
eckhart committed
50

51
52
53
    elapsed = time.time() - timestamp
    print('\n Test-Duration: %.2f seconds' % elapsed)

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