[Tile-serving] [openstreetmap/osm2pgsql] Introduce behaviour-driven testing for integration tests (PR #1670)
Jochen Topf
notifications at github.com
Mon May 9 13:30:18 UTC 2022
@joto commented on this pull request.
I needed `tests/bdd/steps/__pycache__` in .gitignore. The `tests/__pycache__` can be removed I think.
The `test/bdd` directory contains the tests themselves (`flex`, `parameters`, `regression`) as well as the "infrastructure" (`environment.py`, `steps`) which I find slightly confusing. Also `parameters` is very general, maybe `command-line` or so?
There are several tests with a single input node that is just there so that *some* data is imported, it isn't checked what. Does it make sense to special case this somehow?
> +```
+
+There are ctest directives to run the tests. If you want to run the tests
+manually, for example to run single tests during development, you can
+switch to the bdd test directory and run behave directly from there:
+
+```sh
+cd osm2pgsql/tests/bdd
+behave -DBINARY=<your build directory>/osm2pgsql
+```
+
+Per default, behave assumes that the build directory is under `osm2pgsql/build`.
+If your setup works like that, you can leave out the -D parameter.
+
+To run a single test, simply add the name of the test file, followed by a
+column an the line number of the test:
column an*d*
> +behave -DBINARY=<your build directory>/osm2pgsql
+```
+
+Per default, behave assumes that the build directory is under `osm2pgsql/build`.
+If your setup works like that, you can leave out the -D parameter.
+
+To run a single test, simply add the name of the test file, followed by a
+column an the line number of the test:
+
+```sh
+behave flex/area.feature:71
+```
+
+If you need to inspect the database that a test produces, you can add
+`-DKEEP_TEST_DB` and behave won't remove the database after the test is
+finished. This makes of course only sense, when running a sinlge test.
...sin*gl*e test
> +
+ Scenario Outline:
+ Given the OSM data
+ """
+ n34 Tamenity=restaurant x77 y45.3
+ """
+
+ When running osm2pgsql pgsql with parameters
+ | -d |
+ | <connection_parameter> |
+
+ Then table planet_osm_point has 1 row
+
+ Examples:
+ | connection_parameter |
+ | {TEST_DB} |
Add spaces for consistency with other tables.
> +# behave -DBINARY=/tmp/my-builddir/osm2pgsql -DKEEP_TEST_DB
+USER_CONFIG = {
+ 'BINARY': (TEST_BASE_DIR / '..' / 'build' / 'osm2pgsql').resolve(),
+ 'TEST_DATA_DIR': TEST_BASE_DIR / 'data',
+ 'SRC_DIR': (TEST_BASE_DIR / '..').resolve(),
+ 'KEEP_TEST_DB': False,
+ 'TEST_DB': 'osm2pgsql-test',
+ 'HAVE_TABLESPACE': True,
+ 'HAVE_LUA': True,
+ 'HAVE_PROJ': True
+}
+
+use_step_matcher('re')
+
+def _connect_db(context, dbname):
+ """ Connect to the given database and return the conntection
`conn**ection`
> + Line geometry
+ (<P>,...,<P>)
+ Polygon geometry
+
+ <P> may either be a coordinate of the form '<x> <y>' or a single
+ number. In the latter case it must refer to a point in
+ a previously defined grid.
+ """
+ if geom.find(',') < 0:
+ out = "POINT({})".format(self.mk_wkt_point(geom))
+ elif geom.find('(') < 0:
+ out = "LINESTRING({})".format(self.mk_wkt_points(geom))
+ else:
+ out = "POLYGON(({}))".format(self.mk_wkt_points(geom.strip('() ')))
+
+ return "ST_SetSRID('{}'::geometry, 4326)".format(out)
Use EWKT format `SRID=4326;POLYGON((0 0,0 1,1 1,1 0,0 0))` instead of the `ST_SetSRID()`?
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/osm2pgsql/pull/1670#pullrequestreview-966081930
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/osm2pgsql/pull/1670/review/966081930 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/tile-serving/attachments/20220509/726f9006/attachment.htm>
More information about the Tile-serving
mailing list