Skip to content

Commit

Permalink
Merge pull request #3493 from lonvia/clean-up-bdd-tests
Browse files Browse the repository at this point in the history
Various cleanups of BDD tests
  • Loading branch information
lonvia authored Jul 31, 2024
2 parents 67462e0 + 2914284 commit a4d7cdd
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 114 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ jobs:

- name: BDD tests
run: |
python3 -m behave -DREMOVE_TEMPLATE=1 -DBUILDDIR=$GITHUB_WORKSPACE/build --format=progress3
export PATH=$GITHUB_WORKSPACE/build/osm2pgsql:$PATH
python3 -m behave -DREMOVE_TEMPLATE=1 --format=progress3
working-directory: Nominatim/test/bdd

- name: Install mypy and typechecking info
Expand Down Expand Up @@ -170,7 +171,8 @@ jobs:

- name: BDD tests (legacy tokenizer)
run: |
python3 -m behave -DREMOVE_TEMPLATE=1 -DBUILDDIR=$GITHUB_WORKSPACE/build -DAPI_ENGINE=php -DTOKENIZER=legacy --format=progress3
export PATH=$GITHUB_WORKSPACE/build/osm2pgsql:$PATH
python3 -m behave -DREMOVE_TEMPLATE=1 -DSERVER_MODULE_PATH=$GITHUB_WORKSPACE/build/module -DAPI_ENGINE=php -DTOKENIZER=legacy --format=progress3
working-directory: Nominatim/test/bdd


Expand Down Expand Up @@ -217,7 +219,8 @@ jobs:

- name: BDD tests (php)
run: |
python3 -m behave -DREMOVE_TEMPLATE=1 -DBUILDDIR=$GITHUB_WORKSPACE/build -DAPI_ENGINE=php --format=progress3
export PATH=$GITHUB_WORKSPACE/build/osm2pgsql:$PATH
python3 -m behave -DREMOVE_TEMPLATE=1 -DAPI_ENGINE=php --format=progress3
working-directory: Nominatim/test/bdd


