conftest.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import sys
  2. import pytest
  3. from os import path
  4. from shutil import rmtree
  5. from tempfile import gettempdir
  6. from lakesuperior import env_setup, env
  7. from lakesuperior.app import create_app
  8. from lakesuperior.util.generators import random_image
  9. @pytest.fixture(scope='module')
  10. def app():
  11. # Override data directory locations.
  12. data_dir = path.join(gettempdir(), 'lsup_test', 'data')
  13. env.config['application']['data_dir'] = data_dir
  14. env.config['application']['store']['ldp_nr']['location'] = path.join(
  15. data_dir, 'ldpnr_store')
  16. env.config['application']['store']['ldp_rs']['location'] = path.join(
  17. data_dir, 'ldprs_store')
  18. app = create_app(env.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)