conftest.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import pytest
  2. from os import makedirs, path
  3. from shutil import rmtree
  4. from tempfile import gettempdir
  5. from lakesuperior import env_setup, env
  6. from lakesuperior.app import create_app
  7. from lakesuperior.util.generators import random_image
  8. @pytest.fixture(scope='module')
  9. def app():
  10. # Override data directory locations.
  11. data_dir = path.join(gettempdir(), 'lsup_test', 'data')
  12. makedirs(data_dir, exist_ok=True)
  13. env.app_globals.config['application']['data_dir'] = data_dir
  14. env.app_globals.config['application']['store']['ldp_nr']['location'] = (
  15. path.join(data_dir, 'ldpnr_store'))
  16. env.app_globals.config['application']['store']['ldp_rs']['location'] = (
  17. path.join(data_dir, 'ldprs_store'))
  18. app = create_app(env.app_globals.config['application'])
  19. yield app
  20. # TODO improve this by using tempfile.TemporaryDirectory as a context
  21. # manager.
  22. print('Removing fixture data directory.')
  23. rmtree(data_dir)
  24. @pytest.fixture(scope='module')
  25. def db(app):
  26. '''
  27. Set up and tear down test triplestore.
  28. '''
  29. rdfly = env.app_globals.rdfly
  30. rdfly.bootstrap()
  31. env.app_globals.nonrdfly.bootstrap()
  32. yield rdfly
  33. print('Tearing down fixture graph store.')
  34. rdfly.store.destroy(rdfly.store.path)
  35. @pytest.fixture
  36. def rnd_img():
  37. '''
  38. Generate a square image with random color tiles.
  39. '''
  40. return random_image(8, 256)