Commit eaf8e83b authored by Dorchies David's avatar Dorchies David
Browse files

refactor(tests): create scheduled tests

- move regression tests sources to tests folder
- create a scheduled test script which look for tests/testhat/scheduled-*.R files
- rename test-Calibration.R to scheduled-Calibration.R

Refs #120
parent eaeff017
Pipeline #23668 failed with stages
in 4 minutes and 32 seconds
stages:
- check
- regression
- scheduled_tests
- revdepcheck
default:
......@@ -10,13 +10,14 @@ default:
- PATH=~/R/sources/R-${R_VERSION}/bin:$PATH
- R -e 'remotes::install_deps(dep = TRUE)'
.regression:
stage: regression
.scheduled_tests:
stage: scheduled_tests
script:
- Rscript tests/testthat/regression_tests.R stable
- Rscript tests/scheduled.R
- Rscript tests/regression.R stable
- R CMD INSTALL .
- Rscript tests/testthat/regression_tests.R dev
- Rscript tests/testthat/regression_tests.R compare
- Rscript tests/regression.R dev
- Rscript tests/regression.R compare
.check:
stage: check
......@@ -33,26 +34,26 @@ default:
NOT_CRAN: "false"
extends: .check
regression_patched:
scheduled_tests_patched:
variables:
R_VERSION: "patched"
extends: .regression
extends: .scheduled_tests
regression_devel:
scheduled_tests_devel:
only:
refs:
- schedules
variables:
R_VERSION: "devel"
extends: .regression
extends: .scheduled_tests
regression_oldrel:
scheduled_tests_oldrel:
only:
refs:
- schedules
variables:
R_VERSION: "oldrel"
extends: .regression
extends: .scheduled_tests
check_not_cran_patched:
variables:
......
# Helper functions for regression
StoreStableExampleResults <- function(
package = "airGR",
path = file.path("tests/tmp", Sys.getenv("R_VERSION"), "stable"),
......@@ -81,3 +83,27 @@ CompareStableDev <- function() {
quit(status = 1)
}
}
###############
# MAIN SCRIPT #
###############
# Execute Regression test by comparing RD files stored in folders /tests/tmp/ref and /tests/tmp/test
Args <- commandArgs(trailingOnly = TRUE)
lActions <- list(
stable = StoreStableExampleResults,
dev = StoreDevExampleResults,
compare = CompareStableDev
)
if(length(Args) == 1 && Args %in% names(lActions)) {
lActions[[Args]]()
} else {
stop("This script should be run with one argument in the command line:\n",
"`Rscript tests/regression_tests.R [stable|dev|compare]`.\n",
"Available arguments are:\n",
"- stable: install stable version from CRAN, run and store examples\n",
"- dev: install dev version from current directory, run and store examples\n",
"- compare: stored results of both versions")
}
#' Script for running scheduled test
#'
#' All files with the pattern /testthat/tests/scheduled-*.R are tested
#' as testthat does for files /testthat/tests/test-*.R.
#'
#' This script should be started with `source` command from the root of the package.
#' @example
#' source("tests/scheduled.R")
####################
# Helper functions #
####################
#' Wrapper for [quit] which is only applied outside of RStudio
#'
#' @param status See `status` parameter of [quit]. Default `quit = 1`.
#' @param ... Other parameters sent to [quit]
#'
#' @return NULL
#' @export
quit2 <- function(status = 1, ...) {
if (all(!grepl("rstudio", Sys.getenv(), ignore.case = TRUE))) {
quit(status, ...)
}
}
###############
# MAIN SCRIPT #
###############
library(testthat)
library(airGR)
scheduled_tests <-
list.files(
path = "tests/testthat",
pattern = "^scheduled-.*\\.R$",
full.names = TRUE
)
lRes = lapply(scheduled_tests, test_file)
for (res in lRes) {
dRes <- as.data.frame(res)
if (any(dRes[, "failed"] > 0) | any(dRes[, "error"])) {
quit2()
}
}
# Execute Regression test by comparing RD files stored in folders /tests/tmp/ref and /tests/tmp/test
Args <- commandArgs(trailingOnly = TRUE)
source("tests/testthat/helper_regression.R")
lActions <- list(
stable = StoreStableExampleResults,
dev = StoreDevExampleResults,
compare = CompareStableDev
)
if(Args %in% names(lActions)) {
lActions[[Args]]()
} else {
stop("This script should be run with one argument in the command line:\n",
"`Rscript tests/regression_tests.R [stable|dev|compare]`.\n",
"Available arguments are:\n",
"- stable: install stable version from CRAN, run and store examples\n",
"- dev: install dev version from current directory, run and store examples\n",
"- compare: stored results of both versions")
}
......@@ -107,7 +107,6 @@ TestModelCalibration <- function(model) {
model <- as.list(model)
test_that(paste(model$name, ifelse(as.logical(model$IsHyst), "Hysteresis", ""), "works"), {
skip_on_cran()
ParamFinalR <- ModelCalibration(model)
......
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