Skip to content

Commit 775beff

Browse files
authored
Merge pull request #2434 from lonvia/bdd-remove-rows-with-condition
BDD: remove "has rows with condition" steps
2 parents 6d964b7 + 2aa48c7 commit 775beff

File tree

6 files changed

+104
-118
lines changed

6 files changed

+104
-118
lines changed

tests/bdd/flex/lua-index-definitions.feature

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,10 @@ Feature: Index definitions in Lua file
473473
})
474474
"""
475475
When running osm2pgsql flex
476-
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))%'
477-
| schemaname | tablename |
478-
| public | mytable |
476+
Then table pg_catalog.pg_indexes contains
477+
| schemaname | tablename | indexdef@fullmatch |
478+
| public | mytable | .*USING btree \(name\).*WHERE \(name = lower\(name\)\).* |
479+
479480

480481
Scenario: Don't create id index if the configuration doesn't mention it
481482
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
@@ -492,10 +493,9 @@ Feature: Index definitions in Lua file
492493
})
493494
"""
494495
When running osm2pgsql flex
495-
Then table pg_catalog.pg_indexes has 0 rows with condition
496-
"""
497-
schemaname = 'public' AND tablename = 'mytable' AND indexname LIKE '%node_id%'
498-
"""
496+
Then table pg_catalog.pg_indexes doesn't contain
497+
| schemaname | tablename | indexname@fullmatch |
498+
| public | mytable | .*node_id.* |
499499

500500
Scenario: Don't create id index if the configuration doesn't says so
501501
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
@@ -512,10 +512,9 @@ Feature: Index definitions in Lua file
512512
})
513513
"""
514514
When running osm2pgsql flex
515-
Then table pg_catalog.pg_indexes has 0 rows with condition
516-
"""
517-
schemaname = 'public' AND tablename = 'mytable' AND indexname LIKE '%node_id%'
518-
"""
515+
Then table pg_catalog.pg_indexes doesn't contain
516+
| schemaname | tablename | indexname@fullmatch |
517+
| public | mytable | .*node_id.* |
519518

520519
Scenario: Always create id index if the configuration says so
521520
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
@@ -532,10 +531,9 @@ Feature: Index definitions in Lua file
532531
})
533532
"""
534533
When running osm2pgsql flex
535-
Then table pg_catalog.pg_indexes has 1 rows with condition
536-
"""
537-
schemaname = 'public' AND tablename = 'mytable' AND indexname LIKE '%node_id%'
538-
"""
534+
Then table pg_catalog.pg_indexes contains
535+
| schemaname | tablename | indexname@fullmatch |
536+
| public | mytable | .*node_id.* |
539537

540538
Scenario: Create a unique id index when requested
541539
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
@@ -553,13 +551,12 @@ Feature: Index definitions in Lua file
553551
"""
554552
When running osm2pgsql flex
555553
Then table foo has 1562 rows
556-
And SELECT indexdef FROM pg_indexes WHERE tablename = 'foo'
557-
| indexdef@fullmatch |
558-
| CREATE UNIQUE INDEX .* USING .*\(node_id\) |
559-
And table pg_catalog.pg_index has 0 rows with condition
560-
"""
561-
indrelid = 'foo'::regclass and indisprimary
562-
"""
554+
Then table pg_catalog.pg_indexes contains
555+
| tablename | indexdef@fullmatch |
556+
| foo | CREATE UNIQUE INDEX .* USING .*\(node_id\) |
557+
And SELECT count(*) FROM pg_catalog.pg_index WHERE indrelid = 'foo'::regclass and indisprimary
558+
| count |
559+
| 0 |
563560

564561
Scenario: Create a primary key id index when requested
565562
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
@@ -577,11 +574,9 @@ Feature: Index definitions in Lua file
577574
"""
578575
When running osm2pgsql flex
579576
Then table foo has 1562 rows
580-
And SELECT indexdef FROM pg_indexes WHERE tablename = 'foo'
581-
| indexdef@fullmatch |
582-
| CREATE UNIQUE INDEX .* USING .*\(node_id\) |
583-
And table pg_catalog.pg_index has 1 row with condition
584-
"""
585-
indrelid = 'foo'::regclass and indisprimary
586-
"""
587-
577+
Then table pg_catalog.pg_indexes contains
578+
| tablename | indexdef@fullmatch |
579+
| foo | CREATE UNIQUE INDEX .* USING .*\(node_id\) |
580+
And SELECT count(*) FROM pg_catalog.pg_index WHERE indrelid = 'foo'::regclass and indisprimary
581+
| count |
582+
| 1 |

tests/bdd/flex/way-change.feature

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ Feature: Changing ways in a flex database
4040
Then table osm2pgsql_test_t1 contains
4141
| way_id |
4242
| 11 |
43-
And table osm2pgsql_test_t1 has <num_w10> rows with condition
44-
"""
45-
way_id = 10
46-
"""
43+
And table osm2pgsql_test_t1 <exist_w10>
44+
| way_id |
45+
| 10 |
4746
Then table osm2pgsql_test_t2 contains exactly
4847
| way_id |
4948
| 10 |
@@ -54,9 +53,9 @@ Feature: Changing ways in a flex database
5453
| 14 |
5554

