use a temporary directory for js tests

This commit is contained in:
Paul Ivanov 2013-09-26 14:41:02 -07:00
parent c6c5066162
commit 3fdbeb5cae

View File

@ -166,6 +166,10 @@ class JSController(TestController):
TestController.__init__(self) TestController.__init__(self)
self.section = section self.section = section
self.ipydir = TemporaryDirectory()
self.dirs.append(self.ipydir)
self.env['IPYTHONDIR'] = self.ipydir.name
# start the ipython notebook, so we get the port number # start the ipython notebook, so we get the port number
self._init_server() self._init_server()
@ -180,20 +184,21 @@ class JSController(TestController):
def _init_server(self): def _init_server(self):
"Start the notebook server in a separate process" "Start the notebook server in a separate process"
self.queue = q = Queue() self.queue = q = Queue()
self.server = server = Process(target=run_webapp, args=(q,)) self.server = Process(target=run_webapp, args=(q, self.ipydir.name))
server.start() self.server.start()
self.server_port = q.get() self.server_port = q.get()
def cleanup(self): def cleanup(self):
self.server.terminate() self.server.terminate()
self.server.join()
TestController.cleanup(self) TestController.cleanup(self)
def run_webapp(q): def run_webapp(q, nbdir):
"""start the IPython Notebook, and pass port back to the queue""" """start the IPython Notebook, and pass port back to the queue"""
import IPython.html.notebookapp as nbapp import IPython.html.notebookapp as nbapp
server = nbapp.NotebookApp() server = nbapp.NotebookApp()
server.initialize(['--no-browser']) server.initialize(['--no-browser', '--notebook-dir='+nbdir])
# communicate the port number to the parent process # communicate the port number to the parent process
q.put(server.port) q.put(server.port)
server.start() server.start()