Skip to content
11 changes: 11 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,14 @@
invisible()
}
rlang::on_load(rlang::local_use_cli(inline = TRUE))


# see ?usethis::use_release_issue() #nolint
release_bullets <- function() {
c(
"Update codemeta.json with: `codemetar::write_codemeta()`",
"update CITATION.cff with `cffr::cff_write(dependencies = FALSE)`
(after incrementing version)",
"Run local tests to ensure attributes and radars with api keys work"
)
}
103 changes: 103 additions & 0 deletions tests/testthat/test-get_pvol_attributes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
check_attributes <- function(x, wr_df) {
expect_s3_class(x, "pvol")
expect_true(bioRad::is.pvol(x))
expect_true(x$radar %in% wr_df$radar)
radar_df <- wr_df[
x$radar == wr_df$radar &
(as.logical(wr_df$status) | wr_df$country == "United States"),
]
expect_equal(nrow(radar_df), 1)
expect_equal(x$geo$height, radar_df$heightantenna, tolerance = .001)
expect_equal(
x$attributes$where$height,
radar_df$heightantenna,
tolerance = .001
)
expect_equal(x$geo$lat, radar_df$latitude, tolerance = .001)
expect_equal(x$attributes$where$lat, radar_df$latitude, tolerance = .001)
expect_equal(x$geo$lon, radar_df$longitude, tolerance = .001)
expect_equal(x$attributes$where$lon, radar_df$longitude, tolerance = .001)
expect_equal(
# For the Netherlands wavelength get a dim 1, using c() drops it
c(x$attributes$how$wavelength),
299792458 / (radar_df$frequency * 10^9) * 100,
tolerance = .005
)
}
wr_df <- get_weather_radars(source = c("nexrad", "opera"))
t <- Sys.time() - 24 * 60 * 60

test_that("Check Germany", {
skip_on_cran()
skip_on_ci()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why skip on CI?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As i remember the tests can take quite long, if we want to test on CI i think we should avoid doing it on all runners (also to reduce load). These tests are mainly meant to check the data format of the radars so are not likely os dependent

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very well, I was just curious. Seems like it should do the trick!

I've once read, I believe in the HTTP testing guide, about setting up a Github Workflow that ran every week instead of every PR to test for this kind of integrity. But I've never actually set something like that up for any of my repo's. I've used postman instead for checking that sort of thing.

pv <- get_pvol("depro", t)
check_attributes(pv, wr_df)
})

test_that("Check Czechia", {
skip_on_cran()
skip_on_ci()

pv <- get_pvol("czbrd", t)
check_attributes(pv, wr_df)
})

test_that("Check Estonia", {
skip_on_cran()
skip_on_ci()
pv <- get_pvol("eehar", t)
check_attributes(pv, wr_df)
})

test_that("Check Finland", {
skip_on_cran()
skip_on_ci()
pv <- get_pvol("fikor", t)
check_attributes(pv, wr_df)
})

test_that("Check Romania", {
skip_on_cran()
skip_on_ci()
pv <- get_pvol("roora", t)
check_attributes(pv, wr_df)
})

test_that("Check Slovakia", {
skip_on_cran()
skip_on_ci()
pv <- get_pvol("skkoj", t)
check_attributes(pv, wr_df)
})

test_that("Check Netherland", {
skip_on_cran()
skip_on_ci()
withr::local_options(list(
"keyring_backend" = "env"
))
# get public key here https://developer.dataplatform.knmi.nl/open-data-api#token
withr::local_envvar(
list(
"getRad_nl_api_key" = "eyJvcmciOiI1ZTU1NGUxOTI3NGE5NjAwMDEyYTNlYjEiLCJpZCI6ImVlNDFjMWI0MjlkODQ2MThiNWI4ZDViZDAyMTM2YTM3IiwiaCI6Im11cm11cjEyOCJ9"
)
)
skip_if(Sys.which("KNMI_vol_h5_to_ODIM_h5") == "")
pv <- get_pvol("nldhl", t)
check_attributes(pv, wr_df)
})

test_that("Check Denmark", {
skip_on_cran()
skip_on_ci()
pv <- get_pvol("dkbor", t)
check_attributes(pv, wr_df)
})


test_that("Check US", {
skip_on_cran()
skip_on_ci()
pv <- get_pvol("KABR", t)
check_attributes(pv, wr_df)
})
4 changes: 4 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ test_that("fetch_from_url_raw warns on failing url", {
200
)
})
testthat::test_that("release_bullets returns expected", {
expect_type(release_bullets(), "character")
expect_gte(length(release_bullets()), 1)
})