conftest.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import sys
  2. import pytest
  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. env.config['application']['data_dir'] = data_dir
  13. env.config['application']['store']['ldp_nr']['location'] = path.join(
  14. data_dir, 'ldpnr_store')
  15. env.config['application']['store']['ldp_rs']['location'] = path.join(
  16. data_dir, 'ldprs_store')
  17. app = create_app(env.config['application'])
  18. yield app
  19. # TODO improve this by using tempfile.TemporaryDirectory as a context
  20. # manager.
  21. print('Removing fixture data directory.')
  22. rmtree(data_dir)
  23. @pytest.fixture(scope='module')
  24. def db(app):
  25. '''
  26. Set up and tear down test triplestore.
  27. '''
  28. rdfly = env.app_globals.rdfly
  29. rdfly.bootstrap()
  30. env.app_globals.nonrdfly.bootstrap()
  31. yield rdfly
  32. print('Tearing down fixture graph store.')
  33. rdfly.store.destroy(rdfly.store.path)
  34. @pytest.fixture
  35. def rnd_img():
  36. '''
  37. Generate a square image with random color tiles.
  38. '''
  39. return random_image(8, 256)