Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace add_row() with insert() in tests #2160

Merged
merged 2 commits into from
Apr 6, 2024
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
19 changes: 12 additions & 7 deletions tests/bdd/flex/area.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,27 @@ Feature: Tests for area column type
columns = {
{ column = 'name', type = 'text' },
{ column = 'geom', type = 'geometry', projection = <geom proj> },
{ column = 'area', type = 'area', projection = <area proj> },
{ column = 'area', type = 'real' },
}
}

function osm2pgsql.process_way(object)
polygons:add_row({
local geom = object:as_polygon()
polygons:insert({
name = object.tags.name,
geom = { create = 'area' }
geom = geom,
area = geom:transform(<area proj>):area()
})
end

function osm2pgsql.process_relation(object)
polygons:add_row({
name = object.tags.name,
geom = { create = 'area', split_at = 'multi' }
})
for sgeom in object:as_multipolygon():geometries() do
polygons:insert({
name = object.tags.name,
geom = sgeom,
area = sgeom:transform(<area proj>):area()
})
end
end
"""
When running osm2pgsql flex
Expand Down
21 changes: 12 additions & 9 deletions tests/bdd/flex/bbox.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ Feature: Test get_bbox() function
{ column = 'min_y', type = 'real' },
{ column = 'max_x', type = 'real' },
{ column = 'max_y', type = 'real' },
{ column = 'geom', type = 'point', projection = <projection> },
{ column = 'geom', type = 'point', projection = <projection>, not_null = true },
})

function osm2pgsql.process_node(object)
local row = {}
local row = { geom = object:as_point() }
row.min_x, row.min_y, row.max_x, row.max_y = object:get_bbox()
points:add_row(row)
points:insert(row)
end
"""
When running osm2pgsql flex
Expand Down Expand Up @@ -47,13 +47,13 @@ Feature: Test get_bbox() function
{ column = 'min_y', type = 'real' },
{ column = 'max_x', type = 'real' },
{ column = 'max_y', type = 'real' },
{ column = 'geom', type = 'linestring', projection = <projection> },
{ column = 'geom', type = 'linestring', projection = <projection>, not_null = true },
})

function osm2pgsql.process_way(object)
local row = { geom = { create = 'line' } }
local row = { geom = object:as_linestring() }
row.min_x, row.min_y, row.max_x, row.max_y = object:get_bbox()
highways:add_row(row)
highways:insert(row)
end
"""
When running osm2pgsql flex
Expand Down Expand Up @@ -85,13 +85,16 @@ Feature: Test get_bbox() function
{ column = 'min_y', type = 'real' },
{ column = 'max_x', type = 'real' },
{ column = 'max_y', type = 'real' },
{ column = 'geom', type = 'linestring', projection = <projection> },
{ column = 'geom', type = 'linestring', projection = <projection>, not_null = true },
})

function osm2pgsql.process_relation(object)
local row = { geom = { create = 'line' } }
local row = {}
row.min_x, row.min_y, row.max_x, row.max_y = object:get_bbox()
rels:add_row(row)
for sgeom in object:as_multilinestring():line_merge():geometries() do
row.geom = sgeom
rels:insert(row)
end
end
"""
When running osm2pgsql flex
Expand Down
6 changes: 3 additions & 3 deletions tests/bdd/flex/extra-attributes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Feature: Tests for including extra attributes
{ column = 'timestamp', type = 'int4' },
{ column = 'uid', type = 'int4' },
{ column = 'user', type = 'text' },
{ column = 'geom', type = 'linestring' },
{ column = 'geom', type = 'linestring', not_null = true },
}
}

function osm2pgsql.process_way(object)
object.geom = { create = 'line' }
attr_table:add_row(object)
object.geom = object:as_linestring()
attr_table:insert(object)
end
"""

Expand Down
24 changes: 14 additions & 10 deletions tests/bdd/flex/invalid-geometries.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Feature: Test handling of invalid geometries
ids = { type = 'way', id_column = 'osm_id' },
columns = {
{ column = 'tags', type = 'hstore' },
{ column = 'geom', type = 'linestring', projection = 4326 },
{ column = 'geom', type = 'linestring', projection = 4326, not_null = true },
}
}

Expand All @@ -19,28 +19,32 @@ Feature: Test handling of invalid geometries
ids = { type = 'area', id_column = 'osm_id' },
columns = {
{ column = 'tags', type = 'hstore' },
{ column = 'geom', type = 'geometry', projection = 4326 }
{ column = 'geom', type = 'geometry', projection = 4326, not_null = true }
}
}

function osm2pgsql.process_way(object)
if object.tags.natural then
tables.polygon:add_row({
tables.polygon:insert({
tags = object.tags,
geom = { create = 'area' }
geom = object:as_polygon()
})
else
tables.line:add_row({
tags = object.tags
tables.line:insert({
tags = object.tags,
geom = object:as_linestring()
})
end
end

function osm2pgsql.process_relation(object)
tables.polygon:add_row({
tags = object.tags,
geom = { create = 'area', split_at = 'multi' }
})
local mgeom = object:as_multipolygon()
for sgeom in mgeom:geometries() do
tables.polygon:insert({
tags = object.tags,
geom = sgeom
})
end
end
"""

