Skip to content

Commit cd08956

Browse files
authored
Merge pull request #3670 from lonvia/flake-for-tests
Extend linting with flake to tests
2 parents 5a245e3 + 12f5719 commit cd08956

File tree

106 files changed

+1342
-1610
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+1342
-1610
lines changed

.flake8

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ extend-ignore =
66
E711
77
per-file-ignores =
88
__init__.py: F401
9+
test/python/utils/test_json_writer.py: E131
10+
test/python/conftest.py: E402
11+
test/bdd/*: F821

.github/workflows/ci-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ jobs:
100100
run: ./venv/bin/pip install -U flake8
101101

102102
- name: Python linting
103-
run: ../venv/bin/python -m flake8 src
103+
run: ../venv/bin/python -m flake8 src test/python test/bdd
104104
working-directory: Nominatim
105105

106106
- name: Install mypy and typechecking info

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pytest:
2424
pytest test/python
2525

2626
lint:
27-
flake8 src
27+
flake8 src test/python test/bdd
2828

2929
bdd:
3030
cd test/bdd; behave -DREMOVE_TEMPLATE=1

test/bdd/environment.py

+22-19
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,53 @@
22
#
33
# This file is part of Nominatim. (https://nominatim.org)
44
#
5-
# Copyright (C) 2024 by the Nominatim developer community.
5+
# Copyright (C) 2025 by the Nominatim developer community.
66
# For a full list of authors see the git log.
77
from pathlib import Path
88
import sys
99

10-
from behave import *
10+
from behave import * # noqa
1111

1212
sys.path.insert(1, str(Path(__file__, '..', '..', '..', 'src').resolve()))
1313

14-
from steps.geometry_factory import GeometryFactory
15-
from steps.nominatim_environment import NominatimEnvironment
14+
from steps.geometry_factory import GeometryFactory # noqa: E402
15+
from steps.nominatim_environment import NominatimEnvironment # noqa: E402
1616

1717
TEST_BASE_DIR = Path(__file__, '..', '..').resolve()
1818

1919
userconfig = {
20-
'REMOVE_TEMPLATE' : False,
21-
'KEEP_TEST_DB' : False,
22-
'DB_HOST' : None,
23-
'DB_PORT' : None,
24-
'DB_USER' : None,
25-
'DB_PASS' : None,
26-
'TEMPLATE_DB' : 'test_template_nominatim',
27-
'TEST_DB' : 'test_nominatim',
28-
'API_TEST_DB' : 'test_api_nominatim',
29-
'API_TEST_FILE' : TEST_BASE_DIR / 'testdb' / 'apidb-test-data.pbf',
30-
'TOKENIZER' : None, # Test with a custom tokenizer
31-
'STYLE' : 'extratags',
20+
'REMOVE_TEMPLATE': False,
21+
'KEEP_TEST_DB': False,
22+
'DB_HOST': None,
23+
'DB_PORT': None,
24+
'DB_USER': None,
25+
'DB_PASS': None,
26+
'TEMPLATE_DB': 'test_template_nominatim',
27+
'TEST_DB': 'test_nominatim',
28+
'API_TEST_DB': 'test_api_nominatim',
29+
'API_TEST_FILE': TEST_BASE_DIR / 'testdb' / 'apidb-test-data.pbf',
30+
'TOKENIZER': None, # Test with a custom tokenizer
31+
'STYLE': 'extratags',
3232
'API_ENGINE': 'falcon'
3333
}
3434

35-
use_step_matcher("re")
35+
36+
use_step_matcher("re") # noqa: F405
37+
3638

3739
def before_all(context):
3840
# logging setup
3941
context.config.setup_logging()
4042
# set up -D options
41-
for k,v in userconfig.items():
43+
for k, v in userconfig.items():
4244
context.config.userdata.setdefault(k, v)
4345
# Nominatim test setup
4446
context.nominatim = NominatimEnvironment(context.config.userdata)
4547
context.osm = GeometryFactory()
4648

4749

4850
def before_scenario(context, scenario):
49-
if not 'SQLITE' in context.tags \
51+
if 'SQLITE' not in context.tags \
5052
and context.config.userdata['API_TEST_DB'].startswith('sqlite:'):
5153
context.scenario.skip("Not usable with Sqlite database.")
5254
elif 'DB' in context.tags:
@@ -56,6 +58,7 @@ def before_scenario(context, scenario):
5658
elif 'UNKNOWNDB' in context.tags:
5759
context.nominatim.setup_unknown_db()
5860

61+
5962
def after_scenario(context, scenario):
6063
if 'DB' in context.tags:
6164
context.nominatim.teardown_db(context)

test/bdd/steps/check_functions.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# This file is part of Nominatim. (https://nominatim.org)
44
#
5-
# Copyright (C) 2023 by the Nominatim developer community.
5+
# Copyright (C) 2025 by the Nominatim developer community.
66
# For a full list of authors see the git log.
77
"""
88
Collection of assertion functions used for the steps.
@@ -11,9 +11,10 @@
1111
import math
1212
import re
1313

14-
OSM_TYPE = {'N' : 'node', 'W' : 'way', 'R' : 'relation',
15-
'n' : 'node', 'w' : 'way', 'r' : 'relation',
16-
'node' : 'n', 'way' : 'w', 'relation' : 'r'}
14+
15+
OSM_TYPE = {'N': 'node', 'W': 'way', 'R': 'relation',
16+
'n': 'node', 'w': 'way', 'r': 'relation',
17+
'node': 'n', 'way': 'w', 'relation': 'r'}
1718

1819

1920
class OsmType:
@@ -23,11 +24,9 @@ class OsmType:
2324
def __init__(self, value):
2425
self.value = value
2526

26-
2727
def __eq__(self, other):
2828
return other == self.value or other == OSM_TYPE[self.value]
2929

30-
3130
def __str__(self):
3231
return f"{self.value} or {OSM_TYPE[self.value]}"
3332

@@ -81,7 +80,6 @@ def __str__(self):
8180
return str(self.coord)
8281

8382

84-
8583
def check_for_attributes(obj, attrs, presence='present'):
8684
""" Check that the object has the given attributes. 'attrs' is a
8785
string with a comma-separated list of attributes. If 'presence'
@@ -99,4 +97,3 @@ def _dump_json():
9997
else:
10098
assert attr in obj, \
10199
f"No attribute '{attr}'. Full response:\n{_dump_json()}"
102-

0 commit comments

Comments
 (0)