Skip to content

Commit d19263d

Browse files
authored
Merge pull request #2431 from lonvia/bdd-sum
BDD tests: replace sum step with table check with aggregate
2 parents 76d90cc + 64b4fc3 commit d19263d

File tree

2 files changed

+48
-58
lines changed

2 files changed

+48
-58
lines changed

tests/bdd/regression/import.feature

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ Feature: Imports of the test database
77
When running osm2pgsql pgsql
88

99
Then table planet_osm_point has 1342 rows
10-
And table planet_osm_line has 3231 rows
11-
And table planet_osm_roads has 375 rows
12-
And table planet_osm_polygon has 4130 rows
13-
14-
Then the sum of 'cast(ST_Area(way) as numeric)' in table planet_osm_polygon is 1247245186
15-
And the sum of 'cast(way_area as numeric)' in table planet_osm_polygon is 1247245413
16-
And the sum of 'ST_Length(way)' in table planet_osm_line is 4211350
17-
And the sum of 'ST_Length(way)' in table planet_osm_roads is 2032023
10+
And table planet_osm_polygon contains
11+
| count(*) | round(sum(ST_Area(way))) | round(sum(way_area)) |
12+
| 4130 | 1247245186 | 1247245413 |
13+
And table planet_osm_line contains
14+
| count(*) | round(sum(ST_Length(way))) |
15+
| 3231 | 4211350 |
16+
And table planet_osm_roads contains
17+
| count(*) | round(sum(ST_Length(way))) |
18+
| 375 | 2032023 |
1819

1920
And there are no tables planet_osm_nodes, planet_osm_ways, planet_osm_rels
2021

@@ -37,14 +38,15 @@ Feature: Imports of the test database
3738
| <drop> |
3839

3940
Then table planet_osm_point has 1342 rows
40-
And table planet_osm_line has 3231 rows
41-
And table planet_osm_roads has 375 rows
42-
And table planet_osm_polygon has 4130 rows
43-
44-
Then the sum of 'cast(ST_Area(way) as numeric)' in table planet_osm_polygon is 1247245186
45-
And the sum of 'cast(way_area as numeric)' in table planet_osm_polygon is 1247245413
46-
And the sum of 'ST_Length(way)' in table planet_osm_line is 4211350
47-
And the sum of 'ST_Length(way)' in table planet_osm_roads is 2032023
41+
And table planet_osm_polygon contains
42+
| count(*) | round(sum(ST_Area(way))) | round(sum(way_area)) |
43+
| 4130 | 1247245186 | 1247245413 |
44+
And table planet_osm_line contains
45+
| count(*) | round(sum(ST_Length(way))) |
46+
| 3231 | 4211350 |
47+
And table planet_osm_roads contains
48+
| count(*) | round(sum(ST_Length(way))) |
49+
| 375 | 2032023 |
4850

4951
And there are <have table> planet_osm_nodes, planet_osm_ways, planet_osm_rels
5052

@@ -61,14 +63,15 @@ Feature: Imports of the test database
6163
| <slim> |
6264

6365
Then table planet_osm_point has 1342 rows
64-
And table planet_osm_line has 3231 rows
65-
And table planet_osm_roads has 375 rows
66-
And table planet_osm_polygon has 4136 rows
67-
68-
Then the sum of 'cast(ST_Area(way) as numeric)' in table planet_osm_polygon is 1272140688
69-
And the sum of 'cast(way_area as numeric)' in table planet_osm_polygon is 1272140891
70-
And the sum of 'ST_Length(way)' in table planet_osm_line is 4211350
71-
And the sum of 'ST_Length(way)' in table planet_osm_roads is 2032023
66+
And table planet_osm_polygon contains
67+
| count(*) | round(sum(ST_Area(way))) | round(sum(way_area)) |
68+
| 4136 | 1272140688 | 1272140891 |
69+
And table planet_osm_line contains
70+
| count(*) | round(sum(ST_Length(way))) |
71+
| 3231 | 4211350 |
72+
And table planet_osm_roads contains
73+
| count(*) | round(sum(ST_Length(way))) |
74+
| 375 | 2032023 |
7275

