Show More
@@ -78,7 +78,6 b' class TestContentsManager(TestCase):' | |||||
78 | self.td = self._temp_dir.name |
|
78 | self.td = self._temp_dir.name | |
79 | self.contents_manager = FileContentsManager( |
|
79 | self.contents_manager = FileContentsManager( | |
80 | root_dir=self.td, |
|
80 | root_dir=self.td, | |
81 | log=logging.getLogger() |
|
|||
82 | ) |
|
81 | ) | |
83 |
|
82 | |||
84 | def tearDown(self): |
|
83 | def tearDown(self): |
@@ -6,11 +6,12 b' import sys' | |||||
6 | import time |
|
6 | import time | |
7 | import requests |
|
7 | import requests | |
8 | from contextlib import contextmanager |
|
8 | from contextlib import contextmanager | |
9 | from subprocess import Popen, STDOUT |
|
9 | from threading import Thread, Event | |
10 | from unittest import TestCase |
|
10 | from unittest import TestCase | |
11 |
|
11 | |||
12 | import nose |
|
12 | from tornado.ioloop import IOLoop | |
13 |
|
13 | |||
|
14 | from ..notebookapp import NotebookApp | |||
14 | from IPython.utils.tempdir import TemporaryDirectory |
|
15 | from IPython.utils.tempdir import TemporaryDirectory | |
15 |
|
16 | |||
16 | MAX_WAITTIME = 30 # seconds to wait for notebook server to start |
|
17 | MAX_WAITTIME = 30 # seconds to wait for notebook server to start | |
@@ -50,35 +51,46 b' class NotebookTestBase(TestCase):' | |||||
50 | @classmethod |
|
51 | @classmethod | |
51 | def wait_until_dead(cls): |
|
52 | def wait_until_dead(cls): | |
52 | """Wait for the server process to terminate after shutdown""" |
|
53 | """Wait for the server process to terminate after shutdown""" | |
53 | for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): |
|
54 | cls.notebook_thread.join(timeout=MAX_WAITTIME) | |
54 |
|
|
55 | if cls.notebook_thread.is_alive(): | |
55 | return |
|
56 | raise TimeoutError("Undead notebook server") | |
56 | time.sleep(POLL_INTERVAL) |
|
|||
57 |
|
||||
58 | raise TimeoutError("Undead notebook server") |
|
|||
59 |
|
57 | |||
60 | @classmethod |
|
58 | @classmethod | |
61 | def setup_class(cls): |
|
59 | def setup_class(cls): | |
62 | cls.ipython_dir = TemporaryDirectory() |
|
60 | cls.ipython_dir = TemporaryDirectory() | |
63 | cls.notebook_dir = TemporaryDirectory() |
|
61 | cls.notebook_dir = TemporaryDirectory() | |
64 | notebook_args = [ |
|
62 | app = cls.notebook = NotebookApp( | |
65 | sys.executable, '-c', |
|
63 | port=cls.port, | |
66 | 'from IPython.html.notebookapp import launch_new_instance; launch_new_instance()', |
|
64 | port_retries=0, | |
67 | '--port=%d' % cls.port, |
|
65 | open_browser=False, | |
68 | '--port-retries=0', # Don't try any other ports |
|
66 | ipython_dir=cls.ipython_dir.name, | |
69 | '--no-browser', |
|
67 | notebook_dir=cls.notebook_dir.name, | |
70 | '--ipython-dir=%s' % cls.ipython_dir.name, |
|
|||
71 | '--notebook-dir=%s' % cls.notebook_dir.name, |
|
|||
72 | ] |
|
|||
73 | cls.notebook = Popen(notebook_args, |
|
|||
74 | stdout=nose.iptest_stdstreams_fileno(), |
|
|||
75 | stderr=STDOUT, |
|
|||
76 | ) |
|
68 | ) | |
|
69 | ||||
|
70 | # clear log handlers and propagate to root for nose to capture it | |||
|
71 | # needs to be redone after initialize, which reconfigures logging | |||
|
72 | app.log.propagate = True | |||
|
73 | app.log.handlers = [] | |||
|
74 | app.initialize(argv=[]) | |||
|
75 | app.log.propagate = True | |||
|
76 | app.log.handlers = [] | |||
|
77 | started = Event() | |||
|
78 | def start_thread(): | |||
|
79 | loop = IOLoop.current() | |||
|
80 | loop.add_callback(started.set) | |||
|
81 | try: | |||
|
82 | app.start() | |||
|
83 | finally: | |||
|
84 | # set the event, so failure to start doesn't cause a hang | |||
|
85 | started.set() | |||
|
86 | cls.notebook_thread = Thread(target=start_thread) | |||
|
87 | cls.notebook_thread.start() | |||
|
88 | started.wait() | |||
77 | cls.wait_until_alive() |
|
89 | cls.wait_until_alive() | |
78 |
|
90 | |||
79 | @classmethod |
|
91 | @classmethod | |
80 | def teardown_class(cls): |
|
92 | def teardown_class(cls): | |
81 |
cls.notebook. |
|
93 | cls.notebook.stop() | |
82 | cls.wait_until_dead() |
|
94 | cls.wait_until_dead() | |
83 | cls.ipython_dir.cleanup() |
|
95 | cls.ipython_dir.cleanup() | |
84 | cls.notebook_dir.cleanup() |
|
96 | cls.notebook_dir.cleanup() |
General Comments 0
You need to be logged in to leave comments.
Login now