]> git.openstreetmap.org Git - nominatim.git/blob - test/bdd/environment.py
bdd tests: make import style configurable
[nominatim.git] / test / bdd / environment.py
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
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
8
9 from behave import *
10
11 from steps.geometry_factory import GeometryFactory
12 from steps.nominatim_environment import NominatimEnvironment
13
14 TEST_BASE_DIR = Path(__file__) / '..' / '..'
15
16 userconfig = {
17     'BUILDDIR' : (TEST_BASE_DIR / '..' / 'build').resolve(),
18     'REMOVE_TEMPLATE' : False,
19     'KEEP_TEST_DB' : False,
20     'DB_HOST' : None,
21     'DB_PORT' : None,
22     'DB_USER' : None,
23     'DB_PASS' : None,
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',
31     'PHPCOV' : False, # set to output directory to enable code coverage
32 }
33
34 use_step_matcher("re")
35
36 def before_all(context):
37     # logging setup
38     context.config.setup_logging()
39     # set up -D options
40     for k,v in userconfig.items():
41         context.config.userdata.setdefault(k, v)
42     # Nominatim test setup
43     context.nominatim = NominatimEnvironment(context.config.userdata)
44     context.osm = GeometryFactory()
45
46
47 def before_scenario(context, scenario):
48     if 'DB' in context.tags:
49         context.nominatim.setup_db(context)
50     elif 'APIDB' in context.tags:
51         context.nominatim.setup_api_db()
52     elif 'UNKNOWNDB' in context.tags:
53         context.nominatim.setup_unknown_db()
54
55 def after_scenario(context, scenario):
56     if 'DB' in context.tags:
57         context.nominatim.teardown_db(context)
58
59
60 def before_tag(context, tag):
61     if tag == 'fail-legacy':
62         if context.config.userdata['TOKENIZER'] == 'legacy':
63             context.scenario.skip("Not implemented in legacy tokenizer")