TEST: Use a temporary file instead of a local file for test db.

This commit is contained in:
Scott Sanderson
2014-10-30 01:49:22 -04:00
parent 8cfbe9b38e
commit cd1695fdb6

View File

@@ -2,6 +2,7 @@
import os import os
import sys import sys
from tempfile import NamedTemporaryFile
import threading import threading
try: try:
@@ -58,19 +59,11 @@ class MockPAMAuthenticator(PAMAuthenticator):
class MockHubApp(JupyterHubApp): class MockHubApp(JupyterHubApp):
"""HubApp with various mock bits""" """HubApp with various mock bits"""
db_path = os.path.join( db_file = None
os.path.dirname(
os.path.realpath(__file__),
),
"test.sqlite",
)
def _ip_default(self): def _ip_default(self):
return 'localhost' return 'localhost'
def _db_url_default(self):
return "sqlite:///" + self.db_path
def _authenticator_class_default(self): def _authenticator_class_default(self):
return MockPAMAuthenticator return MockPAMAuthenticator
@@ -80,12 +73,9 @@ class MockHubApp(JupyterHubApp):
def _admin_users_default(self): def _admin_users_default(self):
return {'admin'} return {'admin'}
def rm_db(self):
if os.path.exists(self.db_path):
os.remove(self.db_path)
def start(self, argv=None): def start(self, argv=None):
self.rm_db() self.db_file = NamedTemporaryFile()
self.db_url = 'sqlite:///' + self.db_file.name
evt = threading.Event() evt = threading.Event()
def _start(): def _start():
self.io_loop = IOLoop.current() self.io_loop = IOLoop.current()
@@ -104,6 +94,6 @@ class MockHubApp(JupyterHubApp):
evt.wait(timeout=5) evt.wait(timeout=5)
def stop(self): def stop(self):
self.rm_db() self.db_file.close()
self.io_loop.add_callback(self.io_loop.stop) self.io_loop.add_callback(self.io_loop.stop)
self._thread.join() self._thread.join()