7376
And there are <have table> planet_osm_nodes, planet_osm_ways, planet_osm_rels
7477

@@ -102,15 +105,18 @@ Feature: Imports of the test database
102105
When running osm2pgsql pgsql with parameters
103106
| --slim | -j |
104107

105-
Then table planet_osm_point has 1360 rows
106-
And table planet_osm_line has 3254 rows
107-
And table planet_osm_roads has 375 rows
108-
And table planet_osm_polygon has 4131 rows
109-
110-
Then the sum of 'array_length(akeys(tags),1)' in table planet_osm_point is 4228
111-
And the sum of 'array_length(akeys(tags),1)' in table planet_osm_roads is 2317
112-
And the sum of 'array_length(akeys(tags),1)' in table planet_osm_line is 10387
113-
And the sum of 'array_length(akeys(tags),1)' in table planet_osm_polygon is 9538
108+
Then table planet_osm_point contains
109+
| count(*) | sum(array_length(akeys(tags), 1)) |
110+
| 1360 | 4228 |
111+
Then table planet_osm_line contains
112+
| count(*) | sum(array_length(akeys(tags), 1)) |
113+
| 3254 | 10387 |
114+
Then table planet_osm_roads contains
115+
| count(*) | sum(array_length(akeys(tags), 1)) |
116+
| 375 | 2317 |
117+
Then table planet_osm_polygon contains
118+
| count(*) | sum(array_length(akeys(tags), 1)) |
119+
| 4131 | 9538 |
114120

115121

116122
Scenario Outline: Import slim with various tweaks
@@ -121,14 +127,15 @@ Feature: Imports of the test database
121127
| <param3> |
122128

123129
Then table planet_osm_point has 1342 rows
124-
And table planet_osm_line has 3231 rows
125-
And table planet_osm_roads has 375 rows
126-
And table planet_osm_polygon has 4130 rows
127-
128-
Then the sum of 'cast(ST_Area(way) as numeric)' in table planet_osm_polygon is 1247245186
129-
And the sum of 'cast(way_area as numeric)' in table planet_osm_polygon is 1247245413
130-
And the sum of 'ST_Length(way)' in table planet_osm_line is 4211350
131-
And the sum of 'ST_Length(way)' in table planet_osm_roads is 2032023
130+
And table planet_osm_polygon contains
131+
| count(*) | round(sum(ST_Area(way))) | round(sum(way_area)) |
132+
| 4130 | 1247245186 | 1247245413 |
133+
And table planet_osm_line contains
134+
| count(*) | round(sum(ST_Length(way))) |
135+
| 3231 | 4211350 |
136+
And table planet_osm_roads contains
137+
| count(*) | round(sum(ST_Length(way))) |
138+
| 375 | 2032023 |
132139

133140
And there are tables planet_osm_nodes, planet_osm_ways, planet_osm_rels
134141

tests/bdd/steps/steps_db.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,6 @@ def db_table_row_count(context, table, row_num, has_where):
4444
f"Table {table}: expected {row_num} rows, got {actual}"
4545

4646

47-
@then(r"the sum of '(?P<formula>.+)' in table (?P<table>.+) is (?P<result>\d+)(?P<has_where> with condition)?")
48-
def db_table_sum_up(context, table, formula, result, has_where):
49-
assert table_exists(context.db, table)
50-
51-
query = sql.SQL("SELECT round(sum({})) FROM {}")\
52-
.format(sql.SQL(formula), sql.Identifier(*table.split('.', 2)))
53-
54-
if has_where:
55-
query = sql.SQL("{} WHERE {}").format(query, sql.SQL(context.text))
56-
57-
58-
actual = scalar(context.db, query)
59-
60-
assert actual == int(result),\
61-
f"Table {table}: expected sum {result}, got {actual}"
62-
63-
6447
@then("there (?:is|are) (?P<exists>no )?tables? (?P<tables>.+)")
6548
def db_table_existance(context, exists, tables):
6649
for table in tables.split(','):

0 commit comments

Comments
 (0)