forked from datajoint/datajoint-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
52 lines (39 loc) · 1.37 KB
/
Copy path__init__.py
File metadata and controls
52 lines (39 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
Package for testing datajoint. Setup fixture will be run
to ensure that proper database connection and access privilege
exists. The content of the test database will be destroyed
after the test.
"""
__author__ = 'Edgar Walker, Fabian Sinz, Dimitri Yatsenko'
import logging
from os import environ
# turn on verbose logging
logging.basicConfig(level=logging.DEBUG)
import datajoint as dj
__all__ = ['__author__', 'PREFIX', 'CONN_INFO']
# Connection for testing
CONN_INFO = dict(
host=environ.get('DJ_TEST_HOST', 'localhost'),
user=environ.get('DJ_TEST_USER', 'datajoint'),
passwd=environ.get('DJ_TEST_PASSWORD', 'datajoint'))
# Prefix for all databases used during testing
PREFIX = environ.get('DJ_TEST_DB_PREFIX', 'djtest')
def setup_package():
"""
Package-level unit test setup
Turns off safemode
"""
dj.config['safemode'] = False
def teardown_package():
"""
Package-level unit test teardown.
Removes all databases with name starting with PREFIX.
To deal with possible foreign key constraints, it will unset
and then later reset FOREIGN_KEY_CHECKS flag
"""
conn = dj.conn(**CONN_INFO)
conn.query('SET FOREIGN_KEY_CHECKS=0')
cur = conn.query('SHOW DATABASES LIKE "{}\_%%"'.format(PREFIX))
for db in cur.fetchall():
conn.query('DROP DATABASE `{}`'.format(db[0]))
conn.query('SET FOREIGN_KEY_CHECKS=1')