Expand Down
18 changes: 10 additions & 8 deletions tests/bdd/flex/line-splitting.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@ Feature: Test splitting of lines

tables.line = osm2pgsql.define_way_table('osm2pgsql_test_line', {
{ column = 'tags', type = 'hstore' },
{ column = 'geom', type = 'linestring', projection = 4326 }
{ column = 'geom', type = 'linestring', projection = 4326, not_null = true }
})

tables.split = osm2pgsql.define_way_table('osm2pgsql_test_split', {
{ column = 'tags', type = 'hstore' },
{ column = 'geom', type = 'linestring', projection = 4326 }
{ column = 'geom', type = 'linestring', projection = 4326, not_null = true }
})

function osm2pgsql.process_way(object)
tables.line:add_row({
tables.line:insert({
tags = object.tags,
geom = { create = 'line' }
})
tables.split:add_row({
tags = object.tags,
geom = { create = 'line', split_at = 1.0 }
geom = object:as_linestring()
})
for sgeom in object:as_linestring():segmentize(1.0):geometries() do
tables.split:insert({
tags = object.tags,
geom = sgeom
})
end
end
"""

Expand Down
44 changes: 24 additions & 20 deletions tests/bdd/flex/multigeom.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ Feature: Handling of multiple geometries
}

function osm2pgsql.process_way(object)
polygons:add_row({
polygons:insert({
name = object.tags.name,
geom = { create = 'area' }
geom = object:as_polygon()
})
end

function osm2pgsql.process_relation(object)
polygons:add_row({
polygons:insert({
name = object.tags.name,
geom = { create = 'area' }
geom = object:as_multipolygon()
})
end
"""
Expand All @@ -61,17 +61,19 @@ Feature: Handling of multiple geometries
}

function osm2pgsql.process_way(object)
polygons:add_row({
polygons:insert({
name = object.tags.name,
geom = { create = 'area' }
geom = object:as_polygon()
})
end

function osm2pgsql.process_relation(object)
polygons:add_row({
name = object.tags.name,
geom = { create = 'area', split_at = 'multi' }
})
for sgeom in object:as_multipolygon():geometries() do
polygons:insert({
name = object.tags.name,
geom = sgeom
})
end
end
"""
When running osm2pgsql flex
Expand Down Expand Up @@ -102,16 +104,16 @@ Feature: Handling of multiple geometries
}

function osm2pgsql.process_way(object)
polygons:add_row({
polygons:insert({
name = object.tags.name,
geom = { create = 'area' }
geom = object:as_polygon()
})
end

function osm2pgsql.process_relation(object)
polygons:add_row({
polygons:insert({
name = object.tags.name,
geom = { create = 'area' }
geom = object:as_multipolygon()
})
end
"""
Expand All @@ -137,17 +139,19 @@ Feature: Handling of multiple geometries
}

function osm2pgsql.process_way(object)
polygons:add_row({
polygons:insert({
name = object.tags.name,
geom = { create = 'area' }
geom = object:as_polygon()
})
end

function osm2pgsql.process_relation(object)
polygons:add_row({
name = object.tags.name,
geom = { create = 'area', split_at = 'multi' }
})
for sgeom in object:as_multipolygon():geometries() do
polygons:insert({
name = object.tags.name,
geom = sgeom
})
end
end
"""
When running osm2pgsql flex
Expand Down
7 changes: 4 additions & 3 deletions tests/bdd/flex/nocluster.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ Feature: Test flex config without clustering
"""
local dtable = osm2pgsql.define_node_table('osm2pgsql_test_point', {
{ column = 'tags', type = 'hstore' },
{ column = 'geom', type = 'point' },
{ column = 'geom', type = 'point', not_null = true },
}, { cluster = 'no' })

function osm2pgsql.process_node(data)
dtable:add_row({
tags = data.tags
dtable:insert({
tags = data.tags,
geom = data:as_point()
})
end
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/bdd/flex/nogeom.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Feature: Handling of tables without geometry
})

function osm2pgsql.process_node(object)
pois:add_row{ tags = object.tags }
pois:insert{ tags = object.tags }
end
"""
When running osm2pgsql flex with parameters
Expand Down
6 changes: 3 additions & 3 deletions tests/bdd/flex/relation-changes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Feature: Handling changes to relations
"""
local rel_table = osm2pgsql.define_area_table('osm2pgsql_test_relations', {
{ column = 'tags', type = 'hstore' },
{ column = 'geom', type = 'geometry' }
{ column = 'geom', type = 'geometry', not_null = true }
})

function osm2pgsql.process_relation(object)
if object.tags.type == 'multipolygon' then
rel_table:add_row{
rel_table:insert{
tags = object.tags,
geom = { create = 'area' }
geom = object:as_multipolygon()
}
end
end
Expand Down
Loading