1 # SPDX-License-Identifier: GPL-2.0-only
 
   3 # This file is part of Nominatim. (https://nominatim.org)
 
   5 # Copyright (C) 2022 by the Nominatim developer community.
 
   6 # For a full list of authors see the git log.
 
   7 from pathlib import Path
 
  11 from steps.geometry_factory import GeometryFactory
 
  12 from steps.nominatim_environment import NominatimEnvironment
 
  14 TEST_BASE_DIR = Path(__file__) / '..' / '..'
 
  17     'BUILDDIR' : (TEST_BASE_DIR / '..' / 'build').resolve(),
 
  18     'REMOVE_TEMPLATE' : False,
 
  19     'KEEP_TEST_DB' : False,
 
  24     'TEMPLATE_DB' : 'test_template_nominatim',
 
  25     'TEST_DB' : 'test_nominatim',
 
  26     'API_TEST_DB' : 'test_api_nominatim',
 
  27     'API_TEST_FILE'  : (TEST_BASE_DIR / 'testdb' / 'apidb-test-data.pbf').resolve(),
 
  28     'SERVER_MODULE_PATH' : None,
 
  29     'TOKENIZER' : None, # Test with a custom tokenizer
 
  30     'STYLE' : 'extratags',
 
  32     'PHPCOV' : False, # set to output directory to enable code coverage
 
  35 use_step_matcher("re")
 
  37 def before_all(context):
 
  39     context.config.setup_logging()
 
  41     for k,v in userconfig.items():
 
  42         context.config.userdata.setdefault(k, v)
 
  43     # Nominatim test setup
 
  44     context.nominatim = NominatimEnvironment(context.config.userdata)
 
  45     context.osm = GeometryFactory()
 
  48 def before_scenario(context, scenario):
 
  49     if 'DB' in context.tags:
 
  50         context.nominatim.setup_db(context)
 
  51     elif 'APIDB' in context.tags:
 
  52         context.nominatim.setup_api_db()
 
  53     elif 'UNKNOWNDB' in context.tags:
 
  54         context.nominatim.setup_unknown_db()
 
  56 def after_scenario(context, scenario):
 
  57     if 'DB' in context.tags:
 
  58         context.nominatim.teardown_db(context)
 
  61 def before_tag(context, tag):
 
  62     if tag == 'fail-legacy':
 
  63         if context.config.userdata['TOKENIZER'] == 'legacy':
 
  64             context.scenario.skip("Not implemented in legacy tokenizer")
 
  65     if tag == 'v1-api-php-only':
 
  66         if context.config.userdata['API_ENGINE'] != 'php':
 
  67             context.scenario.skip("Only valid with PHP version of v1 API.")
 
  68     if tag == 'v1-api-python-only':
 
  69         if context.config.userdata['API_ENGINE'] == 'php':
 
  70             context.scenario.skip("Only valid with Python version of v1 API.")