##// END OF EJS Templates
Require jsonschema for nbformat, html and nbconvert tests
Require jsonschema for nbformat, html and nbconvert tests

File last commit:

r16538:2c5d8c33
r16981:96681f4a
Show More
launchnotebook.py
101 lines | 3.1 KiB | text/x-python | PythonLexer
Brian E. Granger
Added base class for Notebook API tests.
r13038 """Base class for notebook tests."""
Brian E. Granger
Adding dashboard navigation tests for dir browsing.
r15080 from __future__ import print_function
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
Thomas Kluyver
Capture server logs when running notebook tests
r13833 from subprocess import Popen, STDOUT
Brian E. Granger
Added base class for Notebook API tests.
r13038 from unittest import TestCase
Thomas Kluyver
Capture server logs when running notebook tests
r13833 import nose
Brian E. Granger
Added base class for Notebook API tests.
r13038 from IPython.utils.tempdir import TemporaryDirectory
Paul Ivanov
Clarify waiting for notebook server to launch
r14071 MAX_WAITTIME = 30 # seconds to wait for notebook server to start
POLL_INTERVAL = 0.1 # time between attempts
Brian E. Granger
Adding comment about this fix.
r15624 # TimeoutError is a builtin on Python 3. This can be removed when we stop
# supporting Python 2.
Brian E. Granger
Missing class def for TimeoutError.
r15621 class TimeoutError(Exception):
pass
Brian E. Granger
Added base class for Notebook API tests.
r13038 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
Paul Ivanov
Clarify waiting for notebook server to launch
r14071 for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)):
Zachary Sailer
review fixes on tests, add extra kernel api test
r13045 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:
Thomas Kluyver
Don't wait forever for notebook server to launch/die for tests...
r14067 if cls.notebook.poll() is not None:
raise RuntimeError("The notebook server exited with status %s" \
% cls.notebook.poll())
Paul Ivanov
Clarify waiting for notebook server to launch
r14071 time.sleep(POLL_INTERVAL)
MinRK
don't start new notebook server for each test *method*...
r13049 else:
Thomas Kluyver
Don't wait forever for notebook server to launch/die for tests...
r14067 return
raise TimeoutError("The notebook server didn't start up correctly.")
MinRK
don't start new notebook server for each test *method*...
r13049
@classmethod
def wait_until_dead(cls):
Thomas Kluyver
Simplify waiting for notebook server to die.
r14068 """Wait for the server process to terminate after shutdown"""
Paul Ivanov
Clarify waiting for notebook server to launch
r14071 for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)):
Thomas Kluyver
Simplify waiting for notebook server to die.
r14068 if cls.notebook.poll() is not None:
return
Paul Ivanov
Clarify waiting for notebook server to launch
r14071 time.sleep(POLL_INTERVAL)
MinRK
don't start new notebook server for each test *method*...
r13049
Thomas Kluyver
Don't wait forever for notebook server to launch/die for tests...
r14067 raise TimeoutError("Undead notebook server")
MinRK
don't start new notebook server for each test *method*...
r13049 @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,
Paul Ivanov
Clarify waiting for notebook server to launch
r14071 '--port-retries=0', # Don't try any other ports
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,
]
cls.notebook = Popen(notebook_args,
Thomas Kluyver
Fix notebook tests w/ new stream capturing API.
r13839 stdout=nose.iptest_stdstreams_fileno(),
Thomas Kluyver
Capture server logs when running notebook tests
r13833 stderr=STDOUT,
MinRK
send ignored output to devnull...
r13180 )
MinRK
don't start new notebook server for each test *method*...
r13049 cls.wait_until_alive()
@classmethod
def teardown_class(cls):
cls.notebook.terminate()
MinRK
wait until dead *before* cleaning up the temp dir
r16538 cls.wait_until_dead()
MinRK
don't start new notebook server for each test *method*...
r13049 cls.ipython_dir.cleanup()
cls.notebook_dir.cleanup()
@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"