##// END OF EJS Templates
Added base class for Notebook API tests.
Brian E. Granger -
Show More
1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
@@ -0,0 +1,23
1 """Test the kernels service API."""
2
3
4 import os
5 import sys
6 import json
7
8 import requests
9
10 from IPython.html.tests.launchnotebook import NotebookTestBase
11
12
13 class KernelAPITest(NotebookTestBase):
14 """Test the kernels web service API"""
15
16 def base_url(self):
17 return super(KernelAPITest,self).base_url() + 'api/kernels'
18
19 def test_no_kernels(self):
20 """Make sure there are no kernels running at the start"""
21 url = self.base_url()
22 r = requests.get(url)
23 assert r.json() == []
@@ -0,0 +1,40
1 """Base class for notebook tests."""
2
3 import sys
4 import time
5 from subprocess import Popen, PIPE
6 from unittest import TestCase
7
8 from IPython.utils.tempdir import TemporaryDirectory
9
10
11 class NotebookTestBase(TestCase):
12 """A base class for tests that need a running notebook.
13
14 This creates an empty profile in a temp ipython_dir
15 and then starts the notebook server with a separate temp notebook_dir.
16 """
17
18 port = 12342
19
20 def setUp(self):
21 self.ipython_dir = TemporaryDirectory()
22 self.notebook_dir = TemporaryDirectory()
23 notebook_args = [
24 sys.executable, '-c',
25 'from IPython.html.notebookapp import launch_new_instance; launch_new_instance()',
26 '--port=%d' % self.port,
27 '--no-browser',
28 '--ipython-dir=%s' % self.ipython_dir.name,
29 '--notebook-dir=%s' % self.notebook_dir.name
30 ]
31 self.notebook = Popen(notebook_args, stdout=PIPE, stderr=PIPE)
32 time.sleep(3.0)
33
34 def tearDown(self):
35 self.notebook.terminate()
36 self.ipython_dir.cleanup()
37 self.notebook_dir.cleanup()
38
39 def base_url(self):
40 return 'http://localhost:%i/' % self.port
General Comments 0
You need to be logged in to leave comments. Login now