diff --git a/DESCRIPTION b/DESCRIPTION index d7b8e9ec..f22d1c36 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: osmdata Title: Import 'OpenStreetMap' Data as Simple Features or Spatial Objects -Version: 0.1.9.016 +Version: 0.1.9.017 Authors@R: c( person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre")), person("Bob", "Rudis", role = "aut"), @@ -40,6 +40,7 @@ Imports: utils, xml2 Suggests: + httptest2, knitr, markdown, raster, diff --git a/codemeta.json b/codemeta.json index b777ca40..d03a58f8 100644 --- a/codemeta.json +++ b/codemeta.json @@ -11,7 +11,7 @@ "codeRepository": "https://github.com/ropensci/osmdata/", "issueTracker": "https://github.com/ropensci/osmdata/issues", "license": "https://spdx.org/licenses/GPL-3.0", - "version": "0.1.9.016", + "version": "0.1.9.017", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", @@ -100,6 +100,18 @@ } ], "softwareSuggestions": [ + { + "@type": "SoftwareApplication", + "identifier": "httptest2", + "name": "httptest2", + "provider": { + "@id": "https://cran.r-project.org", + "@type": "Organization", + "name": "Comprehensive R Archive Network (CRAN)", + "url": "https://cran.r-project.org" + }, + "sameAs": "https://CRAN.R-project.org/package=httptest2" + }, { "@type": "SoftwareApplication", "identifier": "knitr", @@ -329,7 +341,7 @@ "r-package", "peer-reviewed" ], - "fileSize": "3000.209KB", + "fileSize": "3002.605KB", "citation": [ { "@type": "ScholarlyArticle", diff --git a/tests/testthat.R b/tests/testthat.R index 76487794..f9b1ae52 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,4 +1,5 @@ library(testthat) +library(httptest2) library(osmdata) test_check("osmdata") diff --git a/tests/testthat/mock_features/wiki.openstreetmap.org/wiki/Map_Features.html b/tests/testthat/mock_features/wiki.openstreetmap.org/wiki/Map_Features.html new file mode 100644 index 00000000..1568f9f7 --- /dev/null +++ b/tests/testthat/mock_features/wiki.openstreetmap.org/wiki/Map_Features.html @@ -0,0 +1,60 @@ + + amenity + + + bar + + +node area + + +Bar is a purpose-built commercial establishment that sells alcoholic drinks to be consumed on the premises. They are characterised by a noisy and vibrant atmosphere, similar to a party and usually don't sell food. See also the description of the tags amenity=pub;bar;restaurant for a distinction between these. + + +
Bar-16.svg
+ + +
Bar MXCT.JPG
+ + + amenity + + + biergarten + + +node area + + +Biergarten or beer garden is an open-air area where alcoholic beverages along with food is prepared and served. See also the description of the tags amenity=pub;bar;restaurant. A biergarten can commonly be found attached to a beer hall, pub, bar, or restaurant. In this case, you can use biergarten=yes additional to amenity=pub;bar;restaurant. + + +
Biergarten-16.svg
+ + +
Hofbräukeller Arkaden.JPG
+ + + amenity + + + cafe + + +node area + + +Cafe is generally an informal place that offers casual meals and beverages; typically, the focus is on coffee or tea. Also known as a coffeehouse/shop, bistro or sidewalk cafe. The kind of food served may be mapped with the tags cuisine=* and diet=*. See also the tags amenity=restaurant;bar;fast_food. + + +
Cafe-16.svg
+ + +
Klagenfurt Wörthersee Strandbad Cafe Sunset Bar 11102008 65.jpg
+ + + amenity + + + fast_food + diff --git a/tests/testthat/mock_tags/wiki.openstreetmap.org/wiki/Map_Features.html b/tests/testthat/mock_tags/wiki.openstreetmap.org/wiki/Map_Features.html new file mode 100644 index 00000000..e486f188 --- /dev/null +++ b/tests/testthat/mock_tags/wiki.openstreetmap.org/wiki/Map_Features.html @@ -0,0 +1,79 @@ +footway +service +service + motorway + trunk + primary + secondary + tertiary + unclassified +road + residential + motorway_link + trunk_link + primary_link + secondary_link + tertiary_link + living_street + service + pedestrian + track + bus_guideway + escape + raceway + road + busway + footway +pedestrian +track + bridleway + steps + corridor +path +footway +cycleway +bridleway +track +footway +path +footway +path + cycleway +cycleway + proposed + construction +path +track +path +track +passing_place +path +footway +path +footway +cycleway +bridleway + bus_stop + crossing + elevator + emergency_bay + emergency_access_point + give_way + milestone + mini_roundabout + motorway_junction +passing_place + platform + rest_area + services + speed_camera + stop +street_lamp + toll_gantry +traffic_mirror + traffic_signals + trailhead + turning_circle + turning_loop +crossing +motorway diff --git a/tests/testthat/mock_tags_fail/wiki.openstreetmap.org/wiki/Map_Features.html b/tests/testthat/mock_tags_fail/wiki.openstreetmap.org/wiki/Map_Features.html new file mode 100644 index 00000000..7a9ce1ae --- /dev/null +++ b/tests/testthat/mock_tags_fail/wiki.openstreetmap.org/wiki/Map_Features.html @@ -0,0 +1,10 @@ +
LOADING TAG LIST... (If you do not see this tag list, you need to enable Javascript)
+
LOADING TAG LIST... (If you do not see this tag list, you need to enable Javascript)
+
LOADING TAG LIST... (If you do not see this tag list, you need to enable Javascript)
+
LOADING TAG LIST... (If you do not see this tag list, you need to enable Javascript)
+
LOADING TAG LIST... (If you do not see this tag list, you need to enable Javascript)
+
LOADING TAG LIST... (If you do not see this tag list, you need to enable Javascript)
+
LOADING TAG LIST... (If you do not see this tag list, you need to enable Javascript)
+
LOADING TAG LIST... (If you do not see this tag list, you need to enable Javascript)
+
LOADING TAG LIST... (If you do not see this tag list, you need to enable Javascript)
+
LOADING TAG LIST... (If you do not see this tag list, you need to enable Javascript)
diff --git a/tests/testthat/test-features.R b/tests/testthat/test-features.R index a8f1fdc1..9405f3dd 100644 --- a/tests/testthat/test-features.R +++ b/tests/testthat/test-features.R @@ -1,21 +1,74 @@ +# Note: the html files produced by these calls, and stored by `httptest2`, are +# huge (> 1MB each), so have to be "post-processeed" here to reduce them to a +# small sample only. Post-process of features is done in the test call; tags are +# done via separate fn defined below. + test_all <- (identical (Sys.getenv ("MPADGE_LOCAL"), "true") | identical (Sys.getenv ("GITHUB_WORKFLOW"), "test-coverage")) test_that ("available_features", { expect_error (available_features (1), "unused argument") - f <- available_features () + + post_process <- !dir.exists ("mock_features") + f <- with_mock_dir ("mock_features", { + available_features () + }) + + if (post_process) { + fname <- list.files ("mock_features", + full.names = TRUE, + recursive = TRUE) [1] + x <- xml2::read_html (fname) + nodes_all <- rvest::html_nodes (x, "td") + nodes_sample <- nodes_all [1:20] + writeLines (as.character (nodes_sample), fname) + } + expect_is (f, "character") expect_true (length (f) > 1L) }) + +post_process_tags <- function (dir_name, sample_index = 1:10, feature = NULL) { + + fname <- list.files (dir_name, + full.names = TRUE, + recursive = TRUE) [1] + x <- xml2::read_html (fname) + nodes_all <- rvest::html_nodes (x, "div[class='taglist']") + if (!is.null (feature)) { + # see features.R/available_tags() for details: + nodes_sample <- rvest::html_nodes ( + x, + sprintf ("a[title^='Tag:%s']", feature) + ) + } else { + nodes_sample <- nodes_all [sample_index] + } + writeLines (as.character (nodes_sample), fname) +} + test_that ("available_tags", { expect_error (available_tags ("highway", 1), "unused argument") - x <- available_tags ("junk") - expect_length (x, 0L) - x <- available_tags ("highway") - expect_is (x, "character") - expect_true (length (x) > 1L) + post_process <- !dir.exists ("mock_tags_fail") + tags <- with_mock_dir ("mock_tags_fail", { + available_tags ("junk") + }) + if (post_process) { + post_process_tags ("mock_tags_fail", 1:10) + } + expect_length (tags, 0L) + + post_process <- !dir.exists ("mock_tags") + tags <- with_mock_dir ("mock_tags", { + available_tags ("highway") + }) + if (post_process) { + post_process_tags ("mock_tags", feature = "highway") + } + expect_is (tags, "character") + expect_true (length (tags) > 1L) })