mirror of
https://github.com/sensebox/opensensmapr
synced 2025-02-20 20:23:58 +01:00
fix print.sensebox, add more tests
This commit is contained in:
parent
7ea3ddca01
commit
8975cbc664
4 changed files with 44 additions and 9 deletions
|
@ -31,12 +31,9 @@ plot.sensebox = function (x, ..., mar = c(2, 2, 1, 1)) {
|
|||
}
|
||||
|
||||
#' @export
|
||||
print.sensebox = function(x, ...) {
|
||||
important_columns = c('name', 'exposure', 'lastMeasurement', 'phenomena')
|
||||
print.sensebox = function(x, columns = c('name', 'exposure', 'lastMeasurement', 'phenomena'), ...) {
|
||||
data = as.data.frame(x)
|
||||
available_columns = important_columns %in% names(data)
|
||||
print(data[available_columns], ...)
|
||||
|
||||
print(dplyr::select(data, dplyr::one_of(columns)), ...)
|
||||
invisible(x)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
library('testthat')
|
||||
library('opensensmapr')
|
||||
library('sf')
|
||||
|
||||
test_check('opensensmapr')
|
||||
|
|
|
@ -3,7 +3,7 @@ context('box')
|
|||
|
||||
try({
|
||||
boxes = osem_boxes()
|
||||
box = osem_box(boxes$X_id[[1]])
|
||||
box = osem_box('57000b8745fd40c8196ad04c')
|
||||
})
|
||||
|
||||
test_that('a single box can be retrieved by ID', {
|
||||
|
@ -18,6 +18,12 @@ test_that('a single box can be retrieved by ID', {
|
|||
expect_silent(osem_box(boxes$X_id[[1]]))
|
||||
})
|
||||
|
||||
test_that('unknown box throws', {
|
||||
check_api()
|
||||
|
||||
expect_error(osem_box('asdf'))
|
||||
expect_error(osem_box('57000b8745fd40c800000000'), 'not found')
|
||||
})
|
||||
|
||||
test_that('[.sensebox maintains attributes', {
|
||||
check_api()
|
||||
|
@ -25,14 +31,14 @@ test_that('[.sensebox maintains attributes', {
|
|||
expect_true(all(attributes(boxes[1:nrow(boxes), ]) %in% attributes(boxes)))
|
||||
})
|
||||
|
||||
test_that("print.sensebox filters important attributes", {
|
||||
test_that("print.sensebox filters important attributes for a single box", {
|
||||
msg = capture.output({
|
||||
print(box)
|
||||
})
|
||||
expect_false(any(grepl('description', msg)), 'should filter attribute "description"')
|
||||
})
|
||||
|
||||
test_that("summary.sensebox outputs all metrics", {
|
||||
test_that("summary.sensebox outputs all metrics for a single box", {
|
||||
msg = capture.output({
|
||||
summary(box)
|
||||
})
|
||||
|
|
|
@ -17,6 +17,13 @@ test_that('both from and to are required when requesting boxes, error otherwise'
|
|||
expect_error(osem_boxes(to = as.POSIXct('2017-01-01')), 'must be used together')
|
||||
})
|
||||
|
||||
test_that('a list of boxes with phenomenon filter returns only the requested phenomenon', {
|
||||
check_api()
|
||||
|
||||
boxes = osem_boxes(phenomenon='Temperatur', date=Sys.time())
|
||||
expect_true(all(grep('Temperatur', boxes$phenomena)))
|
||||
})
|
||||
|
||||
test_that('a list of boxes with exposure filter returns only the requested exposure', {
|
||||
check_api()
|
||||
|
||||
|
@ -106,3 +113,29 @@ test_that('box retrieval does not give progress information in non-interactive m
|
|||
})
|
||||
expect_length(out, 0)
|
||||
})
|
||||
|
||||
test_that('print.sensebox filters important attributes for a set of boxes', {
|
||||
check_api()
|
||||
|
||||
boxes = osem_boxes()
|
||||
msg = capture.output({
|
||||
print(boxes)
|
||||
})
|
||||
expect_false(any(grepl('description', msg)), 'should filter attribute "description"')
|
||||
})
|
||||
|
||||
test_that('summary.sensebox outputs all metrics for a set of boxes', {
|
||||
check_api()
|
||||
|
||||
boxes = osem_boxes()
|
||||
msg = capture.output({
|
||||
summary(boxes)
|
||||
})
|
||||
expect_true(any(grepl('sensors per box:', msg)))
|
||||
expect_true(any(grepl('oldest box:', msg)))
|
||||
expect_true(any(grepl('newest box:', msg)))
|
||||
expect_true(any(grepl('\\$last_measurement_within', msg)))
|
||||
expect_true(any(grepl('boxes by model:', msg)))
|
||||
expect_true(any(grepl('boxes by exposure:', msg)))
|
||||
expect_true(any(grepl('boxes total:', msg)))
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue