Skip to content

Commit cf5500b

Browse files
committed
Update function names in tests
All tests passed without changes before this commit. Old functions still work
1 parent a64f726 commit cf5500b

File tree

7 files changed

+75
-69
lines changed

7 files changed

+75
-69
lines changed

tests/testthat/test-data_frame-osm.R

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ test_that ("empty result", {
6969
colnames (bb) <- c ("min", "max")
7070

7171
q0 <- opq (bb, osm_types = "node", datetime = "1714-09-11T00:00:00Z") |>
72-
add_osm_feature ("does not exist", "&%$")
72+
filter_osm_tags ("does not exist", "&%$")
7373

7474
osm_empty <- test_path ("fixtures", "osm-empty.osm")
7575
doc <- xml2::read_xml (osm_empty)
@@ -104,7 +104,7 @@ test_that ("empty result", {
104104
datetime = "1714-09-11T00:00:00Z",
105105
adiff = TRUE
106106
) |>
107-
add_osm_feature ("does not exist", "&%$")
107+
filter_osm_tags ("does not exist", "&%$")
108108

109109
# osm_empty <- test_path ("fixtures", "osm-empty.osm") # same result
110110
# doc <- xml2::read_xml (osm_empty)
@@ -177,9 +177,9 @@ test_that ("date", {
177177
rownames (bb) <- c ("x", "y")
178178
colnames (bb) <- c ("min", "max")
179179
q <- opq (bb, osm_types = "node", datetime = "2020-11-07T00:00:00Z") |>
180-
add_osm_feature ("natural", "peak") |>
181-
add_osm_feature ("prominence") |>
182-
add_osm_feature ("name:ca")
180+
filter_osm_tags ("natural", "peak") |>
181+
filter_osm_tags ("prominence") |>
182+
filter_osm_tags ("name:ca")
183183

184184
osm_meta_date <- test_path ("fixtures", "osm-date.osm")
185185
doc <- xml2::read_xml (osm_meta_date)
@@ -222,7 +222,7 @@ test_that ("out tags center", {
222222
rownames (bb) <- c ("x", "y")
223223
colnames (bb) <- c ("min", "max")
224224
q <- opq (bb, out = "tags center") |>
225-
add_osm_feature ("amenity", "community_centre")
225+
filter_osm_tags ("amenity", "community_centre")
226226

227227
osm_tags_center <- test_path ("fixtures", "osm-tags_center.osm")
228228
doc <- xml2::read_xml (osm_tags_center)
@@ -258,9 +258,9 @@ test_that ("out meta & diff", {
258258
datetime = "2020-11-07T00:00:00Z",
259259
datetime2 = "2022-12-04T00:00:00Z"
260260
) |>
261-
add_osm_feature ("natural", "peak") |>
262-
add_osm_feature ("prominence") |>
263-
add_osm_feature ("name:ca")
261+
filter_osm_tags ("natural", "peak") |>
262+
filter_osm_tags ("prominence") |>
263+
filter_osm_tags ("name:ca")
264264

265265
osm_meta_diff <- test_path ("fixtures", "osm-meta_diff.osm")
266266
doc <- xml2::read_xml (osm_meta_diff)
@@ -310,9 +310,9 @@ test_that ("out meta & adiff", {
310310
osm_types = "node", out = "meta",
311311
datetime = "2020-11-07T00:00:00Z", adiff = TRUE
312312
) |>
313-
add_osm_feature ("natural", "peak") |>
314-
add_osm_feature ("prominence") |>
315-
add_osm_feature ("name:ca")
313+
filter_osm_tags ("natural", "peak") |>
314+
filter_osm_tags ("prominence") |>
315+
filter_osm_tags ("name:ca")
316316

317317
osm_meta_adiff <- test_path ("fixtures", "osm-meta_adiff.osm")
318318
doc <- xml2::read_xml (osm_meta_adiff)
@@ -372,7 +372,7 @@ test_that ("out tags center & adiff", {
372372
adiff = TRUE,
373373
timeout = 50
374374
) |>
375-
add_osm_feature ("amenity", "community_centre")
375+
filter_osm_tags ("amenity", "community_centre")
376376

377377
osm_tags_center <- test_path ("fixtures", "osm-tags_center-adiff.osm")
378378
doc <- xml2::read_xml (osm_tags_center)
@@ -421,7 +421,7 @@ test_that ("adiff2", {
421421
datetime2 = "2016-11-07T00:00:00Z",
422422
adiff = TRUE
423423
) |>
424-
add_osm_feature ("amenity", "restaurant")
424+
filter_osm_tags ("amenity", "restaurant")
425425

426426
osm_adiff2 <- test_path ("fixtures", "osm-adiff2.osm")
427427
doc <- xml2::read_xml (osm_adiff2)
@@ -462,8 +462,8 @@ test_that ("adiff2", {
462462
test_that ("out:csv", {
463463
# q <- getbb ("Catalan Countries", format_out = "osm_type_id") |>
464464
q <- opq (bbox = "relation(id:11747082)", out = "tags center", osm_type = "relation", timeout = 50) |>
465-
add_osm_feature ("admin_level", "7") |>
466-
add_osm_feature ("boundary", "administrative") |>
465+
filter_osm_tags ("admin_level", "7") |>
466+
filter_osm_tags ("boundary", "administrative") |>
467467
opq_csv (fields = c ("name", "::type", "::id", "::lat", "::lon"))
468468

469469
with_mock_dir ("mock_csv", {
@@ -476,7 +476,7 @@ test_that ("out:csv", {
476476
# qqoutes <- getbb ("Barcelona", format_out = "osm_type_id") |>
477477
qqoutes <- opq (bbox = "relation(id:347950)", osm_types = "nwr", out = "tags") |>
478478
opq_csv (fields = c ("name", "::id", "no_exists", "amenity")) |>
479-
add_osm_feature (
479+
filter_osm_tags (
480480
key = "name", value = "\\\"|,|Pont",
481481
value_exact = FALSE
482482
)

tests/testthat/test-elevation.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ test_that ("elevation", {
33
# elevation can't actually be tested, because it only works with a full SRTM
44
# elevation file, so this test doesn't actually do anything.
55
qry <- opq (bbox = c (-0.116, 51.516, -0.115, 51.517)) |>
6-
add_osm_feature (key = "highway")
6+
filter_osm_tags (key = "highway")
77

88
f <- file.path (tempdir (), "junk.osm")
99
doc <- with_mock_dir ("mock_elevation", {

tests/testthat/test-opq.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,18 @@ test_that ("osm_types", {
137137
)
138138
expect_true ("nwr" == q1$osm_types)
139139

140-
features <- c (
140+
tags <- c (
141141
"\"amenity\"=\"school\"",
142142
"\"amenity\"=\"kindergarten\"",
143143
"\"amenity\"=\"music_school\"",
144144
"\"amenity\"=\"language_school\"",
145145
"\"amenity\"=\"dancing_school\""
146146
)
147147
q2 <- opq ("relation(id:349053)") |> # "Catalunya"
148-
add_osm_features (features = features)
148+
add_osm_tags (tags = tags)
149149
s <- opq_string (q2)
150150

151-
n_fts <- length (features)
151+
n_fts <- length (tags)
152152
n_fts_in_query <- length (gregexpr ("amenity", s) [[1]])
153153
# Query should have that number repeated for each osm_types (default to
154154
# node, way, relation):
@@ -336,7 +336,7 @@ test_that ("opq_string", {
336336
bbox = c (-0.118, 51.514, -0.115, 51.517),
337337
osm_types = "node"
338338
)
339-
q1 <- add_osm_feature (q1, key = "amenity", value = "restaurant")
339+
q1 <- filter_osm_tags (q1, key = "amenity", value = "restaurant")
340340
s1 <- opq_string (q1)
341341
# nodes only, so "out" instead of "out body" and no way nor relation
342342
expect_false (grepl ("\\(\\._;>;\\)", s1))
@@ -346,7 +346,7 @@ test_that ("opq_string", {
346346
bbox = "relation(id:11747082)",
347347
osm_types = "node"
348348
)
349-
q2 <- add_osm_feature (q2, key = "amenity", value = "restaurant")
349+
q2 <- filter_osm_tags (q2, key = "amenity", value = "restaurant")
350350
s2 <- opq_string (q2)
351351
# nodes only, so "out" instead of "out body" and no way nor relation on clauses
352352
expect_false (grepl ("\\(\\._;>;\\)", s2))
@@ -367,7 +367,7 @@ test_that ("opq_string", {
367367

368368

369369
# key-value pair:
370-
q2 <- add_osm_feature (q0, key = "highway", value = "!primary")
370+
q2 <- filter_osm_tags (q0, key = "highway", value = "!primary")
371371
s2 <- opq_string (q2)
372372
expect_true (grepl ("highway", s2))
373373
expect_true (grepl ("primary", s2))

tests/testthat/test-osmdata.R

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@ has_internet <- curl::has_internet ()
33
test_that ("query-construction", {
44

55
q0 <- opq (bbox = c (-0.12, 51.51, -0.11, 51.52))
6-
expect_error (q1 <- add_osm_feature (q0), "key must be provided")
7-
expect_silent (q1 <- add_osm_feature (q0, key = "aaa")) # bbox from qry
6+
expect_error (q1 <- filter_osm_tags (q0), "key must be provided")
7+
expect_silent (q1 <- filter_osm_tags (q0, key = "aaa")) # bbox from qry
88
q0$bbox <- NULL
99
expect_error (
10-
q1 <- add_osm_feature (q0, key = "aaa"),
10+
q1 <- filter_osm_tags (q0, key = "aaa"),
1111
"Bounding box has to either be set in opq or must be set here"
1212
)
1313
q0 <- opq (bbox = c (-0.12, 51.51, -0.11, 51.52))
14-
q1 <- add_osm_feature (q0, key = "aaa")
14+
q1 <- filter_osm_tags (q0, key = "aaa")
1515
expect_false (grepl ("=", q1$features))
16-
q1 <- add_osm_feature (q0, key = "aaa", value = "bbb")
16+
q1 <- filter_osm_tags (q0, key = "aaa", value = "bbb")
1717
expect_true (grepl ("=", q1$features))
1818
expect_message (
19-
q1 <- add_osm_feature (q0,
19+
q1 <- filter_osm_tags (q0,
2020
key = "aaa", value = "bbb",
2121
key_exact = FALSE
2222
),
2323
"key_exact = FALSE can only combined with value_exact = FALSE;"
2424
)
2525
expect_silent (
26-
q1 <- add_osm_feature (q0,
26+
q1 <- filter_osm_tags (q0,
2727
key = "aaa", value = "bbb",
2828
key_exact = FALSE, value_exact = FALSE
2929
)
@@ -33,14 +33,14 @@ test_that ("query-construction", {
3333
test_that ("add feature", {
3434

3535
qry <- opq (bbox = c (-0.118, 51.514, -0.115, 51.517))
36-
qry1 <- add_osm_feature (qry, key = "highway")
37-
qry2 <- add_osm_feature (qry, key = "highway", value = "primary")
38-
qry3 <- add_osm_feature (qry,
36+
qry1 <- filter_osm_tags (qry, key = "highway")
37+
qry2 <- filter_osm_tags (qry, key = "highway", value = "primary")
38+
qry3 <- filter_osm_tags (qry,
3939
key = "highway",
4040
value = c ("primary", "tertiary")
4141
)
42-
qry4 <- add_osm_feature (qry, key = "highway", value = "!primary")
43-
qry5 <- add_osm_feature (qry,
42+
qry4 <- filter_osm_tags (qry, key = "highway", value = "!primary")
43+
qry5 <- filter_osm_tags (qry,
4444
key = "highway", value = "primary",
4545
match_case = FALSE
4646
)
@@ -56,7 +56,7 @@ test_that ("add feature", {
5656
bbox <- c (-0.118, 51.514, -0.115, 51.517)
5757
qry <- opq (bbox = bbox)
5858
bbox2 <- bbox + c (0.01, 0.01, -0.01, -0.01)
59-
qry6 <- add_osm_feature (
59+
qry6 <- filter_osm_tags (
6060
qry,
6161
bbox = bbox2,
6262
key = "highway",
@@ -65,14 +65,14 @@ test_that ("add feature", {
6565
expect_true (!identical (qry$bbox, qry6$bbox))
6666

6767
qry7 <- opq ("relation(id:74310)") |> # "Vinçà"
68-
add_osm_feature (key = c ("name", "!name:ca"))
68+
filter_osm_tags (key = c ("name", "!name:ca"))
6969
qry8 <- opq ("relation(id:11755232)") |> # "el Carxe"
70-
add_osm_feature (key = "natural", value = "peak") |>
71-
add_osm_feature (key = "!ele")
70+
filter_osm_tags (key = "natural", value = "peak") |>
71+
filter_osm_tags (key = "!ele")
7272
expect_warning (
7373
qry9 <- opq ("relation(id:11755232)") |> # "el Carxe"
74-
add_osm_feature (key = "!ele") |>
75-
add_osm_feature (key = "natural", value = "peak"),
74+
filter_osm_tags (key = "!ele") |>
75+
filter_osm_tags (key = "natural", value = "peak"),
7676
"The query will request objects whith only a negated key "
7777
)
7878
expect_identical (qry7$features, "[\"name\"] [!\"name:ca\"]")
@@ -249,7 +249,7 @@ test_that ("osmdata without query", {
249249
test_that ("make_query", {
250250

251251
qry <- opq (bbox = c (-0.116, 51.516, -0.115, 51.517))
252-
qry <- add_osm_feature (qry, key = "highway")
252+
qry <- filter_osm_tags (qry, key = "highway")
253253

254254
if (!has_internet) {
255255
expect_error (
@@ -361,7 +361,7 @@ test_that ("make_query", {
361361
test_that ("query-no-quiet", {
362362

363363
qry <- opq (bbox = c (-0.116, 51.516, -0.115, 51.517))
364-
qry <- add_osm_feature (qry, key = "highway")
364+
qry <- filter_osm_tags (qry, key = "highway")
365365

366366
with_mock_dir ("mock_osm_xml", {
367367
expect_message (
@@ -395,47 +395,47 @@ test_that ("query-no-quiet", {
395395
})
396396
})
397397

398-
test_that ("add_osm_features", {
398+
test_that ("add_osm_tags", {
399399

400400
qry <- opq (bbox = c (-0.118, 51.514, -0.115, 51.517))
401401
expect_error (
402-
qry <- add_osm_features (qry),
402+
qry <- add_osm_tags (qry),
403403
"tags must be provided"
404404
)
405405

406406
qry$bbox <- NULL
407407
expect_error (
408-
qry <- add_osm_features (qry, features = "a"),
408+
qry <- add_osm_tags (qry, tags = "a"),
409409
"Bounding box has to either be set in opq or must be set here"
410410
)
411411

412412
qry <- opq (bbox = c (-0.118, 51.514, -0.115, 51.517))
413413

414414
expect_error (
415-
qry <- add_osm_features (qry, features = "a"),
415+
qry <- add_osm_tags (qry, tags = "a"),
416416
"tags must be a named list or vector or a character vector enclosed in escape delimited quotations \\(see examples\\)"
417417
)
418418

419419
bbox <- c (-0.118, 51.514, -0.115, 51.517)
420420
bbox_mod <- bbox + c (-0.001, -0.001, 0.001, 0.001)
421421
qry0 <- opq (bbox = bbox)
422-
qry1 <- add_osm_features (qry0, features = "\"amenity\"=\"restaurant\"")
423-
qry2 <- add_osm_features (qry0,
424-
features = "\"amenity\"=\"restaurant\"",
422+
qry1 <- add_osm_tags (qry0, tags = "\"amenity\"=\"restaurant\"")
423+
qry2 <- add_osm_tags (qry0,
424+
tags = "\"amenity\"=\"restaurant\"",
425425
bbox = bbox_mod
426426
)
427427
expect_false (identical (qry1$bbox, qry2$bbox))
428428

429-
qry3 <- add_osm_features (qry0, features = c ("amenity" = "restaurant"))
429+
qry3 <- add_osm_tags (qry0, tags = c ("amenity" = "restaurant"))
430430
expect_identical (qry1, qry3)
431431

432-
qry4 <- add_osm_features (qry0,
433-
features = c ("amenity" = "restaurant", "amentity" = "pub")
432+
qry4 <- add_osm_tags (qry0,
433+
tags = c ("amenity" = "restaurant", "amentity" = "pub")
434434
)
435435
expect_s3_class (qry4, "overpass_query")
436436

437-
qry5 <- add_osm_features (qry0,
438-
features = list ("amenity" = "restaurant", "amentity" = "pub")
437+
qry5 <- add_osm_tags (qry0,
438+
tags = list ("amenity" = "restaurant", "amentity" = "pub")
439439
)
440440
expect_s3_class (qry5, "overpass_query")
441441
})

tests/testthat/test-set_bind_key_pre.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# NOTE: As of November 2022, these conditions are currently not possible, and
22
# can only be triggered by direct calls to the internal functions. The bind
3-
# and key_pre parameters may be exposed in add_osm_features() in the future if
3+
# and key_pre parameters may be exposed in add_osm_tags() in the future if
44
# package developers decide the option could be useful.
55

66
test_that ("set_bind_key_pre errors", {

tests/testthat/test-unname.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ require (sf)
33
test_that ("unname", {
44

55
qry <- opq (bbox = c (-0.116, 51.516, -0.115, 51.517))
6-
qry <- add_osm_feature (qry, key = "highway")
6+
qry <- filter_osm_tags (qry, key = "highway")
77

88
res <- with_mock_dir ("mock_unname", {
99
osmdata_sf (qry)

tests/timing-benchmark.R

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
#library (osmdata)
1+
# library (osmdata)
22

33
benchmark <- function (times = 100) {
44

55
devtools::load_all (".", export_all = FALSE)
6-
q0 <- opq (bbox = c(-0.27, 51.47, -0.20, 51.50))
7-
q1 <- add_osm_feature (q0, key = "name", value = "Thames")
6+
q0 <- opq (bbox = c (-0.27, 51.47, -0.20, 51.50))
7+
q1 <- filter_osm_tags (q0, key = "name", value = "Thames")
88
# contains both multipolygons and multilinestrings
99
doc <- osmdata_xml (q1, "export.osm")
1010

11-
objs <- c ("points", "lines", "multilinestrings", "multipolygons",
12-
"other_relations")
11+
objs <- c (
12+
"points", "lines", "multilinestrings", "multipolygons",
13+
"other_relations"
14+
)
1315
mt_sf <- size_sf <- NULL
1416
for (i in seq (objs)) {
1517
mb <- microbenchmark::microbenchmark (
16-
dat <- sf::st_read ("export.osm", layer = objs [i], quiet = TRUE),
17-
times = times)
18+
dat <- sf::st_read ("export.osm", layer = objs [i], quiet = TRUE),
19+
times = times
20+
)
1821
size_sf <- c (size_sf, object.size (dat))
1922
mt_sf <- c (mt_sf, median (mb$time))
2023
cat ("\r", i, " / ", length (objs))
@@ -24,13 +27,16 @@ benchmark <- function (times = 100) {
2427
cat ("\t(", mt_sf, "); total = ", sum (mt_sf), "\n")
2528

2629
mb <- microbenchmark::microbenchmark (x <- osmdata_sf (q1, doc),
27-
times = times)
28-
#mb <- microbenchmark::microbenchmark ( x <- osmdata_sf (q1, "export.osm"),
30+
times = times
31+
)
32+
# mb <- microbenchmark::microbenchmark ( x <- osmdata_sf (q1, "export.osm"),
2933
# times = 10L)
3034
mt <- median (mb$time / 1e6)
3135
cat ("osmdata: Median time = ", mt, " ms\n")
3236
size_od <- object.size (x)
3337

34-
cat ("\nosmdata took ", mt / sum (mt_sf), " times longer to extract ",
35-
size_od / sum (size_sf), " times as much data\n")
38+
cat (
39+
"\nosmdata took ", mt / sum (mt_sf), " times longer to extract ",
40+
size_od / sum (size_sf), " times as much data\n"
41+
)
3642
}

0 commit comments

Comments
 (0)