##// END OF EJS Templates
Added font-awesome to the slides to easily use some nice icons.
Added font-awesome to the slides to easily use some nice icons.

File last commit:

r13180:deb0ad90
r13699:508daae0
Show More
launchnotebook.py
87 lines | 2.5 KiB | text/x-python | PythonLexer
Brian E. Granger
Added base class for Notebook API tests.
r13038 """Base class for notebook tests."""
MinRK
send ignored output to devnull...
r13180 import os
Brian E. Granger
Added base class for Notebook API tests.
r13038 import sys
import time
Zachary Sailer
review fixes on tests, add extra kernel api test
r13045 import requests
Thomas Kluyver
Add failing test for listing nonexistant directory
r13099 from contextlib import contextmanager
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
refactoring of nbmanager and filenbmanager...
r13046 port = 12341
Brian E. Granger
Added base class for Notebook API tests.
r13038
MinRK
don't start new notebook server for each test *method*...
r13049 @classmethod
def wait_until_alive(cls):
"""Wait for the server to be alive"""
url = 'http://localhost:%i/api/notebooks' % cls.port
Zachary Sailer
review fixes on tests, add extra kernel api test
r13045 while True:
try:
MinRK
don't start new notebook server for each test *method*...
r13049 requests.get(url)
Zachary Sailer
review fixes on tests, add extra kernel api test
r13045 except requests.exceptions.ConnectionError:
MinRK
don't start new notebook server for each test *method*...
r13049 time.sleep(.1)
else:
break
@classmethod
def wait_until_dead(cls):
"""Wait for the server to stop getting requests after shutdown"""
url = 'http://localhost:%i/api/notebooks' % cls.port
Zachary Sailer
review fixes on tests, add extra kernel api test
r13045 while True:
try:
MinRK
don't start new notebook server for each test *method*...
r13049 requests.get(url)
Zachary Sailer
review fixes on tests, add extra kernel api test
r13045 except requests.exceptions.ConnectionError:
break
MinRK
don't start new notebook server for each test *method*...
r13049 else:
time.sleep(.1)
@classmethod
def setup_class(cls):
cls.ipython_dir = TemporaryDirectory()
cls.notebook_dir = TemporaryDirectory()
Brian E. Granger
Added base class for Notebook API tests.
r13038 notebook_args = [
sys.executable, '-c',
'from IPython.html.notebookapp import launch_new_instance; launch_new_instance()',
MinRK
don't start new notebook server for each test *method*...
r13049 '--port=%d' % cls.port,
Brian E. Granger
Added base class for Notebook API tests.
r13038 '--no-browser',
MinRK
don't start new notebook server for each test *method*...
r13049 '--ipython-dir=%s' % cls.ipython_dir.name,
MinRK
send ignored output to devnull...
r13180 '--notebook-dir=%s' % cls.notebook_dir.name,
]
devnull = open(os.devnull, 'w')
cls.notebook = Popen(notebook_args,
stdout=devnull,
stderr=devnull,
)
MinRK
don't start new notebook server for each test *method*...
r13049 cls.wait_until_alive()
@classmethod
def teardown_class(cls):
cls.notebook.terminate()
cls.ipython_dir.cleanup()
cls.notebook_dir.cleanup()
cls.wait_until_dead()
@classmethod
def base_url(cls):
return 'http://localhost:%i/' % cls.port
Thomas Kluyver
Add failing test for listing nonexistant directory
r13099
@contextmanager
Thomas Kluyver
Refactor tests for kernels REST API
r13105 def assert_http_error(status, msg=None):
Thomas Kluyver
Add failing test for listing nonexistant directory
r13099 try:
yield
except requests.HTTPError as e:
real_status = e.response.status_code
assert real_status == status, \
"Expected status %d, got %d" % (real_status, status)
Thomas Kluyver
Refactor tests for kernels REST API
r13105 if msg:
assert msg in str(e), e
Thomas Kluyver
Add failing test for listing nonexistant directory
r13099 else:
assert False, "Expected HTTP error status"