run_test.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Copyright (c) Jupyter Development Team.
  2. # Distributed under the terms of the Modified BSD License.
  3. import subprocess
  4. import sys
  5. import argparse
  6. import threading
  7. KARMA_PORT = 9876
  8. argparser = argparse.ArgumentParser(
  9. description='Run Jupyter JS Terminal integration tests'
  10. )
  11. argparser.add_argument('-b', '--browsers', default='Firefox',
  12. help="Browsers to use for Karma test")
  13. argparser.add_argument('-d', '--debug', action='store_true',
  14. help="Whether to enter debug mode in Karma")
  15. options = argparser.parse_args(sys.argv[1:])
  16. nb_command = [sys.executable, '-m', 'notebook', '--no-browser',
  17. '--NotebookApp.allow_origin="*"']
  18. nb_server = subprocess.Popen(nb_command, stderr=subprocess.STDOUT,
  19. stdout=subprocess.PIPE)
  20. # wait for notebook server to start up
  21. while 1:
  22. line = nb_server.stdout.readline().decode('utf-8').strip()
  23. if not line:
  24. continue
  25. print(line)
  26. if 'The IPython Notebook is running at: http://localhost:8888/':
  27. break
  28. if 'Control-C' in line:
  29. raise ValueError(
  30. 'The port 8888 was already taken, kill running notebook servers'
  31. )
  32. def readlines():
  33. """Print the notebook server output."""
  34. while 1:
  35. line = nb_server.stdout.readline().decode('utf-8').strip()
  36. if line:
  37. print(line)
  38. thread = threading.Thread(target=readlines)
  39. thread.setDaemon(True)
  40. thread.start()
  41. if options.debug:
  42. options.browsers = 'Chrome'
  43. karma_command = ['karma', 'start', '--browsers=' + options.browsers,
  44. 'karma.conf.js', '--port=%s' % KARMA_PORT]
  45. if options.debug:
  46. karma_command += ['--singleRun=false', '--debug=true']
  47. print(' '.join(karma_command))
  48. resp = 1
  49. try:
  50. resp = subprocess.check_call(karma_command, stderr=subprocess.STDOUT)
  51. except subprocess.CalledProcessError:
  52. pass
  53. finally:
  54. nb_server.kill()
  55. sys.exit(resp)