Show More
@@ -18,45 +18,52 b' class NotebookTestBase(TestCase):' | |||||
18 |
|
18 | |||
19 | port = 12341 |
|
19 | port = 12341 | |
20 |
|
20 | |||
21 | def wait_till_alive(self): |
|
21 | @classmethod | |
22 | url = 'http://localhost:%i/' % self.port |
|
22 | def wait_until_alive(cls): | |
|
23 | """Wait for the server to be alive""" | |||
|
24 | url = 'http://localhost:%i/api/notebooks' % cls.port | |||
23 | while True: |
|
25 | while True: | |
24 | time.sleep(.1) |
|
|||
25 | try: |
|
26 | try: | |
26 |
|
|
27 | requests.get(url) | |
27 | break |
|
|||
28 | except requests.exceptions.ConnectionError: |
|
28 | except requests.exceptions.ConnectionError: | |
29 |
|
|
29 | time.sleep(.1) | |
|
30 | else: | |||
|
31 | break | |||
30 |
|
|
32 | ||
31 | def wait_till_dead(self): |
|
33 | @classmethod | |
32 | url = 'http://localhost:%i/' % self.port |
|
34 | def wait_until_dead(cls): | |
|
35 | """Wait for the server to stop getting requests after shutdown""" | |||
|
36 | url = 'http://localhost:%i/api/notebooks' % cls.port | |||
33 | while True: |
|
37 | while True: | |
34 | time.sleep(.1) |
|
|||
35 | try: |
|
38 | try: | |
36 |
|
|
39 | requests.get(url) | |
37 | continue |
|
|||
38 | except requests.exceptions.ConnectionError: |
|
40 | except requests.exceptions.ConnectionError: | |
39 | break |
|
41 | break | |
|
42 | else: | |||
|
43 | time.sleep(.1) | |||
40 |
|
44 | |||
41 | def setUp(self): |
|
45 | @classmethod | |
42 | self.ipython_dir = TemporaryDirectory() |
|
46 | def setup_class(cls): | |
43 |
s |
|
47 | cls.ipython_dir = TemporaryDirectory() | |
|
48 | cls.notebook_dir = TemporaryDirectory() | |||
44 | notebook_args = [ |
|
49 | notebook_args = [ | |
45 | sys.executable, '-c', |
|
50 | sys.executable, '-c', | |
46 | 'from IPython.html.notebookapp import launch_new_instance; launch_new_instance()', |
|
51 | 'from IPython.html.notebookapp import launch_new_instance; launch_new_instance()', | |
47 |
'--port=%d' % s |
|
52 | '--port=%d' % cls.port, | |
48 | '--no-browser', |
|
53 | '--no-browser', | |
49 |
'--ipython-dir=%s' % s |
|
54 | '--ipython-dir=%s' % cls.ipython_dir.name, | |
50 |
'--notebook-dir=%s' % s |
|
55 | '--notebook-dir=%s' % cls.notebook_dir.name | |
51 | ] |
|
56 | ] | |
52 |
s |
|
57 | cls.notebook = Popen(notebook_args, stdout=PIPE, stderr=PIPE) | |
53 |
s |
|
58 | cls.wait_until_alive() | |
54 |
|
59 | |||
55 | def tearDown(self): |
|
60 | @classmethod | |
56 | self.notebook.terminate() |
|
61 | def teardown_class(cls): | |
57 | self.ipython_dir.cleanup() |
|
62 | cls.notebook.terminate() | |
58 |
s |
|
63 | cls.ipython_dir.cleanup() | |
59 | self.wait_till_dead() |
|
64 | cls.notebook_dir.cleanup() | |
|
65 | cls.wait_until_dead() | |||
60 |
|
66 | |||
61 | def base_url(self): |
|
67 | @classmethod | |
62 | return 'http://localhost:%i/' % self.port |
|
68 | def base_url(cls): | |
|
69 | return 'http://localhost:%i/' % cls.port |
General Comments 0
You need to be logged in to leave comments.
Login now