From 7e7b9bcb12af2ff58d69b083f96786c7f8cf3049 Mon Sep 17 00:00:00 2001 From: Norwin Roosen Date: Mon, 15 Jan 2018 15:25:18 +0100 Subject: [PATCH] skip API dependant tests on CRAN --- tests/testthat/test_box.R | 2 ++ tests/testthat/test_boxes.R | 18 ++++++++++-------- tests/testthat/test_counts.R | 6 ++++-- tests/testthat/test_measurements.R | 13 +++++++------ tests/testthat/test_phenomena.R | 10 ++++++---- 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/tests/testthat/test_box.R b/tests/testthat/test_box.R index b6ca332..4d92141 100644 --- a/tests/testthat/test_box.R +++ b/tests/testthat/test_box.R @@ -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") diff --git a/tests/testthat/test_boxes.R b/tests/testthat/test_boxes.R index d7021ab..c0d925e 100644 --- a/tests/testthat/test_boxes.R +++ b/tests/testthat/test_boxes.R @@ -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") }) diff --git a/tests/testthat/test_counts.R b/tests/testthat/test_counts.R index 90de81d..f4c7d6a 100644 --- a/tests/testthat/test_counts.R +++ b/tests/testthat/test_counts.R @@ -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) diff --git a/tests/testthat/test_measurements.R b/tests/testthat/test_measurements.R index e4600fc..fb85bd7 100644 --- a/tests/testthat/test_measurements.R +++ b/tests/testthat/test_measurements.R @@ -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)) diff --git a/tests/testthat/test_phenomena.R b/tests/testthat/test_phenomena.R index 5e1c5ac..5cf7682 100644 --- a/tests/testthat/test_phenomena.R +++ b/tests/testthat/test_phenomena.R @@ -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)) })