Commit 9f435b1f authored by Dorchies David's avatar Dorchies David

test: Fix devtools::check errors and warnings

- Fix vignette location issue in check environment
- add testthat in DESCRIPTION Suggests as Hadley (https://github.com/r-lib/testthat/issues/103#issuecomment-28515632)

Refs #52
parent 15e762ba
......@@ -20,7 +20,7 @@ Authors@R: c(
person("Audrey", "Valéry", role = c("ctb"))
)
Depends: R (>= 3.0.1)
Suggests: knitr, rmarkdown, coda, DEoptim, dplyr, FME, ggmcmc, hydroPSO, Rmalschains
Suggests: knitr, rmarkdown, coda, DEoptim, dplyr, FME, ggmcmc, hydroPSO, Rmalschains, testthat
Description: Hydrological modelling tools developed at INRAE-Antony (HYCAR Research Unit, France). The package includes several conceptual rainfall-runoff models (GR4H, GR5H, GR4J, GR5J, GR6J, GR2M, GR1A), a snow accumulation and melt model (CemaNeige) and the associated functions for their calibration and evaluation. Use help(airGR) for package description and references.
License: GPL-2
URL: https://hydrogr.github.io/airGR/
......
......@@ -60,6 +60,25 @@ RunRmdChunks <- function(fileRmd,
return(TRUE)
}
#' Extract chunks from vignette and source them
#'
#' @param vignette Name of the vignette
#' @param tmpFolder Folder storing the script containing extracted chunks
#' @param force.eval Force execution of chunks with parameter eval=FALSE
#'
#' @return TRUE if succeed.
RunVignetteChunks <- function(vignette,
tmpFolder = "../tmp",
force.eval = TRUE) {
if(file.exists(file.path("../../vignettes/", paste0(vignette, ".Rmd")))) {
# testthat context in development environnement
RunRmdChunks(file.path("../../vignettes/", paste0(vignette, ".Rmd")), tmpFolder, force.eval)
} else {
# R CMD check context in package environnement
RunRmdChunks(system.file(file.path("doc/", paste0(vignette, ".Rmd")), package = "airGR"), tmpFolder, force.eval)
}
return(TRUE)
}
#' Test if conversion from Q in mm per day into Q in L/s is good in BasinObs
#'
......@@ -67,7 +86,7 @@ RunRmdChunks <- function(fileRmd,
#' @param BasinArea Area of the basin in km2
#' @param tolerance See ?all.equal
#'
#' @return
#' @return
TestQmmQlsConversion <- function(BasinObs, BasinArea, tolerance = 1E-7) {
Conversion <- BasinArea * 1000^2 / 1000 * 1000 # km2 -> m2, mm -> m and m3 -> L
Conversion <- Conversion / 86400 # Day -> seconds
......
......@@ -3,7 +3,7 @@ context("Test vignette chunks")
test_that("V01_get_started works", {
skip_on_cran()
rm(list = ls())
expect_true(RunRmdChunks("../../vignettes/V01_get_started.Rmd"))
expect_true(RunVignetteChunks("V01_get_started"))
TestQmmQlsConversion(BasinObs, BasinInfo$BasinArea)
})
......@@ -11,7 +11,7 @@ test_that("V02.1_param_optim works", {
skip_on_cran()
skip("hydroPSO not working presently")
rm(list = ls())
expect_true(RunRmdChunks("../../vignettes/V02.1_param_optim.Rmd"))
expect_true(RunVignetteChunks("V02.1_param_optim"))
})
test_that("V02.2_param_mcmc works", {
......@@ -20,7 +20,7 @@ test_that("V02.2_param_mcmc works", {
load(system.file("vignettesData/vignetteParamMCMC.rda", package = "airGR"))
rda_gelRub <- gelRub
rda_multDRAM <- multDRAM
expect_true(RunRmdChunks("../../vignettes/V02.2_param_mcmc.Rmd"))
expect_true(RunVignetteChunks("V02.2_param_mcmc"))
expect_equal(gelRub, rda_gelRub, tolerance = 1E-7)
expect_equal(multDRAM, rda_multDRAM, tolerance = 1E-7)
})
......@@ -28,7 +28,7 @@ test_that("V02.2_param_mcmc works", {
test_that("V03_param_sets_GR4J works", {
skip_on_cran()
rm(list = ls())
expect_true(RunRmdChunks("../../vignettes/V03_param_sets_GR4J.Rmd"))
expect_true(RunVignetteChunks("V03_param_sets_GR4J"))
})
......@@ -40,7 +40,7 @@ test_that("V04_cemaneige_hysteresis works", {
rda_OutputsCrit_Cal_NoHyst <- OutputsCrit_Cal_NoHyst
rda_OutputsCrit_Val <- OutputsCrit_Val
rda_OutputsCrit_Val_NoHyst <- OutputsCrit_Val_NoHyst
expect_true(RunRmdChunks("../../vignettes/V04_cemaneige_hysteresis.Rmd"))
expect_true(RunVignetteChunks("V04_cemaneige_hysteresis"))
TestQmmQlsConversion(BasinObs, BasinInfo$BasinArea)
expect_equal(OutputsCrit_Cal, rda_OutputsCrit_Cal, tolerance = 1E-7)
expect_equal(OutputsCrit_Cal_NoHyst, rda_OutputsCrit_Cal_NoHyst, tolerance = 1E-7)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment