diff --git a/tests/bdd/flex/lua-index-definitions.feature b/tests/bdd/flex/lua-index-definitions.feature index da77db887..eeb92202a 100644 --- a/tests/bdd/flex/lua-index-definitions.feature +++ b/tests/bdd/flex/lua-index-definitions.feature @@ -473,9 +473,10 @@ Feature: Index definitions in Lua file }) """ When running osm2pgsql flex - Then SELECT schemaname, tablename FROM pg_catalog.pg_indexes WHERE tablename = 'mytable' AND indexdef LIKE '%USING btree (name)%' AND indexdef LIKE '%WHERE (name = lower(name))%' - | schemaname | tablename | - | public | mytable | + Then table pg_catalog.pg_indexes contains + | schemaname | tablename | indexdef@fullmatch | + | public | mytable | .*USING btree \(name\).*WHERE \(name = lower\(name\)\).* | + Scenario: Don't create id index if the configuration doesn't mention it Given the input file 'liechtenstein-2013-08-03.osm.pbf' @@ -492,10 +493,9 @@ Feature: Index definitions in Lua file }) """ When running osm2pgsql flex - Then table pg_catalog.pg_indexes has 0 rows with condition - """ - schemaname = 'public' AND tablename = 'mytable' AND indexname LIKE '%node_id%' - """ + Then table pg_catalog.pg_indexes doesn't contain + | schemaname | tablename | indexname@fullmatch | + | public | mytable | .*node_id.* | Scenario: Don't create id index if the configuration doesn't says so Given the input file 'liechtenstein-2013-08-03.osm.pbf' @@ -512,10 +512,9 @@ Feature: Index definitions in Lua file }) """ When running osm2pgsql flex - Then table pg_catalog.pg_indexes has 0 rows with condition - """ - schemaname = 'public' AND tablename = 'mytable' AND indexname LIKE '%node_id%' - """ + Then table pg_catalog.pg_indexes doesn't contain + | schemaname | tablename | indexname@fullmatch | + | public | mytable | .*node_id.* | Scenario: Always create id index if the configuration says so Given the input file 'liechtenstein-2013-08-03.osm.pbf' @@ -532,10 +531,9 @@ Feature: Index definitions in Lua file }) """ When running osm2pgsql flex - Then table pg_catalog.pg_indexes has 1 rows with condition - """ - schemaname = 'public' AND tablename = 'mytable' AND indexname LIKE '%node_id%' - """ + Then table pg_catalog.pg_indexes contains + | schemaname | tablename | indexname@fullmatch | + | public | mytable | .*node_id.* | Scenario: Create a unique id index when requested Given the input file 'liechtenstein-2013-08-03.osm.pbf' @@ -553,13 +551,12 @@ Feature: Index definitions in Lua file """ When running osm2pgsql flex Then table foo has 1562 rows - And SELECT indexdef FROM pg_indexes WHERE tablename = 'foo' - | indexdef@fullmatch | - | CREATE UNIQUE INDEX .* USING .*\(node_id\) | - And table pg_catalog.pg_index has 0 rows with condition - """ - indrelid = 'foo'::regclass and indisprimary - """ + Then table pg_catalog.pg_indexes contains + | tablename | indexdef@fullmatch | + | foo | CREATE UNIQUE INDEX .* USING .*\(node_id\) | + And SELECT count(*) FROM pg_catalog.pg_index WHERE indrelid = 'foo'::regclass and indisprimary + | count | + | 0 | Scenario: Create a primary key id index when requested Given the input file 'liechtenstein-2013-08-03.osm.pbf' @@ -577,11 +574,9 @@ Feature: Index definitions in Lua file """ When running osm2pgsql flex Then table foo has 1562 rows - And SELECT indexdef FROM pg_indexes WHERE tablename = 'foo' - | indexdef@fullmatch | - | CREATE UNIQUE INDEX .* USING .*\(node_id\) | - And table pg_catalog.pg_index has 1 row with condition - """ - indrelid = 'foo'::regclass and indisprimary - """ - + Then table pg_catalog.pg_indexes contains + | tablename | indexdef@fullmatch | + | foo | CREATE UNIQUE INDEX .* USING .*\(node_id\) | + And SELECT count(*) FROM pg_catalog.pg_index WHERE indrelid = 'foo'::regclass and indisprimary + | count | + | 1 | diff --git a/tests/bdd/flex/way-change.feature b/tests/bdd/flex/way-change.feature index 4346fec50..28c73d448 100644 --- a/tests/bdd/flex/way-change.feature +++ b/tests/bdd/flex/way-change.feature @@ -40,10 +40,9 @@ Feature: Changing ways in a flex database Then table osm2pgsql_test_t1 contains | way_id | | 11 | - And table osm2pgsql_test_t1 has rows with condition - """ - way_id = 10 - """ + And table osm2pgsql_test_t1 + | way_id | + | 10 | Then table osm2pgsql_test_t2 contains exactly | way_id | | 10 | @@ -54,9 +53,9 @@ Feature: Changing ways in a flex database | 14 | Examples: - | input | num_w10 | - | w10 v2 dV Tt2=yes Nn10,n11 | 0 | - | w10 v2 dV Tt1=yes,t2=yes Nn10,n11 | 1 | + | input | exist_w10 | + | w10 v2 dV Tt2=yes Nn10,n11 | doesn't contain | + | w10 v2 dV Tt1=yes,t2=yes Nn10,n11 | contains | Scenario Outline: change way from t2 @@ -96,19 +95,18 @@ Feature: Changing ways in a flex database Then table osm2pgsql_test_t2 contains | way_id | | 12 | - And table osm2pgsql_test_t2 has rows with condition - """ - way_id = 10 - """ + And table osm2pgsql_test_t2 + | way_id | + | 10 | Then table osm2pgsql_test_tboth contains exactly | way_id | | 13 | | 14 | Examples: - | input | num_w10 | - | w10 v2 dV Tt1=yes Nn10,n11 | 0 | - | w10 v2 dV Tt1=yes,t2=yes Nn10,n11 | 1 | + | input | exist_w10 | + | w10 v2 dV Tt1=yes Nn10,n11 | doesn't contain | + | w10 v2 dV Tt1=yes,t2=yes Nn10,n11 | contains | Scenario Outline: change way from t1 and t2 @@ -145,26 +143,24 @@ Feature: Changing ways in a flex database Then table osm2pgsql_test_t1 contains | way_id | | 11 | - And table osm2pgsql_test_t1 has rows with condition - """ - way_id = 10 - """ + And table osm2pgsql_test_t1 + | way_id | + | 10 | Then table osm2pgsql_test_t2 contains | way_id | | 12 | - And table osm2pgsql_test_t2 has rows with condition - """ - way_id = 10 - """ + And table osm2pgsql_test_t2 + | way_id | + | 10 | Then table osm2pgsql_test_tboth contains exactly | way_id | | 13 | | 14 | Examples: - | input | num_t1 | num_t2 | - | w10 v2 dV Tt1=yes Nn10,n11 | 1 | 0 | - | w10 v2 dV Tt2=yes Nn10,n11 | 0 | 1 | + | input | exist_t1 | exist_t2 | + | w10 v2 dV Tt1=yes Nn10,n11 | contains | doesn't contain | + | w10 v2 dV Tt2=yes Nn10,n11 | doesn't contain | contains | Scenario Outline: change valid geom to invalid geom diff --git a/tests/bdd/regression/forward_dependencies.feature b/tests/bdd/regression/forward_dependencies.feature index 8b48bbee2..cf96032e7 100644 --- a/tests/bdd/regression/forward_dependencies.feature +++ b/tests/bdd/regression/forward_dependencies.feature @@ -29,16 +29,15 @@ Feature: Test forward propagation of changes When running osm2pgsql pgsql with parameters | --slim | -a | --latlong | - Then table planet_osm_point has 1 row - Then table planet_osm_line has 1 row - Then table planet_osm_line has 0 rows with condition - """ - abs(ST_X(ST_StartPoint(way)) - 3.0) < 0.0001 - """ - Then table planet_osm_line has 1 row with condition - """ - abs(ST_X(ST_StartPoint(way)) - 3.1) < 0.0001 - """ - Then table planet_osm_roads has 1 row - Then table planet_osm_polygon has 1 row - + Then table planet_osm_point contains exactly + | osm_id | + | 12 | + Then table planet_osm_line contains exactly + | osm_id | round(ST_X(ST_StartPoint(way))::numeric, 1) | + | 21 | 3.1 | + Then table planet_osm_roads contains exactly + | osm_id | + | 21 | + Then table planet_osm_polygon contains exactly + | osm_id | + | 20 | diff --git a/tests/bdd/regression/import.feature b/tests/bdd/regression/import.feature index c848dc1f4..4cd4760d6 100644 --- a/tests/bdd/regression/import.feature +++ b/tests/bdd/regression/import.feature @@ -162,32 +162,15 @@ Feature: Imports of the test database | -j | | -x | - Then table planet_osm_point has 1360 rows with condition - """ - tags ? 'osm_user' AND - tags ? 'osm_version' AND - tags ? 'osm_uid' AND - tags ? 'osm_changeset' - """ - And table planet_osm_line has 3254 rows with condition - """ - tags ? 'osm_user' AND - tags ? 'osm_version' AND - tags ? 'osm_uid' AND - tags ? 'osm_changeset' - """ - And table planet_osm_roads has 375 rows with condition - """ - tags ? 'osm_user' AND - tags ? 'osm_version' AND - tags ? 'osm_uid' AND - tags ? 'osm_changeset' - """ - And table planet_osm_polygon has 4131 rows with condition - """ - tags ? 'osm_user' AND - tags ? 'osm_version' AND - tags ? 'osm_uid' AND - tags ? 'osm_changeset' - """ - + Then table planet_osm_point contains + | count(*) | every(tags ?& ARRAY['osm_user', 'osm_version', 'osm_uid', 'osm_changeset']) | + | 1360 | True | + Then table planet_osm_line contains + | count(*) | every(tags ?& ARRAY['osm_user', 'osm_version', 'osm_uid', 'osm_changeset']) | + | 3254 | True | + Then table planet_osm_roads contains + | count(*) | every(tags ?& ARRAY['osm_user', 'osm_version', 'osm_uid', 'osm_changeset']) | + | 375 | True | + Then table planet_osm_polygon contains + | count(*) | every(tags ?& ARRAY['osm_user', 'osm_version', 'osm_uid', 'osm_changeset']) | + | 4131 | True | diff --git a/tests/bdd/regression/multipolygon.feature b/tests/bdd/regression/multipolygon.feature index 1e3701219..ce4b48ef5 100644 --- a/tests/bdd/regression/multipolygon.feature +++ b/tests/bdd/regression/multipolygon.feature @@ -54,15 +54,14 @@ Feature: Import and update of multipolygon areas | 138 | 1 | | 140 | 1 | - Then table planet_osm_polygon has 0 rows with condition - """ - osm_id IN (109, 104) - """ + Then table planet_osm_polygon doesn't contain + | osm_id | + | 109 | + | 104 | - Then table planet_osm_polygon has 0 rows with condition - """ - osm_id = -33 and "natural" = 'water' - """ + Then table planet_osm_polygon doesn't contain + | osm_id | "natural" | + | -33 | water | Then SELECT osm_id, CASE WHEN '' = '-G' THEN min(ST_NumGeometries(way)) ELSE count(*) END FROM planet_osm_polygon GROUP BY osm_id | osm_id | count | @@ -118,15 +117,15 @@ Feature: Import and update of multipolygon areas | 138 | 1 | | 140 | 1 | - Then table planet_osm_polygon has 0 rows with condition - """ - osm_id IN (-25, 109, 104) - """ + Then table planet_osm_polygon doesn't contain + | osm_id | + | -25 | + | 109 | + | 104 | - Then table planet_osm_polygon has 0 rows with condition - """ - osm_id = -33 and "natural" = 'water' - """ + Then table planet_osm_polygon doesn't contain + | osm_id | "natural" | + | -33 | water | Examples: | param1 | lua | diff --git a/tests/bdd/steps/steps_db.py b/tests/bdd/steps/steps_db.py index c2ba93298..f83d085af 100644 --- a/tests/bdd/steps/steps_db.py +++ b/tests/bdd/steps/steps_db.py @@ -29,15 +29,12 @@ def delete_table(context, table): cur.execute("DROP TABLE " + table) -@then(r"table (?P.+) has (?P\d+) rows?(?P with condition)?") -def db_table_row_count(context, table, row_num, has_where): +@then(r"table (?P
.+) has (?P\d+) rows?") +def db_table_row_count(context, table, row_num): assert table_exists(context.db, table) query = sql.SQL("SELECT count(*) FROM {}").format(sql.Identifier(*table.split('.', 2))) - if has_where: - query = sql.SQL("{} WHERE {}").format(query, sql.SQL(context.text)) - actual = scalar(context.db, query) assert actual == int(row_num),\ @@ -78,6 +75,23 @@ def db_check_table_content(context, table, exact): assert not exact or not actuals,\ f"Unexpected lines in row:\n{actuals}" + +@then("table (?P
.+) doesn't contain") +def db_check_table_absence(context, table): + assert table_exists(context.db, table) + + rows = sql.SQL(', '.join(h.rsplit('@')[0] for h in context.table.headings)) + + with context.db.cursor() as cur: + cur.execute(sql.SQL("SELECT {} FROM {}") + .format(rows, sql.Identifier(*table.split('.', 2)))) + + actuals = list(DBRow(r, context.table.headings, context.geometry_factory) for r in cur) + + for row in context.table.rows: + assert not row in actuals, f"Row unexpectedly found: {row}. Full content:\n{actuals}" + + @then("(?PSELECT .*)") def db_check_sql_statement(context, query): with context.db.cursor() as cur: