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