test_examples.py 1.3 KB

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