Skip to content

Commit

Permalink
Improve tests and fixes
Browse files Browse the repository at this point in the history
TODO: osm_full_object() lost last object in format = R (test-elements.R:611)
  • Loading branch information
jmaspons committed Jul 1, 2024
1 parent 6d8f3bc commit 08fb4b1
Show file tree
Hide file tree
Showing 44 changed files with 23,231 additions and 1,393 deletions.
30 changes: 29 additions & 1 deletion R/osm_get_user_details.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,39 @@ osm_get_user_details <- function(user_id, format = c("R", "xml", "json")) {
if (length(user_id) == 1) {
out <- tryCatch( # ! HTTP 404 Not Found. Different from osm_details_users()
osm_details_user(user_id = user_id, format = format),
error = function(e) empty_user()
error = function(e) {
switch(format,
R = empty_user(),
xml = empty_usr_xml(),
json = empty_usr_json()
)
}
)
} else {
out <- osm_details_users(user_ids = user_id, format = format)
}

return(out)
}


empty_usr_xml <- function() {
out <- xml2::xml_new_root(
"osm",
version = "0.6", generator = "OpenStreetMap server", copyright = "OpenStreetMap and contributors",
attribution = "http://www.openstreetmap.org/copyright", license = "http://opendatacommons.org/licenses/odbl/1-0/"
)

return(out)
}


empty_usr_json <- function() {
out <- list(
version = "0.6", generator = "OpenStreetMap server", copyright = "OpenStreetMap and contributors",
attribution = "http://www.openstreetmap.org/copyright", license = "http://opendatacommons.org/licenses/odbl/1-0/",
users = list()
)

return(out)
}
3 changes: 0 additions & 3 deletions R/osmapi_elements.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ osm_create_object <- function(x, changeset_id) {
}
osm_type <- xml2::xml_name(xml2::xml_child(xml))

if (length(osm_type) > 1) {
warning("More than one OSM object found. Only the first is created.")
}
if (!osm_type[1] %in% c("node", "way", "relation")) {
warning("Malformed xml. Node name is ", osm_type[1], ", and should be one of `node`, `way` or `relation`.")
}
Expand Down
2 changes: 2 additions & 0 deletions R/osmapi_gps_traces.R
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,8 @@ osm_list_gpxs <- function(format = c("R", "xml")) {

if (format == "R") {
out <- gpx_meta_xml2DF(obj_xml)
} else {
out <- obj_xml
}

return(out)
Expand Down
234 changes: 151 additions & 83 deletions tests/testthat/_snaps/elements.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/map_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
---

Code
print(empty_search_notes)
print(empty_search_notes$df)
Output
[1] lon lat id url comment_url
[6] close_url date_created status comments
Expand Down
929 changes: 20 additions & 909 deletions tests/testthat/_snaps/miscellaneous.md

Large diffs are not rendered by default.

384 changes: 205 additions & 179 deletions tests/testthat/mock_bbox_objects/osm.org/api/0.6/map-e6e175.xml

Large diffs are not rendered by default.

Loading

0 comments on commit 08fb4b1

Please sign in to comment.