mirror of
https://github.com/sensebox/opensensmapr
synced 2025-02-22 14:53:57 +01:00
skip API dependant tests on CRAN
This commit is contained in:
parent
6d2f6f67e1
commit
7e7b9bcb12
5 changed files with 29 additions and 20 deletions
|
@ -1,6 +1,8 @@
|
|||
context("box")
|
||||
|
||||
check_api <- function() {
|
||||
skip_on_cran()
|
||||
|
||||
code <- NA
|
||||
try(code <- httr::status_code(httr::GET(osem_endpoint())))
|
||||
if (is.na(code)) skip("API not available")
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
context("boxes")
|
||||
|
||||
check_api <- function() {
|
||||
skip_on_cran()
|
||||
|
||||
code <- NA
|
||||
try(code <- httr::status_code(httr::GET(osem_endpoint())))
|
||||
if (is.na(code)) skip("API not available")
|
||||
|
@ -8,7 +10,7 @@ check_api <- function() {
|
|||
|
||||
test_that("a list of all boxes can be retrieved and returns a sensebox data.frame", {
|
||||
check_api()
|
||||
|
||||
|
||||
boxes <- osem_boxes()
|
||||
expect_true(is.data.frame(boxes))
|
||||
expect_true(is.factor(boxes$model))
|
||||
|
@ -24,21 +26,21 @@ test_that("both from and to are required when requesting boxes, error otherwise"
|
|||
|
||||
test_that("a list of boxes with exposure filter returns only the requested exposure", {
|
||||
check_api()
|
||||
|
||||
|
||||
boxes <- osem_boxes(exposure = "mobile")
|
||||
expect_true(all(boxes$exposure == "mobile"))
|
||||
})
|
||||
|
||||
test_that("a list of boxes with model filter returns only the requested model", {
|
||||
check_api()
|
||||
|
||||
|
||||
boxes <- osem_boxes(model = "homeWifi")
|
||||
expect_true(all(boxes$model == "homeWifi"))
|
||||
})
|
||||
|
||||
test_that("box query can combine exposure and model filter", {
|
||||
check_api()
|
||||
|
||||
|
||||
boxes <- osem_boxes(exposure = "mobile", model = "homeWifi")
|
||||
expect_true(all(boxes$model == "homeWifi"))
|
||||
expect_true(all(boxes$exposure == "mobile"))
|
||||
|
@ -46,20 +48,20 @@ test_that("box query can combine exposure and model filter", {
|
|||
|
||||
test_that("a list of boxes with grouptype returns only boxes of that group", {
|
||||
check_api()
|
||||
|
||||
|
||||
boxes <- osem_boxes(grouptag = "codeformuenster")
|
||||
expect_true(all(boxes$grouptag == "codeformuenster"))
|
||||
})
|
||||
|
||||
test_that("endpoint can be (mis)configured", {
|
||||
check_api()
|
||||
|
||||
|
||||
expect_error(osem_boxes(endpoint = "http://not.the.opensensemap.org"), "resolve host")
|
||||
})
|
||||
|
||||
test_that("a response with no matches returns empty sensebox data.frame and a warning", {
|
||||
check_api()
|
||||
|
||||
|
||||
suppressWarnings(boxes <- osem_boxes(grouptag = "does_not_exist"))
|
||||
expect_true(is.data.frame(boxes))
|
||||
expect_true(any("sensebox" %in% class(boxes)))
|
||||
|
@ -67,7 +69,7 @@ test_that("a response with no matches returns empty sensebox data.frame and a wa
|
|||
|
||||
test_that("a response with no matches gives a warning", {
|
||||
check_api()
|
||||
|
||||
|
||||
expect_warning(osem_boxes(grouptag = "does_not_exist"), "no senseBoxes found")
|
||||
})
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
context("counts")
|
||||
|
||||
check_api <- function() {
|
||||
skip_on_cran()
|
||||
|
||||
code <- NA
|
||||
try(code <- httr::status_code(httr::GET(osem_endpoint())))
|
||||
if (is.na(code)) skip("API not available")
|
||||
|
@ -8,9 +10,9 @@ check_api <- function() {
|
|||
|
||||
test_that("counts can be retrieved as a list of numbers", {
|
||||
check_api()
|
||||
|
||||
|
||||
counts <- osem_counts()
|
||||
|
||||
|
||||
expect_true(is.list(counts))
|
||||
expect_true(is.numeric(unlist(counts)))
|
||||
expect_length(counts, 3)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
context("measurements")
|
||||
|
||||
check_api <- function() {
|
||||
skip_on_cran()
|
||||
|
||||
code <- NA
|
||||
try(code <- httr::status_code(httr::GET(osem_endpoint())))
|
||||
if (is.na(code)) skip("API not available")
|
||||
|
@ -10,10 +12,9 @@ try({
|
|||
boxes <- osem_boxes()
|
||||
})
|
||||
|
||||
|
||||
test_that("measurements can be retrieved for a phenomenon", {
|
||||
check_api()
|
||||
|
||||
|
||||
measurements <- osem_measurements(x = "Windgeschwindigkeit")
|
||||
expect_true(is.data.frame(measurements))
|
||||
expect_true("osem_measurements" %in% class(measurements))
|
||||
|
@ -41,7 +42,7 @@ test_that("data.frame can be converted to measurements data.frame", {
|
|||
|
||||
test_that("columns can be specified for phenomena", {
|
||||
check_api()
|
||||
|
||||
|
||||
cols <- c("value", "boxId", "boxName")
|
||||
measurements <- osem_measurements(x = "Windgeschwindigkeit", columns = cols)
|
||||
expect_equal(names(measurements), cols)
|
||||
|
@ -49,7 +50,7 @@ test_that("columns can be specified for phenomena", {
|
|||
|
||||
test_that("measurements can be retrieved for a phenomenon and exposure", {
|
||||
check_api()
|
||||
|
||||
|
||||
measurements <- osem_measurements(x = "Temperatur", exposure = "unknown",
|
||||
columns = c("value", "boxId", "boxName"))
|
||||
expect_equal(nrow(measurements), 0)
|
||||
|
@ -57,14 +58,14 @@ test_that("measurements can be retrieved for a phenomenon and exposure", {
|
|||
|
||||
test_that("measurements of specific boxes can be retrieved for one phenomenon and returns a measurements data.frame", {
|
||||
check_api()
|
||||
|
||||
|
||||
# fix for subsetting
|
||||
class(boxes) <- c("data.frame")
|
||||
three_boxes <- boxes[1:3,]
|
||||
class(boxes) <- c("sensebox", "data.frame")
|
||||
three_boxes <- osem_as_sensebox(three_boxes)
|
||||
phens <- names(osem_phenomena(three_boxes))
|
||||
|
||||
|
||||
measurements <- osem_measurements(x = three_boxes, phenomenon = phens[[1]])
|
||||
expect_true(is.data.frame(measurements))
|
||||
expect_true("osem_measurements" %in% class(measurements))
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
context("phenomena")
|
||||
|
||||
check_api <- function() {
|
||||
skip_on_cran()
|
||||
|
||||
code <- NA
|
||||
try(code <- httr::status_code(httr::GET(osem_endpoint())))
|
||||
if (is.na(code)) skip("API not available")
|
||||
|
@ -13,18 +15,18 @@ try({
|
|||
|
||||
test_that("phenomena from boxes is a list of counts", {
|
||||
check_api()
|
||||
|
||||
|
||||
phenomena <- osem_phenomena(boxes)
|
||||
|
||||
|
||||
expect_true(is.numeric(unlist(phenomena)))
|
||||
expect_true(is.list(phenomena))
|
||||
})
|
||||
|
||||
test_that("phenomena from boxes has all phenomena", {
|
||||
check_api()
|
||||
|
||||
|
||||
phenomena <- osem_phenomena(boxes)
|
||||
|
||||
|
||||
expect_true(all(all_phen %in% names(phenomena)))
|
||||
expect_true(all(names(phenomena) %in% all_phen))
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue