##// END OF EJS Templates
Merge pull request #8190 from minrk/sticky-tooltip-description...
Merge pull request #8190 from minrk/sticky-tooltip-description update description of sticky tooltip

File last commit:

r19604:25165b0a
r21005:12f54add merge
Show More
launchnotebook.py
115 lines | 3.5 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
Min RK
run test server in thread...
r19348 from threading import Thread, Event
Brian E. Granger
Added base class for Notebook API tests.
r13038 from unittest import TestCase
Min RK
run test server in thread...
r19348 from tornado.ioloop import IOLoop
Thomas Kluyver
Capture server logs when running notebook tests
r13833
Min RK
run test server in thread...
r19348 from ..notebookapp import NotebookApp
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
Min RK
abstract some methods in contents service tests...
r19604 config = None
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"""
MinRK
rename notebooks service to contents service...
r17524 url = 'http://localhost:%i/api/contents' % 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)
MinRK
catch any exception while waiting to connect...
r17749 except Exception as e:
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"""
Min RK
run test server in thread...
r19348 cls.notebook_thread.join(timeout=MAX_WAITTIME)
if cls.notebook_thread.is_alive():
raise TimeoutError("Undead notebook server")
Thomas Kluyver
Don't wait forever for notebook server to launch/die for tests...
r14067
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()
Min RK
run test server in thread...
r19348 app = cls.notebook = NotebookApp(
port=cls.port,
port_retries=0,
open_browser=False,
ipython_dir=cls.ipython_dir.name,
notebook_dir=cls.notebook_dir.name,
Min RK
abstract some methods in contents service tests...
r19604 config=cls.config,
MinRK
send ignored output to devnull...
r13180 )
Min RK
run test server in thread...
r19348
# clear log handlers and propagate to root for nose to capture it
# needs to be redone after initialize, which reconfigures logging
app.log.propagate = True
app.log.handlers = []
app.initialize(argv=[])
app.log.propagate = True
app.log.handlers = []
started = Event()
def start_thread():
loop = IOLoop.current()
loop.add_callback(started.set)
try:
app.start()
finally:
# set the event, so failure to start doesn't cause a hang
started.set()
cls.notebook_thread = Thread(target=start_thread)
cls.notebook_thread.start()
started.wait()
MinRK
don't start new notebook server for each test *method*...
r13049 cls.wait_until_alive()
@classmethod
def teardown_class(cls):
Min RK
run test server in thread...
r19348 cls.notebook.stop()
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, \
Thomas Kluyver
Fix failure message for tests
r17774 "Expected status %d, got %d" % (status, real_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"