Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 25 additions & 30 deletions tests/bdd/flex/lua-index-definitions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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 |
46 changes: 21 additions & 25 deletions tests/bdd/flex/way-change.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 <num_w10> rows with condition
"""
way_id = 10
"""
And table osm2pgsql_test_t1 <exist_w10>
| way_id |
| 10 |
Then table osm2pgsql_test_t2 contains exactly
| way_id |
| 10 |
Expand All @@ -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
Expand Down Expand Up @@ -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 <num_w10> rows with condition
"""
way_id = 10
"""
And table osm2pgsql_test_t2 <exist_w10>
| 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
Expand Down Expand Up @@ -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 <num_t1> rows with condition
"""
way_id = 10
"""
And table osm2pgsql_test_t1 <exist_t1>
| way_id |
| 10 |
Then table osm2pgsql_test_t2 contains
| way_id |
| 12 |
And table osm2pgsql_test_t2 has <num_t2> rows with condition
"""
way_id = 10
"""
And table osm2pgsql_test_t2 <exist_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
Expand Down
25 changes: 12 additions & 13 deletions tests/bdd/regression/forward_dependencies.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
41 changes: 12 additions & 29 deletions tests/bdd/regression/import.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
31 changes: 15 additions & 16 deletions tests/bdd/regression/multipolygon.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<param1>' = '-G' THEN min(ST_NumGeometries(way)) ELSE count(*) END FROM planet_osm_polygon GROUP BY osm_id
| osm_id | count |
Expand Down Expand Up @@ -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 |
Expand Down
24 changes: 19 additions & 5 deletions tests/bdd/steps/steps_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@ def delete_table(context, table):
cur.execute("DROP TABLE " + table)


@then(r"table (?P<table>.+) has (?P<row_num>\d+) rows?(?P<has_where> with condition)?")
def db_table_row_count(context, table, row_num, has_where):
@then(r"table (?P<table>.+) has (?P<row_num>\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),\
Expand Down Expand Up @@ -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<table>.+) 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("(?P<query>SELECT .*)")
def db_check_sql_statement(context, query):
with context.db.cursor() as cur:
Expand Down