test_examples.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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.
  8. """
  9. import glob
  10. import os.path as osp
  11. import subprocess
  12. import sys
  13. here = osp.abspath(osp.dirname(__file__))
  14. def header(path):
  15. test_name = osp.basename(path)
  16. print('\n'.join((
  17. '\n',
  18. '*' * 40,
  19. 'Starting %s test' % test_name,
  20. '*' * 40
  21. )), flush=True)
  22. def main():
  23. paths = [i for i in glob.glob('%s/*' % here) if osp.isdir(i)]
  24. services_dir = osp.abspath(osp.join(here, '../packages/services/examples'))
  25. paths += [i for i in glob.glob('%s/*' % services_dir)]
  26. count = 0
  27. for path in sorted(paths):
  28. if osp.basename(path) == 'node':
  29. header(path)
  30. runner = osp.join(path, 'main.py')
  31. subprocess.check_call([sys.executable, runner])
  32. count += 1
  33. continue
  34. if not osp.exists(osp.join(path, 'main.py')):
  35. continue
  36. count += 1
  37. header(path)
  38. runner = osp.join(here, 'example_check.py')
  39. subprocess.check_call([sys.executable, runner, path])
  40. print('\n\n%s tests complete!' % count)
  41. if __name__ == "__main__":
  42. main()