test_examples.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # -*- coding: utf-8 -*-
  2. """
  3. This file is meant to be used to test all of the example here and and
  4. in ../packages/services/examples. We import each of the applications
  5. and add instrument them with a puppeteer test that makes sure
  6. there are no console errors or uncaught errors prior to a sentinel
  7. string being printed (see chrome-example-test.js for the sentinel strings
  8. checked before the browser.close() call).
  9. """
  10. import argparse
  11. import glob
  12. import os.path as osp
  13. import subprocess
  14. import sys
  15. import tempfile
  16. here = osp.abspath(osp.dirname(__file__))
  17. def header(path):
  18. test_name = osp.basename(path)
  19. print('\n'.join((
  20. '\n',
  21. '*' * 40,
  22. 'Starting %s test in %s' % (test_name, path),
  23. '*' * 40
  24. )), flush=True)
  25. def main():
  26. parser = argparse.ArgumentParser()
  27. parser.add_argument("--testPath", help="paths containing this string are tested")
  28. args = parser.parse_args()
  29. paths = [i for i in glob.glob('%s/*' % here) if osp.isdir(i)]
  30. services_dir = osp.abspath(osp.join(here, '../packages/services/examples'))
  31. paths += [i for i in glob.glob('%s/*' % services_dir)]
  32. if args.testPath:
  33. paths = [p for p in paths if args.testPath in p]
  34. print('Testing %s'%paths)
  35. count = 0
  36. for path in sorted(paths):
  37. if osp.basename(path) == 'node':
  38. with tempfile.TemporaryDirectory() as cwd:
  39. header(path)
  40. runner = osp.join(path, 'main.py')
  41. subprocess.check_call([sys.executable, runner], cwd=cwd)
  42. count += 1
  43. elif osp.exists(osp.join(path, 'main.py')):
  44. with tempfile.TemporaryDirectory() as cwd:
  45. header(path)
  46. runner = osp.join(here, 'example_check.py')
  47. subprocess.check_call([sys.executable, runner, path], cwd=cwd)
  48. count += 1
  49. print('\n\n%s tests complete!' % count)
  50. if __name__ == "__main__":
  51. main()