Skip to content

Commit

Permalink
Merge pull request #309 from ropensci/tests
Browse files Browse the repository at this point in the history
Move tests' dependencies to setup.R
  • Loading branch information
mpadge authored Feb 7, 2023
2 parents 07334e1 + 963c007 commit 5036746
Show file tree
Hide file tree
Showing 9 changed files with 371 additions and 39 deletions.
1 change: 0 additions & 1 deletion tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
library(testthat)
library(httptest2)
library(osmdata)

test_check("osmdata")

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions tests/testthat/mock_osm_sc/overpass-api.de/api/status.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Connected as: 123456789
Current time: 2022-01-01T00:00:00Z
Announced endpoint: z.overpass-api.de/api/
Rate limit: 3
3 slots available now.
Currently running queries (pid, space limit, time limit, start time):
5 changes: 5 additions & 0 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
library(httptest2)

set_overpass_url ("https://overpass-api.de/api/interpreter")

test_all <- Sys.getenv ("GITHUB_WORKFLOW") != "R-CMD-check"
5 changes: 0 additions & 5 deletions tests/testthat/test-elevation.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
has_internet <- curl::has_internet ()

test_all <- (identical (Sys.getenv ("MPADGE_LOCAL"), "true") |
identical (Sys.getenv ("GITHUB_WORKFLOW"), "test-coverage"))

set_overpass_url ("https://overpass-api.de/api/interpreter")

test_that ("elevation", {

# elevation can't actually be tested, because it only works with a full SRTM
Expand Down
5 changes: 0 additions & 5 deletions tests/testthat/test-features.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
# 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"))

set_overpass_url ("https://overpass-api.de/api/interpreter")

test_that ("available_features", {

expect_error (available_features (1), "unused argument")
Expand Down
5 changes: 0 additions & 5 deletions tests/testthat/test-getbb.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
has_internet <- curl::has_internet ()

test_all <- (identical (Sys.getenv ("MPADGE_LOCAL"), "true") |
identical (Sys.getenv ("GITHUB_WORKFLOW"), "test-coverage"))

set_overpass_url ("https://overpass-api.de/api/interpreter")

test_that ("bbox", {

expect_error (bbox_to_string (), "bbox must be provided")
Expand Down
38 changes: 21 additions & 17 deletions tests/testthat/test-osmdata.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
has_internet <- curl::has_internet ()

test_all <- (identical (Sys.getenv ("MPADGE_LOCAL"), "true") |
identical (Sys.getenv ("GITHUB_WORKFLOW"), "test-coverage"))

set_overpass_url ("https://overpass-api.de/api/interpreter")

test_that ("query-construction", {

q0 <- opq (bbox = c (-0.12, 51.51, -0.11, 51.52))
Expand Down Expand Up @@ -325,21 +320,30 @@ test_that ("make_query", {

test_that ("query-no-quiet", {

qry <- opq (bbox = c (-0.118, 51.514, -0.115, 51.517))
qry <- opq (bbox = c (-0.116, 51.516, -0.115, 51.517))
qry <- add_osm_feature (qry, key = "highway")
# switched off until mock results for httr2 reinstanted for #272
# expect_message (x <- osmdata_xml (qry, quiet = FALSE),
# "Issuing query to Overpass API")

if (test_all) {
# expect_message (x <- osmdata_sp (qry, quiet = FALSE),
# "Issuing query to Overpass API")
# expect_message (x <- osmdata_sf (qry, quiet = FALSE),
# "Issuing query to Overpass API")
# expect_message (x <- osmdata_sc (qry, quiet = FALSE),
# "Issuing query to Overpass API")
# expect_message (x <- osmdata_data_frame (qry, quiet = FALSE),
# "Issuing query to Overpass API")
with_mock_dir ("mock_osm_xml", {
expect_message (x <- osmdata_xml (qry, quiet = FALSE),
"Issuing query to Overpass API")
})
with_mock_dir ("mock_osm_sp", {
expect_message (x <- osmdata_sp (qry, quiet = FALSE),
"Issuing query to Overpass API")
})
with_mock_dir ("mock_osm_sf", {
expect_message (x <- osmdata_sf (qry, quiet = FALSE),
"Issuing query to Overpass API")
})
with_mock_dir ("mock_osm_sc", {
expect_message (x <- osmdata_sc (qry, quiet = FALSE),
"Issuing query to Overpass API")
})
with_mock_dir ("mock_osm_df", {
expect_message (x <- osmdata_data_frame (qry, quiet = FALSE),
"Issuing query to Overpass API")
})
}
})

Expand Down
8 changes: 2 additions & 6 deletions tests/testthat/test-unname.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
context ("unname-osmdata-sf")

has_internet <- curl::has_internet ()
skip_if (!has_internet)

test_all <- (identical (Sys.getenv ("MPADGE_LOCAL"), "true") |
identical (Sys.getenv ("GITHUB_WORKFLOW"), "test-coverage"))
skip_if (!test_all)

set_overpass_url ("https://overpass-api.de/api/interpreter")
has_internet <- curl::has_internet ()
skip_if (!has_internet)

require (sf)

Expand Down

0 comments on commit 5036746

Please sign in to comment.