-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconftest.py
64 lines (48 loc) · 1.59 KB
/
conftest.py
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
53
54
55
56
57
58
59
60
61
62
63
64
import logging
import pytest
from os import makedirs, path
from shutil import rmtree
from tempfile import gettempdir
from lakesuperior import env
from lakesuperior.config_parser import parse_config
from lakesuperior.util.generators import random_image
# Override data directory locations.
config = parse_config()
data_dir = path.join(gettempdir(), 'lsup_test', 'data')
config['application']['data_dir'] = data_dir
config['application']['store']['ldp_nr']['location'] = (
path.join(data_dir, 'ldpnr_store'))
config['application']['store']['ldp_rs']['location'] = (
path.join(data_dir, 'ldprs_store'))
env.setup(config=config)
from lakesuperior.app import create_app
@pytest.fixture(scope='module')
def app():
app = create_app(env.app_globals.config['application'])
yield app
@pytest.fixture(scope='module')
def db(app):
'''
Set up and tear down test triplestore.
'''
env.app_globals.rdfly.bootstrap()
env.app_globals.nonrdfly.bootstrap()
print('Initialized data store.')
env.app_globals.rdf_store.open_env(
env.app_globals.rdf_store.env_path)
yield env.app_globals.rdfly
# TODO improve this by using tempfile.TemporaryDirectory as a context
# manager.
print('Removing fixture data directory.')
env.app_globals.rdf_store.close_env()
env.app_globals.rdf_store.destroy()
@pytest.fixture
def rnd_img():
'''
Generate a square image with random color tiles.
'''
return random_image(8, 256)
@pytest.fixture(autouse=True)
def disable_logging():
"""Disable logging in all tests."""
logging.disable(logging.INFO)