Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test tutorial + styling modifications in tests #4

Merged
merged 3 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tests/testthat/test-estim_param.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ xfun::gsub_file(file=vignette_rmd,
pattern="stics_version = \"V9.0\"",
replacement=paste0("stics_version = \"",stics_version,"\""),fixed=TRUE)

## Fixing cores number for CI context on Github
if (Sys.getenv("CI") != "") {
xfun::gsub_file(file = vignette_rmd,
"parallel = TRUE","parallel = TRUE, cores = 2",
fixed = TRUE)
}


## generate the R script
knitr::purl(input=vignette_rmd,
output=file.path(tmpdir,"Parameter_estimation_Specific_and_Varietal.R"), documentation = 2)
Expand Down Expand Up @@ -519,6 +527,13 @@ xfun::gsub_file(file=vignette_rmd,
pattern="stics_version = \"V9.0\"",
replacement=paste0("stics_version = \"",stics_version,"\""),fixed=TRUE)

## Fixing cores number for CI context on Github
if (Sys.getenv("CI") != "") {
xfun::gsub_file(file = vignette_rmd,
"parallel = TRUE, cores = 4","parallel = TRUE, cores = 2",
fixed = TRUE)
}

## generate the R script
knitr::purl(input=vignette_rmd,
output=file.path(tmpdir,"AgMIP_Calibration_Phenology_protocol.R"), documentation = 2)
Expand Down
19 changes: 14 additions & 5 deletions tests/testthat/test-stics-wrapper.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@

context("Stics Wrapper")
stics_version <- "V10.0"

# fixing the number of cores in the context of Github CI
if (Sys.getenv("CI") != "") {
cores <- 2
} else {
cores <- NA
}


# Define path to JavaStics and download data
path_to_JavaStics=system.file("stics", package = "SticsRTests")
javastics_path=file.path(path_to_JavaStics,stics_version)
Expand All @@ -14,7 +23,7 @@ SticsRFiles::gen_usms_xml2txt(javastics = javastics_path, workspace = javastics_
out_dir = stics_inputs_path, verbose = TRUE)

# Set options for Stics wrapper
model_options=SticsOnR::stics_wrapper_options(javastics=javastics_path,workspace = stics_inputs_path, parallel=FALSE)
model_options=SticsOnR::stics_wrapper_options(javastics=javastics_path,workspace = stics_inputs_path, parallel = FALSE)

# Standard wrapper tests
param_names=c("dlaimax","durvieF")
Expand All @@ -33,7 +42,7 @@ test_that("Stics Wrapper succeed test_wrapper tests", {

# Test forcing of parameter per situation works
param_values <- data.frame(situation="bo96iN+",dlaimax=0.0005,durvieF=50)
model_options=SticsOnR::stics_wrapper_options(javastics=javastics_path, workspace = stics_inputs_path, parallel=FALSE)
model_options=SticsOnR::stics_wrapper_options(javastics=javastics_path, workspace = stics_inputs_path, parallel = FALSE)

var_name="lai_n"
sim_without_forcing <- SticsOnR::stics_wrapper(model_options = model_options, var="lai_n", situation = c("bo96iN+", "bou99t1"))
Expand Down Expand Up @@ -139,13 +148,13 @@ SticsRFiles::gen_usms_xml2txt(javastics = javastics_path, workspace = javastics_
out_dir = stics_inputs_path,
usm = c("demo_BareSoil2","demo_Wheat1","banana","demo_maize3"), verbose = TRUE)

model_options= SticsOnR::stics_wrapper_options(javastics=javastics_path, workspace = stics_inputs_path, parallel=TRUE)
model_options= SticsOnR::stics_wrapper_options(javastics=javastics_path, workspace = stics_inputs_path, parallel = TRUE, cores = cores)
sim_without_successive=SticsOnR::stics_wrapper(model_options=model_options)

model_options= SticsOnR::stics_wrapper_options(javastics=javastics_path, workspace = stics_inputs_path, successive = list(c("demo_Wheat1","demo_BareSoil2","demo_maize3")), parallel=TRUE)
model_options= SticsOnR::stics_wrapper_options(javastics=javastics_path, workspace = stics_inputs_path, successive = list(c("demo_Wheat1","demo_BareSoil2","demo_maize3")), parallel = TRUE, cores = cores)
sim_with_successive=SticsOnR::stics_wrapper(model_options=model_options)

model_options= SticsOnR::stics_wrapper_options(javastics=javastics_path, workspace = stics_inputs_path, successive = list(c("demo_Wheat1","demo_BareSoil2","demo_maize3")), parallel=TRUE)
model_options= SticsOnR::stics_wrapper_options(javastics=javastics_path, workspace = stics_inputs_path, successive = list(c("demo_Wheat1","demo_BareSoil2","demo_maize3")), parallel = TRUE, cores = cores)
sim_with_successive_restricted_results=SticsOnR::stics_wrapper(model_options=model_options, situation=c("banana","demo_maize3"))

maize_succ_res <- file(file.path(stics_inputs_path,"demo_maize3","mod_bdemo_maize3.sti"), "rb")
Expand Down
26 changes: 17 additions & 9 deletions tests/testthat/test-tutorial.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@

#Download and transform Tutorial .RMD to .R
tmpdir <- normalizePath(tempdir(), winslash = "/", mustWork = FALSE)
tutorial_rmd <-file.path(tmpdir,"SticsRpacks.Rmd")
tutorial_rmd <- file.path(tmpdir, "SticsRpacks.Rmd")
download.file("https://raw.githubusercontent.com/SticsRPacks/SticsRPacks/main/inst/tutorials/SticsRpacks/SticsRpacks.Rmd",
tutorial_rmd)
xfun::gsub_file(file=tutorial_rmd,
"eval=FALSE","eval=TRUE",fixed=TRUE)
xfun::gsub_file(file = tutorial_rmd,
"eval=FALSE","eval=TRUE",
fixed = TRUE)

xfun::gsub_file(file=tutorial_rmd,
xfun::gsub_file(file = tutorial_rmd,
"optim_options = list(nb_rep = 3, out_dir = workspace_path)",
"optim_options = list(nb_rep = 3, out_dir = workspace_path, maxeval=3)",fixed=TRUE)
"optim_options = list(nb_rep = 3, out_dir = workspace_path, maxeval = 3)",
fixed = TRUE)

if (Sys.getenv("CI") != "") {
xfun::gsub_file(file = tutorial_rmd,
"parallel = TRUE","parallel = TRUE, cores = 2",
fixed = TRUE)
}

tutorial_r <-file.path(tmpdir,"tutorial.R")
knitr::purl(input=tutorial_rmd,
output=tutorial_r, documentation = 2)
tutorial_r <-file.path(tmpdir, "tutorial.R")
knitr::purl(input = tutorial_rmd,
output = tutorial_r,
documentation = 2)


# Test Tutor=ial
# Test Tutorial
test_tuto <- function() {
source(tutorial_r)
return (TRUE)
Expand Down
Loading