/
test_examples.py
63 lines (51 loc) · 1.91 KB
/
test_examples.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
# -*- coding: utf-8 -*-
"""
This file is meant to be used to test all of the example here and and
in ../packages/services/examples. We import each of the applications
and add instrument them with a puppeteer test that makes sure
there are no console errors or uncaught errors prior to a sentinel
string being printed (see chrome-example-test.js for the sentinel strings
checked before the browser.close() call).
"""
import argparse
import glob
import os.path as osp
import subprocess
import sys
import tempfile
here = osp.abspath(osp.dirname(__file__))
def header(path):
test_name = osp.basename(path)
print('\n'.join((
'\n',
'*' * 40,
'Starting %s test in %s' % (test_name, path),
'*' * 40
)), flush=True)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--testPath", help="paths containing this string are tested")
args = parser.parse_args()
paths = [i for i in glob.glob('%s/*' % here) if osp.isdir(i)]
services_dir = osp.abspath(osp.join(here, '../packages/services/examples'))
paths += [i for i in glob.glob('%s/*' % services_dir)]
if args.testPath:
paths = [p for p in paths if args.testPath in p]
print('Testing %s'%paths)
count = 0
for path in sorted(paths):
if osp.basename(path) == 'node':
with tempfile.TemporaryDirectory() as cwd:
header(path)
runner = osp.join(path, 'main.py')
subprocess.check_call([sys.executable, runner], cwd=cwd)
count += 1
elif osp.exists(osp.join(path, 'main.py')):
with tempfile.TemporaryDirectory() as cwd:
header(path)
runner = osp.join(here, 'example_check.py')
subprocess.check_call([sys.executable, runner, path], cwd=cwd)
count += 1
print('\n\n%s tests complete!' % count)
if __name__ == "__main__":
main()