##// END OF EJS Templates
review fixes on tests, add extra kernel api test
review fixes on tests, add extra kernel api test

File last commit:

r13045:cc15133f
r13045:cc15133f
Show More
launchnotebook.py
63 lines | 1.9 KiB | text/x-python | PythonLexer
Brian E. Granger
Added base class for Notebook API tests.
r13038 """Base class for notebook tests."""
import sys
import time
Zachary Sailer
review fixes on tests, add extra kernel api test
r13045 import requests
Brian E. Granger
Added base class for Notebook API tests.
r13038 from subprocess import Popen, PIPE
from unittest import TestCase
from IPython.utils.tempdir import TemporaryDirectory
class NotebookTestBase(TestCase):
"""A base class for tests that need a running notebook.
This creates an empty profile in a temp ipython_dir
and then starts the notebook server with a separate temp notebook_dir.
"""
Zachary Sailer
add tests for session api
r13044 port = 1234
Brian E. Granger
Added base class for Notebook API tests.
r13038
Zachary Sailer
review fixes on tests, add extra kernel api test
r13045 def wait_till_alive(self):
url = 'http://localhost:%i/' % self.port
while True:
time.sleep(.1)
try:
r = requests.get(url + 'api/notebooks')
break
except requests.exceptions.ConnectionError:
pass
def wait_till_dead(self):
url = 'http://localhost:%i/' % self.port
while True:
time.sleep(.1)
try:
r = requests.get(url + 'api/notebooks')
continue
except requests.exceptions.ConnectionError:
break
Brian E. Granger
Added base class for Notebook API tests.
r13038 def setUp(self):
self.ipython_dir = TemporaryDirectory()
self.notebook_dir = TemporaryDirectory()
notebook_args = [
sys.executable, '-c',
'from IPython.html.notebookapp import launch_new_instance; launch_new_instance()',
'--port=%d' % self.port,
'--no-browser',
'--ipython-dir=%s' % self.ipython_dir.name,
'--notebook-dir=%s' % self.notebook_dir.name
Zachary Sailer
review fixes on tests, add extra kernel api test
r13045 ]
Brian E. Granger
Added base class for Notebook API tests.
r13038 self.notebook = Popen(notebook_args, stdout=PIPE, stderr=PIPE)
Zachary Sailer
review fixes on tests, add extra kernel api test
r13045 self.wait_till_alive()
#time.sleep(3.0)
Brian E. Granger
Added base class for Notebook API tests.
r13038
def tearDown(self):
self.notebook.terminate()
self.ipython_dir.cleanup()
self.notebook_dir.cleanup()
Zachary Sailer
review fixes on tests, add extra kernel api test
r13045 self.wait_till_dead()
Brian E. Granger
Added base class for Notebook API tests.
r13038 def base_url(self):
return 'http://localhost:%i/' % self.port