Expand Down
4 changes: 4 additions & 0 deletions docs/develop/Development-Environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ The documentation is built with mkdocs:
* [mkdocstrings](https://mkdocstrings.github.io/) >= 0.25
* [mkdocs-material](https://squidfunk.github.io/mkdocs-material/)

Please be aware that tests always run against the globally installed
osm2pgsql, so you need to have this set up. If you want to test against
the vendored version of osm2pgsql, you need to set the PATH accordingly.

### Installing prerequisites on Ubuntu/Debian

The Python tools should always be run with the most recent version.
Expand Down
20 changes: 1 addition & 19 deletions docs/develop/Testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ To run the functional tests, do

The tests can be configured with a set of environment variables (`behave -D key=val`):

* `BUILDDIR` - build directory of Nominatim installation to test
* `TEMPLATE_DB` - name of template database used as a skeleton for
the test databases (db tests)
* `TEST_DB` - name of test database (db tests)
Expand All @@ -91,7 +90,7 @@ The tests can be configured with a set of environment variables (`behave -D key=
* `DB_USER` - (optional) username of database login
* `DB_PASS` - (optional) password for database login
* `SERVER_MODULE_PATH` - (optional) path on the Postgres server to Nominatim
module shared library file
module shared library file (only needed for legacy tokenizer)
* `REMOVE_TEMPLATE` - if true, the template and API database will not be reused
during the next run. Reusing the base templates speeds
up tests considerably but might lead to outdated errors
Expand Down Expand Up @@ -122,23 +121,6 @@ and compromises the following data:
API tests should only be testing the functionality of the website PHP code.
Most tests should be formulated as BDD DB creation tests (see below) instead.

#### Code Coverage (PHP engine only)

The API tests also support code coverage tests. You need to install
[PHP_CodeCoverage](https://github.com/sebastianbergmann/php-code-coverage).
On Debian/Ubuntu run:

apt-get install php-codecoverage php-xdebug

Then run the API tests as follows:

behave api -DPHPCOV=<coverage output dir>

The output directory must be an absolute path. To generate reports, you can use
the [phpcov](https://github.com/sebastianbergmann/phpcov) tool:

phpcov merge --html=<report output dir> <coverage output dir>

### DB Creation Tests (`test/bdd/db`)

These tests check the import and update of the Nominatim database. They do not
Expand Down
7 changes: 6 additions & 1 deletion src/nominatim_api/search/db_search_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,12 @@ def build_housenumber_search(self, sdata: dbf.SearchData, hnrs: List[Token],
expected_count = sum(t.count for t in hnrs)

partials = {t.token: t.addr_count for trange in address
for t in self.query.get_partials_list(trange)}
for t in self.query.get_partials_list(trange)
if t.is_indexed}

if not partials:
# can happen when none of the partials is indexed
return

if expected_count < 8000:
sdata.lookups.append(dbf.FieldLookup('nameaddress_vector',
Expand Down
7 changes: 4 additions & 3 deletions src/nominatim_api/search/legacy_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def make_token(self, row: SaRow) -> Tuple[LegacyToken, qmod.TokenType]:
lookup_word = row.word_token[1:]
elif rowclass == 'place' and row.type == 'postcode':
ttype = qmod.TokenType.POSTCODE
lookup_word = row.word_token[1:]
lookup_word = row.word
else:
ttype = qmod.TokenType.NEAR_ITEM if row.operator in ('in', 'near')\
else qmod.TokenType.QUALIFIER
Expand Down Expand Up @@ -253,13 +253,14 @@ def rerank_tokens(self, query: qmod.QueryStruct) -> None:


def _dump_word_tokens(query: qmod.QueryStruct) -> Iterator[List[Any]]:
yield ['type', 'token', 'word_token', 'lookup_word', 'penalty', 'count', 'info']
yield ['type', 'token', 'word_token', 'lookup_word', 'penalty', 'count', 'info', 'indexed']
for node in query.nodes:
for tlist in node.starting:
for token in tlist.tokens:
t = cast(LegacyToken, token)
yield [tlist.ttype.name, t.token, t.word_token or '',
t.lookup_word or '', t.penalty, t.count, t.info]
t.lookup_word or '', t.penalty, t.count, t.info,
'Y' if t.is_indexed else 'N']


async def create_query_analyzer(conn: SearchConnection) -> AbstractQueryAnalyzer:
Expand Down
4 changes: 4 additions & 0 deletions test/bdd/api/search/postcode.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
Feature: Searches with postcodes
Various searches involving postcodes

@v1-api-php-only
Scenario: US 5+4 ZIP codes are shortened to 5 ZIP codes if not found
When sending json search query "36067 1111, us" with address
Then result addresses contain
| postcode |
| 36067 |
And results contain
| type |
| postcode |

Scenario: Postcode search with address
When sending json search query "9486, mauren"
Expand Down
1 change: 1 addition & 0 deletions test/bdd/db/query/postcodes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Feature: Querying fo postcode variants
| AD675 |


@fail-legacy
Scenario: Different postcodes with the same normalization can both be found
Given the places
| osm | class | type | addr+postcode | addr+housenumber | geometry |
Expand Down
23 changes: 23 additions & 0 deletions test/bdd/db/query/reverse.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@DB
Feature: Reverse searches
Test results of reverse queries

@v1-api-python-only
Scenario: POI in POI area
Given the 0.0001 grid with origin 1,1
| 1 | | | | | | | | 2 |
| | 9 | | | | | | | |
| 4 | | | | | | | | 3 |
And the places
| osm | class | type | geometry |
| W1 | aeroway | terminal | (1,2,3,4,1) |
| N1 | amenity | restaurant | 9 |
When importing
And sending v1/reverse at 1.0001,1.0001
Then results contain
| osm |
| N1 |
When sending v1/reverse at 1.0003,1.0001
Then results contain
| osm |
| W1 |
1 change: 1 addition & 0 deletions test/bdd/db/query/search_simple.feature
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Feature: Searching of simple objects
| W1 |


@fail-legacy
Scenario Outline: Special cased american states will be found
Given the grid
| 1 | | 2 |
Expand Down
16 changes: 8 additions & 8 deletions test/bdd/db/update/linked_places.feature
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,17 @@ Feature: Updates of linked places
| R1 | boundary | administrative | rel | 8 | (10,11,12,13,10) |
And the places
| osm | class | type | name+name:de |
| N3 | place | city | pnt |
| N3 | place | city | greeny |
And the relations
| id | members |
| 1 | N3:label |
When importing
Then placex contains
| object | linked_place_id | name+_place_name:de |
| R1 | - | pnt |
| R1 | - | greeny |
And placex contains
| object | linked_place_id | name+name:de |
| N3 | R1 | pnt |
| N3 | R1 | greeny |
When updating places
| osm | class | type | name+name:de |
| N3 | place | city | newname |
Expand All @@ -188,18 +188,18 @@ Feature: Updates of linked places
| R1 | boundary | administrative | rel | 8 | (10,11,12,13,10) |
And the places
| osm | class | type | name |
| N3 | place | city | pnt |
| N3 | place | city | greeny |
And the relations
| id | members |
| 1 | N3:label |
When importing
Then placex contains
| object | linked_place_id | name+_place_name | name+name |
| R1 | - | pnt | rel |
| R1 | - | greeny | rel |
And placex contains
| object | linked_place_id | name+name |
| N3 | R1 | pnt |
When sending search query "pnt"
| N3 | R1 | greeny |
When sending search query "greeny"
Then results contain
| osm |
| R1 |
Expand All @@ -212,7 +212,7 @@ Feature: Updates of linked places
And placex contains
| object | linked_place_id | name+_place_name:de | name+name |
| R1 | - | depnt | rel |
When sending search query "pnt"
When sending search query "greeny"
Then exactly 0 results are returned

Scenario: Updating linkee extratags keeps linker's extratags
Expand Down
11 changes: 6 additions & 5 deletions test/bdd/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
from pathlib import Path
import sys

from behave import *

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

from steps.geometry_factory import GeometryFactory
from steps.nominatim_environment import NominatimEnvironment

TEST_BASE_DIR = Path(__file__) / '..' / '..'
TEST_BASE_DIR = Path(__file__, '..', '..').resolve()

userconfig = {
'BUILDDIR' : (TEST_BASE_DIR / '..' / 'build').resolve(),
'REMOVE_TEMPLATE' : False,
'KEEP_TEST_DB' : False,
'DB_HOST' : None,
Expand All @@ -24,12 +26,11 @@
'TEMPLATE_DB' : 'test_template_nominatim',
'TEST_DB' : 'test_nominatim',
'API_TEST_DB' : 'test_api_nominatim',
'API_TEST_FILE' : (TEST_BASE_DIR / 'testdb' / 'apidb-test-data.pbf').resolve(),
'API_TEST_FILE' : TEST_BASE_DIR / 'testdb' / 'apidb-test-data.pbf',
'SERVER_MODULE_PATH' : None,
'TOKENIZER' : None, # Test with a custom tokenizer
'STYLE' : 'extratags',
'API_ENGINE': 'falcon',
'PHPCOV' : False, # set to output directory to enable code coverage
'API_ENGINE': 'falcon'
}

use_step_matcher("re")
Expand Down
40 changes: 0 additions & 40 deletions test/bdd/steps/cgi-with-coverage.php

This file was deleted.

Loading

0 comments on commit a4d7cdd

Please sign in to comment.