5655
Examples:
57-
| input | num_w10 |
58-
| w10 v2 dV Tt2=yes Nn10,n11 | 0 |
59-
| w10 v2 dV Tt1=yes,t2=yes Nn10,n11 | 1 |
56+
| input | exist_w10 |
57+
| w10 v2 dV Tt2=yes Nn10,n11 | doesn't contain |
58+
| w10 v2 dV Tt1=yes,t2=yes Nn10,n11 | contains |
6059

6160

6261
Scenario Outline: change way from t2
@@ -96,19 +95,18 @@ Feature: Changing ways in a flex database
9695
Then table osm2pgsql_test_t2 contains
9796
| way_id |
9897
| 12 |
99-
And table osm2pgsql_test_t2 has <num_w10> rows with condition
100-
"""
101-
way_id = 10
102-
"""
98+
And table osm2pgsql_test_t2 <exist_w10>
99+
| way_id |
100+
| 10 |
103101
Then table osm2pgsql_test_tboth contains exactly
104102
| way_id |
105103
| 13 |
106104
| 14 |
107105

108106
Examples:
109-
| input | num_w10 |
110-
| w10 v2 dV Tt1=yes Nn10,n11 | 0 |
111-
| w10 v2 dV Tt1=yes,t2=yes Nn10,n11 | 1 |
107+
| input | exist_w10 |
108+
| w10 v2 dV Tt1=yes Nn10,n11 | doesn't contain |
109+
| w10 v2 dV Tt1=yes,t2=yes Nn10,n11 | contains |
112110

113111

114112
Scenario Outline: change way from t1 and t2
@@ -145,26 +143,24 @@ Feature: Changing ways in a flex database
145143
Then table osm2pgsql_test_t1 contains
146144
| way_id |
147145
| 11 |
148-
And table osm2pgsql_test_t1 has <num_t1> rows with condition
149-
"""
150-
way_id = 10
151-
"""
146+
And table osm2pgsql_test_t1 <exist_t1>
147+
| way_id |
148+
| 10 |
152149
Then table osm2pgsql_test_t2 contains
153150
| way_id |
154151
| 12 |
155-
And table osm2pgsql_test_t2 has <num_t2> rows with condition
156-
"""
157-
way_id = 10
158-
"""
152+
And table osm2pgsql_test_t2 <exist_t2>
153+
| way_id |
154+
| 10 |
159155
Then table osm2pgsql_test_tboth contains exactly
160156
| way_id |
161157
| 13 |
162158
| 14 |
163159

164160
Examples:
165-
| input | num_t1 | num_t2 |
166-
| w10 v2 dV Tt1=yes Nn10,n11 | 1 | 0 |
167-
| w10 v2 dV Tt2=yes Nn10,n11 | 0 | 1 |
161+
| input | exist_t1 | exist_t2 |
162+
| w10 v2 dV Tt1=yes Nn10,n11 | contains | doesn't contain |
163+
| w10 v2 dV Tt2=yes Nn10,n11 | doesn't contain | contains |
168164

169165

170166
Scenario Outline: change valid geom to invalid geom

tests/bdd/regression/forward_dependencies.feature

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@ Feature: Test forward propagation of changes
2929
When running osm2pgsql pgsql with parameters
3030
| --slim | -a | --latlong |
3131

32-
Then table planet_osm_point has 1 row
33-
Then table planet_osm_line has 1 row
34-
Then table planet_osm_line has 0 rows with condition
35-
"""
36-
abs(ST_X(ST_StartPoint(way)) - 3.0) < 0.0001
37-
"""
38-
Then table planet_osm_line has 1 row with condition
39-
"""
40-
abs(ST_X(ST_StartPoint(way)) - 3.1) < 0.0001
41-
"""
42-
Then table planet_osm_roads has 1 row
43-
Then table planet_osm_polygon has 1 row
44-
32+
Then table planet_osm_point contains exactly
33+
| osm_id |
34+
| 12 |
35+
Then table planet_osm_line contains exactly
36+
| osm_id | round(ST_X(ST_StartPoint(way))::numeric, 1) |
37+
| 21 | 3.1 |
38+
Then table planet_osm_roads contains exactly
39+
| osm_id |
40+
| 21 |
41+
Then table planet_osm_polygon contains exactly
42+
| osm_id |
43+
| 20 |

tests/bdd/regression/import.feature

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -162,32 +162,15 @@ Feature: Imports of the test database
162162
| -j |
163163
| -x |
164164

