Skip to content

Commit 40669ef

Browse files
committed
bdd: replace remaining SELECT steps with SQL templates
1 parent e8fe65f commit 40669ef

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

tests/bdd/flex/delete-callbacks.feature

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ Feature: Test for delete callbacks
2727

2828
Given the input file '008-ch.osc.gz'
2929

30+
Given the SQL statement grouped_counts
31+
"""
32+
SELECT osm_type, count(*), sum(extra) FROM change GROUP BY osm_type
33+
"""
34+
3035
Scenario: Delete callbacks are called
3136
When running osm2pgsql flex with parameters
3237
| --slim | -a |
3338

34-
Then SELECT osm_type, count(*), sum(extra) FROM change GROUP BY osm_type
39+
Then statement grouped_counts returns exactly
3540
| osm_type | count | sum |
3641
| N | 16773 | 16779 |
3742
| W | 4 | 9 |
@@ -40,11 +45,11 @@ Feature: Test for delete callbacks
4045
When running osm2pgsql flex with parameters
4146
| --slim | -a |
4247

43-
Then SELECT osm_type, count(*), sum(osm_id) FROM change GROUP BY osm_type
48+
Then statement grouped_counts returns exactly
4449
| osm_type | count | sum |
45-
| N | 16773 | 37856781001834 |
46-
| W | 4 | 350933407 |
47-
| R | 1 | 2871571 |
50+
| N | 16773 | 16779 |
51+
| W | 4 | 9 |
52+
| R | 1 | 3 |
4853

4954
Scenario: No object payload is available
5055
Given the lua style
@@ -72,7 +77,7 @@ Feature: Test for delete callbacks
7277
"""
7378
When running osm2pgsql flex with parameters
7479
| --slim | -a |
75-
Then SELECT osm_type, count(*), sum(extra) FROM change GROUP BY osm_type
80+
Then statement grouped_counts returns exactly
7681
| osm_type | count | sum |
7782
| N | 16773 | 16773 |
7883
| W | 4 | 4 |
@@ -105,7 +110,7 @@ Feature: Test for delete callbacks
105110
"""
106111
When running osm2pgsql flex with parameters
107112
| --slim | -a |
108-
Then SELECT osm_type, count(*), sum(extra) FROM change GROUP BY osm_type
113+
Then statement grouped_counts returns exactly
109114
| osm_type | count | sum |
110115
| N | 16773 | 16773|
111116
| W | 4 | 4|

tests/bdd/regression/multipolygon.feature

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ Feature: Import and update of multipolygon areas
33
Background:
44
Given the input file 'test_multipolygon.osm'
55

6+
Given the SQL statement grouped_polygons
7+
"""
8+
SELECT osm_id,
9+
count(*) as count,
10+
round(sum(ST_Area(way))) as area,
11+
round(sum(way_area::numeric)) as way_area
12+
FROM planet_osm_polygon
13+
GROUP BY osm_id
14+
"""
15+
616
Scenario Outline: Import and update slim
717
Given <lua> lua tagtransform
818
When running osm2pgsql pgsql with parameters
@@ -35,15 +45,15 @@ Feature: Import and update of multipolygon areas
3545
| osm_id | landuse | name | ST_NumInteriorRing(way) |
3646
| -3 | residential | Name_rel11 | 2 |
3747

38-
Then SELECT osm_id, round(sum(ST_Area(way))), round(sum(way_area::numeric)) FROM planet_osm_polygon GROUP BY osm_id
48+
Then statement grouped_polygons returns
3949
| osm_id | area | way_area |
4050
| -13 | 17581 | 17581 |
4151
| -7 | 16169 | 16169 |
4252
| -29 | 68494 | 68494 |
4353
| -39 | 10377 | 10378 |
4454
| -40 | 12397 | 12397 |
4555

46-
Then SELECT osm_id, count(*) FROM planet_osm_polygon GROUP BY osm_id
56+
Then statement grouped_polygons returns
4757
| osm_id | count |
4858
| -25 | 1 |
4959
| 113 | 1 |
@@ -63,7 +73,15 @@ Feature: Import and update of multipolygon areas
6373
| osm_id | "natural" |
6474
| -33 | water |
6575

66-
Then SELECT osm_id, CASE WHEN '<param1>' = '-G' THEN min(ST_NumGeometries(way)) ELSE count(*) END FROM planet_osm_polygon GROUP BY osm_id
76+
Given the SQL statement geometries_polygon
77+
"""
78+
SELECT osm_id,
79+
CASE WHEN '<param1>' = '-G' THEN min(ST_NumGeometries(way))
80+
ELSE count(*) END as count
81+
FROM planet_osm_polygon
82+
GROUP BY osm_id
83+
"""
84+
Then statement geometries_polygon returns
6785
| osm_id | count |
6886
| -13 | 2 |
6987
| -7 | 2 |
@@ -99,15 +117,15 @@ Feature: Import and update of multipolygon areas
99117
| osm_id | landuse | name | ST_NumInteriorRing(way) |
100118
| -3 | residential | Name_rel11 | 2 |
101119

102-
Then SELECT osm_id, round(sum(ST_Area(way))), round(sum(way_area::numeric)) FROM planet_osm_polygon GROUP BY osm_id
120+
Then statement grouped_polygons returns
103121
| osm_id | area | way_area |
104122
| -13 | 17581 | 17581 |
105123
| -7 | 16169 | 16169 |
106124
| -29 | 29155 | 29155 |
107125
| -39 | 10377 | 10378 |
108126
| -40 | 12397 | 12397 |
109127

110-
Then SELECT osm_id, count(*) FROM planet_osm_polygon GROUP BY osm_id
128+
Then statement grouped_polygons returns
111129
| osm_id | count |
112130
| 113 | 1 |
113131
| 118 | 1 |

tests/bdd/steps/steps_db.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,12 @@ def db_define_sql_statement(context, sql):
9898

9999
@then("statement (?P<stmt>.+) returns(?P<exact> exactly)?")
100100
def db_check_sql_statement(context, stmt, exact):
101+
assert stmt in context.sql_statements
102+
rows = sql.SQL(', '.join(h.rsplit('@')[0] for h in context.table.headings))
103+
101104
with context.db.cursor() as cur:
102-
assert stmt in context.sql_statements
103-
cur.execute(context.sql_statements[stmt])
105+
cur.execute(sql.SQL("SELECT {} FROM ({}) _sql_statement")
106+
.format(rows, sql.SQL(context.sql_statements[stmt])))
104107

105108
actuals = list(DBRow(r, context.table.headings, context.geometry_factory) for r in cur)
106109

0 commit comments

Comments
 (0)