Title: | Run PIK Integration Tests |
---|---|
Description: | This package includes integration tests for selected models and packages related to those models. |
Authors: | Pascal Führlich [aut, cre], Jan Philipp Dietrich [aut] |
Maintainer: | Pascal Führlich <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.10.2 |
Built: | 2024-12-13 05:29:57 UTC |
Source: | https://github.com/pik-piam/piktests |
This package includes integration tests for selected models and packages related to those models.
Maintainer: Pascal Führlich [email protected]
Authors:
Jan Philipp Dietrich [email protected]
Useful links:
A list of computation objects to be used by run
via the 'whatToRun' parameter.
baseComputations
baseComputations
An object of class list
of length 7.
Each computation object is a list with a setup and a compute function. These are called at the appropriate times
during a piktests run
.
Pascal Führlich
Constructs a folder name based on current data and existing folders
createRunFolder( computationNames = c("magpiePrep", "remindPrep"), piktestsFolder = getwd(), runFolder = NULL )
createRunFolder( computationNames = c("magpiePrep", "remindPrep"), piktestsFolder = getwd(), runFolder = NULL )
computationNames |
These are appended to the created folder's name. |
piktestsFolder |
A new folder for this piktests run is created in the given directory. |
runFolder |
Path where a folder for this piktests run should be created. Generally should be left as default, which creates a folder name based on the current date and computationNames. |
Jan Philipp Dietrich
Runs integration tests in an isolated runtime environment.
run( renvInstallPackages = NULL, computations = c("magpiePrep", "remindPrep"), piktestsFolder = getwd(), runFolder = NULL, jobNameSuffix = "", executionMode = c("slurm", "directly"), localCache = TRUE )
run( renvInstallPackages = NULL, computations = c("magpiePrep", "remindPrep"), piktestsFolder = getwd(), runFolder = NULL, jobNameSuffix = "", executionMode = c("slurm", "directly"), localCache = TRUE )
renvInstallPackages |
After installing other packages, renv::install(renvInstallPackages) is called. Use this to test changes in your fork by passing "<gituser>/<repo>" (e.g. "pfuehrlich-pik/madrat"). |
computations |
A named list of "computations", or names of computations predefined in
|
piktestsFolder |
A new folder for this piktests run is created in the given directory. |
runFolder |
Path where a folder for this piktests run should be created. Generally should be left as default, which creates a folder name based on the current date, time, and the computation names. |
jobNameSuffix |
A suffix to be appended to the SLURM job's name. |
executionMode |
Determines how long running jobs are started. One of "slurm", "directly" |
localCache |
If TRUE (default) use a new and empty cache folder, otherwise 'getConfig("cachefolder")'. |
The preconfigured madrat source and mapping folders are used, otherwise a subfolder of the newly created run folder is used as madrat mainfolder.
Invisibly, the path to the folder holding everything related to this piktests run.
Pascal Führlich, Jan Philipp Dietrich
## Not run: piktests::run(renvInstallPackages = c("tscheypidi/madrat", "[email protected]"), computations = list(testComputation = list(setup = function() message("Hello"), compute = function() message("World"))), executionMode = "directly", localCache = FALSE) ## End(Not run)
## Not run: piktests::run(renvInstallPackages = c("tscheypidi/madrat", "[email protected]"), computations = list(testComputation = list(setup = function() message("Hello"), compute = function() message("World"))), executionMode = "directly", localCache = FALSE) ## End(Not run)
Experimental. Create an renv with all packages needed to run the given function and run that function in that renv.
runInRenv( work, ..., targetFolder = ".", renvLockfile = NULL, renvPreInstall = NULL )
runInRenv( work, ..., targetFolder = ".", renvLockfile = NULL, renvPreInstall = NULL )
work |
A function that should be executed in the newly created renv. |
... |
Arguments passed to |
targetFolder |
Where the renv is created. |
renvLockfile |
Optional. An renv lockfile used to create the renv. If NULL auto-detect dependencies instead. |
renvPreInstall |
Optional. A function that is run right after initializing the renv, can be used to apply system specific fixes. |
Run a function in a new R session, per default via SLURM (see executionMode). The log will be written to 'file.path(workingDirectory, "job.log")'.
runLongJob( workFunction, arguments = list(), workingDirectory = getwd(), renvToLoad = NULL, madratConfig = NULL, jobName = opts_slurmR$get_job_name(), executionMode = c("slurm", "directly") )
runLongJob( workFunction, arguments = list(), workingDirectory = getwd(), renvToLoad = NULL, madratConfig = NULL, jobName = opts_slurmR$get_job_name(), executionMode = c("slurm", "directly") )
workFunction |
This function will be run in a new R session, so it must use '::' whenever package functions are used. Also it cannot refer to variables in the outer scope, use the next parameter (arguments) to pass them. |
arguments |
A list of arguments passed to workFunction. |
workingDirectory |
The working directory in which workFunction will be called. |
renvToLoad |
The renv project to load before running workFunction. |
madratConfig |
A madrat config (as returned by 'madrat::getConfig()') to be used when running workFunction. |
jobName |
The SLURM job's name. |
executionMode |
Determines how workFunction is started. "slurm" -> 'slurmR::Slurm_lapply', "directly" -> 'callr::r' |
Pascal Führlich
Starts two piktests runs, one with default packages and another one with renvInstallPackages installed, so they can be compared. Run this to test changes in your fork by passing "<gituser>/<repo>" (e.g. "pfuehrlich-pik/madrat"). Use the shell scripts created in the run folder to compare logs after all runs are finished.
runWithComparison( renvInstallPackages, computations = c("magpiePrep", "remindPrep"), piktestsFolder = getwd(), diffTool = c("delta", "colordiff", "diff"), ... )
runWithComparison( renvInstallPackages, computations = c("magpiePrep", "remindPrep"), piktestsFolder = getwd(), diffTool = c("delta", "colordiff", "diff"), ... )
renvInstallPackages |
Only in the second run, after installing other packages, 'renv::install(renvInstallPackages)' is called. |
computations |
A named list of "computations", or names of computations predefined in
|
piktestsFolder |
A new folder is created in the given directory. In that folder two folders called "old" and "new" are created which contain the actual piktests runs. |
diffTool |
One or more names of command line tools for comparing two text files. The first one that is found via 'Sys.which' is used in the comparison shell script. If none is found falls back to "diff". |
... |
Additional arguments passed to |
Invisibly, the path to the folder holding the two actual piktests runs.
Pascal Führlich
Sets up a fresh renv and installs the required packages in it.
setupRenv(targetFolder, renvInstallPackages, computationsSourceCode)
setupRenv(targetFolder, renvInstallPackages, computationsSourceCode)
targetFolder |
Where to setup the renv. |
renvInstallPackages |
renv::install(renvInstallPackages) is called. Use this to test changes in your fork by passing "<gituser>/<repo>" (e.g. "pfuehrlich-pik/madrat"). |
computationsSourceCode |
A character vector containing the source code to create a list of computations
(see |
This function should be called in a fresh R session (e.g. via callr::r), because setting up an renv involves changing critical aspects of your R session like your libpaths.
Pascal Führlich
## Not run: computations <- piktests::baseComputations[c("madratExample", "magpiePreprocessing")] callr::r(piktests:::setupRenv, list(targetFolder = tempdir(), renvInstallPackages = c("tscheypidi/madrat", "[email protected]"), computationsSourceCode = deparse(computations)), show = TRUE) ## End(Not run)
## Not run: computations <- piktests::baseComputations[c("madratExample", "magpiePreprocessing")] callr::r(piktests:::setupRenv, list(targetFolder = tempdir(), renvInstallPackages = c("tscheypidi/madrat", "[email protected]"), computationsSourceCode = deparse(computations)), show = TRUE) ## End(Not run)