1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import pytest
- from os import makedirs, path
- from shutil import rmtree
- from tempfile import gettempdir
- from lakesuperior import env_setup, env
- from lakesuperior.app import create_app
- from lakesuperior.util.generators import random_image
- @pytest.fixture(scope='module')
- def app():
- # Override data directory locations.
- data_dir = path.join(gettempdir(), 'lsup_test', 'data')
- makedirs(data_dir, exist_ok=True)
- env.app_globals.config['application']['data_dir'] = data_dir
- env.app_globals.config['application']['store']['ldp_nr']['location'] = (
- path.join(data_dir, 'ldpnr_store'))
- env.app_globals.config['application']['store']['ldp_rs']['location'] = (
- path.join(data_dir, 'ldprs_store'))
- app = create_app(env.app_globals.config['application'])
- yield app
- # TODO improve this by using tempfile.TemporaryDirectory as a context
- # manager.
- print('Removing fixture data directory.')
- rmtree(data_dir)
- @pytest.fixture(scope='module')
- def db(app):
- '''
- Set up and tear down test triplestore.
- '''
- rdfly = env.app_globals.rdfly
- rdfly.bootstrap()
- env.app_globals.nonrdfly.bootstrap()
- yield rdfly
- print('Tearing down fixture graph store.')
- rdfly.store.destroy(rdfly.store.path)
- @pytest.fixture
- def rnd_img():
- '''
- Generate a square image with random color tiles.
- '''
- return random_image(8, 256)
|