165-
Then table planet_osm_point has 1360 rows with condition
166-
"""
167-
tags ? 'osm_user' AND
168-
tags ? 'osm_version' AND
169-
tags ? 'osm_uid' AND
170-
tags ? 'osm_changeset'
171-
"""
172-
And table planet_osm_line has 3254 rows with condition
173-
"""
174-
tags ? 'osm_user' AND
175-
tags ? 'osm_version' AND
176-
tags ? 'osm_uid' AND
177-
tags ? 'osm_changeset'
178-
"""
179-
And table planet_osm_roads has 375 rows with condition
180-
"""
181-
tags ? 'osm_user' AND
182-
tags ? 'osm_version' AND
183-
tags ? 'osm_uid' AND
184-
tags ? 'osm_changeset'
185-
"""
186-
And table planet_osm_polygon has 4131 rows with condition
187-
"""
188-
tags ? 'osm_user' AND
189-
tags ? 'osm_version' AND
190-
tags ? 'osm_uid' AND
191-
tags ? 'osm_changeset'
192-
"""
193-
165+
Then table planet_osm_point contains
166+
| count(*) | every(tags ?& ARRAY['osm_user', 'osm_version', 'osm_uid', 'osm_changeset']) |
167+
| 1360 | True |
168+
Then table planet_osm_line contains
169+
| count(*) | every(tags ?& ARRAY['osm_user', 'osm_version', 'osm_uid', 'osm_changeset']) |
170+
| 3254 | True |
171+
Then table planet_osm_roads contains
172+
| count(*) | every(tags ?& ARRAY['osm_user', 'osm_version', 'osm_uid', 'osm_changeset']) |
173+
| 375 | True |
174+
Then table planet_osm_polygon contains
175+
| count(*) | every(tags ?& ARRAY['osm_user', 'osm_version', 'osm_uid', 'osm_changeset']) |
176+
| 4131 | True |

tests/bdd/regression/multipolygon.feature

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,14 @@ Feature: Import and update of multipolygon areas
5454
| 138 | 1 |
5555
| 140 | 1 |
5656

57-
Then table planet_osm_polygon has 0 rows with condition
58-
"""
59-
osm_id IN (109, 104)
60-
"""
57+
Then table planet_osm_polygon doesn't contain
58+
| osm_id |
59+
| 109 |
60+
| 104 |
6161

62-
Then table planet_osm_polygon has 0 rows with condition
63-
"""
64-
osm_id = -33 and "natural" = 'water'
65-
"""
62+
Then table planet_osm_polygon doesn't contain
63+
| osm_id | "natural" |
64+
| -33 | water |
6665

6766
Then SELECT osm_id, CASE WHEN '<param1>' = '-G' THEN min(ST_NumGeometries(way)) ELSE count(*) END FROM planet_osm_polygon GROUP BY osm_id
6867
| osm_id | count |
@@ -118,15 +117,15 @@ Feature: Import and update of multipolygon areas
118117
| 138 | 1 |
119118
| 140 | 1 |
120119

121-
Then table planet_osm_polygon has 0 rows with condition
122-
"""
123-
osm_id IN (-25, 109, 104)
124-
"""
120+
Then table planet_osm_polygon doesn't contain
121+
| osm_id |
122+
| -25 |
123+
| 109 |
124+
| 104 |
125125

126-
Then table planet_osm_polygon has 0 rows with condition
127-
"""
128-
osm_id = -33 and "natural" = 'water'
129-
"""
126+
Then table planet_osm_polygon doesn't contain
127+
| osm_id | "natural" |
128+
| -33 | water |
130129

131130
Examples:
132131
| param1 | lua |

tests/bdd/steps/steps_db.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,12 @@ def delete_table(context, table):
2929
cur.execute("DROP TABLE " + table)
3030

3131

32-
@then(r"table (?P<table>.+) has (?P<row_num>\d+) rows?(?P<has_where> with condition)?")
33-
def db_table_row_count(context, table, row_num, has_where):
32+
@then(r"table (?P<table>.+) has (?P<row_num>\d+) rows?")
33+
def db_table_row_count(context, table, row_num):
3434
assert table_exists(context.db, table)
3535

3636
query = sql.SQL("SELECT count(*) FROM {}").format(sql.Identifier(*table.split('.', 2)))
3737

38-
if has_where:
39-
query = sql.SQL("{} WHERE {}").format(query, sql.SQL(context.text))
40-
4138
actual = scalar(context.db, query)
4239

4340
assert actual == int(row_num),\
@@ -78,6 +75,23 @@ def db_check_table_content(context, table, exact):
7875
assert not exact or not actuals,\
7976
f"Unexpected lines in row:\n{actuals}"
8077

78+
79+
@then("table (?P<table>.+) doesn't contain")
80+
def db_check_table_absence(context, table):
81+
assert table_exists(context.db, table)
82+
83+
rows = sql.SQL(', '.join(h.rsplit('@')[0] for h in context.table.headings))
84+
85+
with context.db.cursor() as cur:
86+
cur.execute(sql.SQL("SELECT {} FROM {}")
87+
.format(rows, sql.Identifier(*table.split('.', 2))))
88+
89+
actuals = list(DBRow(r, context.table.headings, context.geometry_factory) for r in cur)
90+
91+
for row in context.table.rows:
92+
assert not row in actuals, f"Row unexpectedly found: {row}. Full content:\n{actuals}"
93+
94+
8195
@then("(?P<query>SELECT .*)")
8296
def db_check_sql_statement(context, query):
8397
with context.db.cursor() as cur:

0 commit comments

Comments
 (0)