Skip to content

Commit 69739e8

Browse files
committed
bdd: replace remaining SELECT steps with SQL templates
1 parent 7d69ce8 commit 69739e8

File tree

3 files changed

+49
-20
lines changed

3 files changed

+49
-20
lines changed

tests/bdd/flex/delete-callbacks.feature

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,29 @@ 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,
33+
count(*),
34+
sum(extra) AS sum_extra,
35+
sum(osm_id) AS sum_osm_id
36+
FROM change
37+
GROUP BY osm_type
38+
"""
39+
3040
Scenario: Delete callbacks are called
3141
When running osm2pgsql flex with parameters
3242
| --slim | -a |
33-
34-
Then SELECT osm_type, count(*), sum(extra) FROM change GROUP BY osm_type
35-
| osm_type | count | sum |
36-
| N | 16773 | 16779 |
37-
| W | 4 | 9 |
38-
| R | 1 | 3 |
43+
Then statement grouped_counts returns exactly
44+
| osm_type | count | sum_extra |
45+
| N | 16773 | 16779 |
46+
| W | 4 | 9 |
47+
| R | 1 | 3 |
3948

4049
When running osm2pgsql flex with parameters
4150
| --slim | -a |
42-
43-
Then SELECT osm_type, count(*), sum(osm_id) FROM change GROUP BY osm_type
44-
| osm_type | count | sum |
51+
Then statement grouped_counts returns exactly
52+
| osm_type | count | sum_osm_id |
4553
| N | 16773 | 37856781001834 |
4654
| W | 4 | 350933407 |
4755
| R | 1 | 2871571 |
@@ -72,8 +80,8 @@ Feature: Test for delete callbacks
7280
"""
7381
When running osm2pgsql flex with parameters
7482
| --slim | -a |
75-
Then SELECT osm_type, count(*), sum(extra) FROM change GROUP BY osm_type
76-
| osm_type | count | sum |
83+
Then statement grouped_counts returns exactly
84+
| osm_type | count | sum_extra |
7785
| N | 16773 | 16773 |
7886
| W | 4 | 4 |
7987
| R | 1 | 1 |
@@ -105,8 +113,8 @@ Feature: Test for delete callbacks
105113
"""
106114
When running osm2pgsql flex with parameters
107115
| --slim | -a |
108-
Then SELECT osm_type, count(*), sum(extra) FROM change GROUP BY osm_type
109-
| osm_type | count | sum |
116+
Then statement grouped_counts returns exactly
117+
| osm_type | count | sum_extra |
110118
| N | 16773 | 16773|
111119
| W | 4 | 4|
112120
| R | 1 | 1|

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)