mirror of
https://github.com/sensebox/opensensmapr
synced 2025-02-23 07:53:58 +01:00
add tests and Travis CI configuration
This commit is contained in:
parent
b9ff952489
commit
d3d758d554
5 changed files with 89 additions and 2 deletions
|
@ -2,3 +2,7 @@
|
||||||
^\.Rproj\.user$
|
^\.Rproj\.user$
|
||||||
^CHANGES\.md$
|
^CHANGES\.md$
|
||||||
^tools*$
|
^tools*$
|
||||||
|
^\.travis\.yml$
|
||||||
|
^appveyor\.yml$
|
||||||
|
^CONDUCT\.md$
|
||||||
|
^codecov\.yml$
|
||||||
|
|
5
.travis.yml
Normal file
5
.travis.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r
|
||||||
|
|
||||||
|
language: R
|
||||||
|
sudo: false
|
||||||
|
cache: packages
|
|
@ -17,7 +17,9 @@ Suggests:
|
||||||
knitr,
|
knitr,
|
||||||
rmarkdown,
|
rmarkdown,
|
||||||
lubridate,
|
lubridate,
|
||||||
units
|
units,
|
||||||
|
testthat,
|
||||||
|
covr
|
||||||
Author: Norwin Roosen
|
Author: Norwin Roosen
|
||||||
Maintainer: Norwin Roosen <bugs@nroo.de>
|
Maintainer: Norwin Roosen <bugs@nroo.de>
|
||||||
Description: Download data (environmental measurements, sensorstations) from the
|
Description: Download data (environmental measurements, sensorstations) from the
|
||||||
|
|
4
tests/testthat.R
Normal file
4
tests/testthat.R
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
library("testthat")
|
||||||
|
library("opensensmapr")
|
||||||
|
|
||||||
|
test_check("opensensmapr")
|
72
tests/testthat/test_boxes.R
Normal file
72
tests/testthat/test_boxes.R
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
context("boxes")
|
||||||
|
|
||||||
|
check_api <- function() {
|
||||||
|
code <- NA
|
||||||
|
try(code <- httr::status_code(httr::GET(osem_endpoint())))
|
||||||
|
if (is.na(code)) skip("API not available")
|
||||||
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
expect_true(is.character(boxes$name))
|
||||||
|
expect_length(names(boxes), 14)
|
||||||
|
expect_true(any("sensebox" %in% class(boxes)))
|
||||||
|
})
|
||||||
|
|
||||||
|
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"))
|
||||||
|
})
|
||||||
|
|
||||||
|
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", {
|
||||||
|
check_api()
|
||||||
|
|
||||||
|
boxes <- osem_boxes(grouptag = "does_not_exist")
|
||||||
|
expect_true(is.data.frame(boxes))
|
||||||
|
expect_true(any("sensebox" %in% class(boxes)))
|
||||||
|
})
|
||||||
|
|
||||||
|
test_that("a response with no matches gives a warning", {
|
||||||
|
check_api()
|
||||||
|
|
||||||
|
expect_warning(osem_boxes(grouptag = "does_not_exist"), "no boxes found")
|
||||||
|
})
|
||||||
|
|
||||||
|
test_that("data.frame can be converted to sensebox data.frame", {
|
||||||
|
df <- osem_as_sensebox(data.frame(c(1,2), c("a", "b")))
|
||||||
|
expect_equal(class(df), c("sensebox", "data.frame"))
|
||||||
|
})
|
Loading…
Add table
Reference in a new issue