add lintr config, make code lint compliant, fixes #20
parent
6a95171bd3
commit
364f612216
@ -0,0 +1,14 @@
|
|||||||
|
exclusions: list('inst/doc/osem-intro.R')
|
||||||
|
linters: with_defaults(
|
||||||
|
# we use snake case
|
||||||
|
camel_case_linter = NULL,
|
||||||
|
# '=' for assignment is fine :^)
|
||||||
|
assignment_linter = NULL,
|
||||||
|
# single quotes are fine
|
||||||
|
single_quotes_linter = NULL,
|
||||||
|
# nobody reads code on a vt100 anymore
|
||||||
|
line_length_linter(120),
|
||||||
|
# this one throws lots of false positives, dial down the noise
|
||||||
|
object_usage_linter = NULL,
|
||||||
|
NULL
|
||||||
|
)
|
@ -1,5 +1,5 @@
|
|||||||
library("testthat")
|
library('testthat')
|
||||||
library("opensensmapr")
|
library('opensensmapr')
|
||||||
library("sf")
|
library('sf')
|
||||||
|
|
||||||
test_check("opensensmapr")
|
test_check('opensensmapr')
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
if (requireNamespace('lintr', quietly = TRUE)) {
|
||||||
|
context('lints')
|
||||||
|
|
||||||
|
test_that('Package Style', {
|
||||||
|
skip_on_cran()
|
||||||
|
lintr::expect_lint_free()
|
||||||
|
})
|
||||||
|
}
|
@ -1,121 +1,116 @@
|
|||||||
context("measurements")
|
source('testhelpers.R')
|
||||||
|
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")
|
|
||||||
}
|
|
||||||
|
|
||||||
try({
|
try({
|
||||||
boxes <- osem_boxes()
|
boxes = osem_boxes()
|
||||||
})
|
})
|
||||||
|
|
||||||
test_that("measurements can be retrieved for a phenomenon", {
|
test_that('measurements can be retrieved for a phenomenon', {
|
||||||
check_api()
|
check_api()
|
||||||
|
|
||||||
measurements <- osem_measurements(x = "Windgeschwindigkeit")
|
measurements = osem_measurements(x = 'Windgeschwindigkeit')
|
||||||
expect_true(is.data.frame(measurements))
|
expect_true(is.data.frame(measurements))
|
||||||
expect_true("osem_measurements" %in% class(measurements))
|
expect_true('osem_measurements' %in% class(measurements))
|
||||||
})
|
})
|
||||||
|
|
||||||
test_that("measurement retrieval does not give progress information in non-interactive mode", {
|
test_that('measurement retrieval does not give progress information in non-interactive mode', {
|
||||||
check_api()
|
check_api()
|
||||||
|
|
||||||
if (!opensensmapr:::is_non_interactive()) skip("interactive session")
|
if (!opensensmapr:::is_non_interactive()) skip('interactive session')
|
||||||
|
|
||||||
out <- capture.output(measurements <- osem_measurements(x = "Licht"))
|
out = capture.output({
|
||||||
|
measurements = osem_measurements(x = 'Licht')
|
||||||
|
})
|
||||||
expect_length(out, 0)
|
expect_length(out, 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
test_that("a response with no matching senseBoxes gives an error", {
|
test_that('a response with no matching senseBoxes gives an error', {
|
||||||
check_api()
|
check_api()
|
||||||
|
|
||||||
expect_error(osem_measurements(x = "Windgeschwindigkeit", exposure = "indoor"), "No senseBoxes found")
|
expect_error(osem_measurements(x = 'Windgeschwindigkeit', exposure = 'indoor'), 'No senseBoxes found')
|
||||||
})
|
})
|
||||||
|
|
||||||
test_that("data.frame can be converted to measurements data.frame", {
|
test_that('data.frame can be converted to measurements data.frame', {
|
||||||
df <- osem_as_measurements(data.frame(c(1,2), c("a", "b")))
|
df = osem_as_measurements(data.frame(c(1, 2), c('a', 'b')))
|
||||||
expect_equal(class(df), c("osem_measurements", "data.frame"))
|
expect_equal(class(df), c('osem_measurements', 'data.frame'))
|
||||||
})
|
})
|
||||||
|
|
||||||
test_that("columns can be specified for phenomena", {
|
test_that('columns can be specified for phenomena', {
|
||||||
check_api()
|
check_api()
|
||||||
|
|
||||||
cols <- c("value", "boxId", "boxName")
|
cols = c('value', 'boxId', 'boxName')
|
||||||
measurements <- osem_measurements(x = "Windgeschwindigkeit", columns = cols)
|
measurements = osem_measurements(x = 'Windgeschwindigkeit', columns = cols)
|
||||||
expect_equal(names(measurements), cols)
|
expect_equal(names(measurements), cols)
|
||||||
})
|
})
|
||||||
|
|
||||||
test_that("measurements can be retrieved for a phenomenon and exposure", {
|
test_that('measurements can be retrieved for a phenomenon and exposure', {
|
||||||
check_api()
|
check_api()
|
||||||
|
|
||||||
measurements <- osem_measurements(x = "Temperatur", exposure = "unknown",
|
measurements = osem_measurements(x = 'Temperatur', exposure = 'unknown',
|
||||||
columns = c("value", "boxId", "boxName"))
|
columns = c('value', 'boxId', 'boxName'))
|
||||||
expect_equal(nrow(measurements), 0)
|
expect_equal(nrow(measurements), 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
test_that("measurements of specific boxes can be retrieved for one phenomenon and returns a measurements data.frame", {
|
test_that('measurements of specific boxes can be retrieved for one phenomenon and returns a measurements data.frame', {
|
||||||
check_api()
|
check_api()
|
||||||
|
|
||||||
# fix for subsetting
|
# fix for subsetting
|
||||||
class(boxes) <- c("data.frame")
|
class(boxes) = c('data.frame')
|
||||||
three_boxes <- boxes[1:3,]
|
three_boxes = boxes[1:3, ]
|
||||||
class(boxes) <- c("sensebox", "data.frame")
|
class(boxes) = c('sensebox', 'data.frame')
|
||||||
three_boxes <- osem_as_sensebox(three_boxes)
|
three_boxes = osem_as_sensebox(three_boxes)
|
||||||
phens <- names(osem_phenomena(three_boxes))
|
phens = names(osem_phenomena(three_boxes))
|
||||||
|
|
||||||
measurements <- osem_measurements(x = three_boxes, phenomenon = phens[[1]])
|
measurements = osem_measurements(x = three_boxes, phenomenon = phens[[1]])
|
||||||
expect_true(is.data.frame(measurements))
|
expect_true(is.data.frame(measurements))
|
||||||
expect_true("osem_measurements" %in% class(measurements))
|
expect_true('osem_measurements' %in% class(measurements))
|
||||||
})
|
})
|
||||||
|
|
||||||
test_that("measurements can be retrieved for a bounding box", {
|
test_that('measurements can be retrieved for a bounding box', {
|
||||||
check_api()
|
check_api()
|
||||||
|
|
||||||
sfc <- sf::st_sfc(sf::st_linestring(x = matrix(data = c(7, 8, 50, 51), ncol = 2)), crs = 4326)
|
sfc = sf::st_sfc(sf::st_linestring(x = matrix(data = c(7, 8, 50, 51), ncol = 2)), crs = 4326)
|
||||||
bbox <- sf::st_bbox(sfc)
|
bbox = sf::st_bbox(sfc)
|
||||||
measurements <- osem_measurements(x = bbox, phenomenon = "Windrichtung")
|
measurements = osem_measurements(x = bbox, phenomenon = 'Windrichtung')
|
||||||
expect_true(all(unique(measurements$lat) > 50))
|
expect_true(all(unique(measurements$lat) > 50))
|
||||||
expect_true(all(unique(measurements$lat) < 51))
|
expect_true(all(unique(measurements$lat) < 51))
|
||||||
expect_true(all(unique(measurements$lon) < 8))
|
expect_true(all(unique(measurements$lon) < 8))
|
||||||
expect_true(all(unique(measurements$lon) > 7))
|
expect_true(all(unique(measurements$lon) > 7))
|
||||||
})
|
})
|
||||||
|
|
||||||
test_that("measurements can be retrieved for a time period", {
|
test_that('measurements can be retrieved for a time period', {
|
||||||
check_api()
|
check_api()
|
||||||
|
|
||||||
from_date <- as.POSIXct("2018-01-01 12:00:00")
|
from_date = as.POSIXct('2018-01-01 12:00:00')
|
||||||
to_date <- as.POSIXct("2018-01-01 13:00:00")
|
to_date = as.POSIXct('2018-01-01 13:00:00')
|
||||||
measurements <- osem_measurements(x = "Temperature", from = from_date, to = to_date)
|
measurements = osem_measurements(x = 'Temperature', from = from_date, to = to_date)
|
||||||
|
|
||||||
expect_true(all(measurements$createdAt < to_date))
|
expect_true(all(measurements$createdAt < to_date))
|
||||||
expect_true(all(measurements$createdAt > from_date))
|
expect_true(all(measurements$createdAt > from_date))
|
||||||
})
|
})
|
||||||
|
|
||||||
test_that("measurements can be retrieved for a time period > 31 days", {
|
test_that('measurements can be retrieved for a time period > 31 days', {
|
||||||
check_api()
|
check_api()
|
||||||
|
|
||||||
from_date <- as.POSIXct("2017-11-01 12:00:00")
|
from_date = as.POSIXct('2017-11-01 12:00:00')
|
||||||
to_date <- as.POSIXct("2018-01-01 13:00:00")
|
to_date = as.POSIXct('2018-01-01 13:00:00')
|
||||||
measurements <- osem_measurements(x = "Windrichtung", from = from_date, to = to_date)
|
measurements = osem_measurements(x = 'Windrichtung', from = from_date, to = to_date)
|
||||||
|
|
||||||
expect_true(all(measurements$createdAt < to_date))
|
expect_true(all(measurements$createdAt < to_date))
|
||||||
expect_true(all(measurements$createdAt > from_date))
|
expect_true(all(measurements$createdAt > from_date))
|
||||||
})
|
})
|
||||||
|
|
||||||
test_that("both from and to are required when requesting measurements, error otherwise", {
|
test_that('both from and to are required when requesting measurements, error otherwise', {
|
||||||
expect_error(osem_measurements(x = "Temperature", from = as.POSIXct("2017-01-01")), "only together with")
|
expect_error(osem_measurements(x = 'Temperature', from = as.POSIXct('2017-01-01')), 'only together with')
|
||||||
expect_error(osem_measurements(x = "Temperature", to = as.POSIXct("2017-01-01")), "only together with")
|
expect_error(osem_measurements(x = 'Temperature', to = as.POSIXct('2017-01-01')), 'only together with')
|
||||||
})
|
})
|
||||||
|
|
||||||
test_that("[.osem_measurements maintains attributes", {
|
test_that('[.osem_measurements maintains attributes', {
|
||||||
check_api()
|
check_api()
|
||||||
|
|
||||||
sfc <- sf::st_sfc(sf::st_linestring(x = matrix(data = c(7, 8, 50, 51), ncol = 2)), crs = 4326)
|
sfc = sf::st_sfc(sf::st_linestring(x = matrix(data = c(7, 8, 50, 51), ncol = 2)), crs = 4326)
|
||||||
bbox <- sf::st_bbox(sfc)
|
bbox = sf::st_bbox(sfc)
|
||||||
m <- osem_measurements(x = bbox, phenomenon = "Windrichtung")
|
m = osem_measurements(x = bbox, phenomenon = 'Windrichtung')
|
||||||
|
|
||||||
expect_true(all(attributes(m[1:nrow(m), ]) %in% attributes(m)))
|
expect_true(all(attributes(m[1:nrow(m), ]) %in% attributes(m)))
|
||||||
})
|
})
|
||||||
|
@ -1,40 +1,33 @@
|
|||||||
context("phenomena")
|
source('testhelpers.R')
|
||||||
|
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")
|
|
||||||
}
|
|
||||||
|
|
||||||
try({
|
try({
|
||||||
boxes <- osem_boxes()
|
boxes = osem_boxes()
|
||||||
all_phen <- unique(unlist(boxes$phenomena))
|
all_phen = unique(unlist(boxes$phenomena))
|
||||||
})
|
})
|
||||||
|
|
||||||
test_that("phenomena from boxes is a list of counts", {
|
test_that('phenomena from boxes is a list of counts', {
|
||||||
check_api()
|
check_api()
|
||||||
|
|
||||||
phenomena <- osem_phenomena(boxes)
|
phenomena = osem_phenomena(boxes)
|
||||||
|
|
||||||
expect_true(is.numeric(unlist(phenomena)))
|
expect_true(is.numeric(unlist(phenomena)))
|
||||||
expect_true(is.list(phenomena))
|
expect_true(is.list(phenomena))
|
||||||
})
|
})
|
||||||
|
|
||||||
test_that("phenomena from boxes has all phenomena", {
|
test_that('phenomena from boxes has all phenomena', {
|
||||||
check_api()
|
check_api()
|
||||||
|
|
||||||
phenomena <- osem_phenomena(boxes)
|
phenomena = osem_phenomena(boxes)
|
||||||
|
|
||||||
expect_true(all(all_phen %in% names(phenomena)))
|
expect_true(all(all_phen %in% names(phenomena)))
|
||||||
expect_true(all(names(phenomena) %in% all_phen))
|
expect_true(all(names(phenomena) %in% all_phen))
|
||||||
})
|
})
|
||||||
|
|
||||||
test_that("phenomena from a not sensebox data.frame returns error", {
|
test_that('phenomena from a not sensebox data.frame returns error', {
|
||||||
expect_error(osem_phenomena(list()), "no applicable method")
|
expect_error(osem_phenomena(list()), 'no applicable method')
|
||||||
expect_error(osem_phenomena(data.frame()), "no applicable method")
|
expect_error(osem_phenomena(data.frame()), 'no applicable method')
|
||||||
boxes_df <- boxes
|
boxes_df = boxes
|
||||||
class(boxes_df) <- c("data.frame")
|
class(boxes_df) = c('data.frame')
|
||||||
expect_error(osem_phenomena(boxes_df), "no applicable method")
|
expect_error(osem_phenomena(boxes_df), 'no applicable method')
|
||||||
})
|
})
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
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')
|
||||||
|
}
|
Loading…
Reference in New Issue