Skip to content

Commit

Permalink
add test for path in setSimulationPath() + test + cleaning vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
berthetclement committed Jul 12, 2024
1 parent 1cf8c49 commit c2b5ff8
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 455 deletions.
17 changes: 6 additions & 11 deletions R/setSimulationPath.R
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ setSimulationPath <- function(path, simulation = NULL) {
# Private function that extracts study, simulation and input paths from the
# path specified by the user.
.getPaths <- function(path, simulation) {
# check path must be length 1
if(length(path)!=1)
stop("Only one path is required",
call. = FALSE)

path <- gsub("[/\\]$", "", path)
path <- normalizePath(path, winslash = "/")

Expand All @@ -276,19 +281,9 @@ setSimulationPath <- function(path, simulation = NULL) {
# - 2. there is only one study in the output. Select it
# - 3. asks the user to interactively choose one simulation

if (!file.exists(file.path(path, "study.antares"))){
# allFiles <- list.files(path)
# avaliableFile <- allFiles[grep(".h5$", allFiles)]
# if(length(avaliableFile) == 0)
# {
if (!file.exists(file.path(path, "study.antares")))
stop("Directory is not an Antares study.")
# }else{
# ##H5 mode
# return("H5")
# }
}


outputPath <- file.path(path, "output")

outputContent <- list.dirs(outputPath, recursive = FALSE)
Expand Down
146 changes: 0 additions & 146 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,152 +108,6 @@ utils::globalVariables(
"DETAILS_FILES_TYPE","ANTARES_DISPLAYED_NAME")
)

# #----------------------------- HDF5 ------------------------------------#
#
#
# is.installed <- function(mypkg) is.element(mypkg, utils::installed.packages()[,1])
#
# rhdf5_version <- "2.24.0"
# rhdf5_message <- "This function require 'rhdf5' (>= 2.24.0) package.
# This is a bioconductor package. You can install it with :
# source('https://bioconductor.org/biocLite.R')
# biocLite('rhdf5')"
#
# # !! parameter versionCheck of requireNamespace does not work correctly, use utils::package_version instead
# .requireRhdf5_Antares <- function(stopP = TRUE){
# if(.check_rhdf5(stopP = stopP)){
# if(.check_rhdf5_version(stopP = stopP)){
# return(TRUE)
# }
# }
# return(FALSE)
# }
#
# .stop_rhdf5_version <- function(stopP = TRUE) {
# if(stopP){
# stop(rhdf5_message)
# }else{
# return(FALSE)
# }
# }
#
# .check_rhdf5 <- function(stopP = TRUE){
# if(requireNamespace("rhdf5", quietly = TRUE)){
# return(TRUE)
# }else{
# .stop_rhdf5_version(stopP)
# }
# }
#
# .check_rhdf5_version <- function(stopP = TRUE){
# if(utils::packageVersion("rhdf5") >= rhdf5_version){
# return(TRUE)
# }else{
# .stop_rhdf5_version(stopP)
# }
# }
#
# # .addClassAndAttributes <- antaresRead:::.addClassAndAttributes
#
# pkgEnvAntareasH5 <- new.env()
#
# pkgEnvAntareasH5$varAreas <- c("OV. COST", "OP. COST", "MRG. PRICE", "CO2 EMIS.", "BALANCE",
# "ROW BAL.", "PSP", "MISC. NDG", "LOAD", "H. ROR", "WIND", "SOLAR",
# "NUCLEAR", "LIGNITE", "COAL", "GAS", "OIL", "MIX. FUEL", "MISC. DTG",
# "H. STOR", "UNSP. ENRG", "SPIL. ENRG", "LOLD", "LOLP", "AVL DTG",
# "DTG MRG", "MAX MRG", "NP COST", "NODU")
#
# pkgEnvAntareasH5$varAreas <- as.vector(sapply(pkgEnvAntareasH5$varAreas, function(X){paste0(X, c("", "_min", "_max", "_std"))}))
#
# pkgEnvAntareasH5$varDistricts <- pkgEnvAntareasH5$varAreas
#
# pkgEnvAntareasH5$varLinks <- c("FLOW LIN.", "UCAP LIN.", "FLOW QUAD.",
# "CONG. FEE (ALG.)", "CONG. FEE (ABS.)",
# "MARG. COST", "CONG. PROB +", "CONG. PROB -", "HURDLE COST")
#
# pkgEnvAntareasH5$varLinks <- as.vector(sapply(pkgEnvAntareasH5$varLinks, function(X){paste0(X, c("", "_min", "_max", "_std"))}))
#
# pkgEnvAntareasH5$varClusters <- c("production", "NP Cost", "NODU")
#
# pkgEnvAntareasH5$varAliasCreated <- list()
#
#
# #misc
# pkgEnvAntareasH5$varAliasCreated$misc$areas <- c("CHP",
# "Bio_mass",
# "Bio_gas",
# "mustRunWasteTotal",
# "GeoThermal",
# "Other",
# "PSP_input",
# "ROW_Balance")
#
# pkgEnvAntareasH5$varAliasCreated$misc$districts <- c("CHP",
# "Bio_mass",
# "Bio_gas",
# "mustRunWasteTotal",
# "GeoThermal",
# "Other",
# "PSP_input",
# "ROW_Balance")
# #thermalAvailabilities
# pkgEnvAntareasH5$varAliasCreated$thermalAvailabilities$clusters <- c("thermalAvailability",
# "availableUnits")
#
#
# #hydroStorage
# pkgEnvAntareasH5$varAliasCreated$hydroStorage$areas <- c("hydroStorage")
#
# pkgEnvAntareasH5$varAliasCreated$hydroStorage$districts <- c("hydroStorage")
#
# #hydroStorageMaxPower
# pkgEnvAntareasH5$varAliasCreated$hydroStorageMaxPower$areas <- c("hstorPMaxLow",
# "hstorPMaxAvg",
# "hstorPMaxHigh")
#
# pkgEnvAntareasH5$varAliasCreated$hydroStorageMaxPower$districts <- c("hstorPMaxLow",
# "hstorPMaxAvg",
# "hstorPMaxHigh")
#
# #reserve
# pkgEnvAntareasH5$varAliasCreated$reserve$areas <- c("primaryRes",
# "strategicRes",
# "DSM",
# "dayAhead")
#
# pkgEnvAntareasH5$varAliasCreated$reserve$districts <- c("primaryRes",
# "strategicRes",
# "DSM",
# "dayAhead")
#
# #linkCapacity
# pkgEnvAntareasH5$varAliasCreated$linkCapacity$links <- c("transCapacityDirect",
# "transCapacityIndirect",
# "impedances",
# "hurdlesCostDirect",
# "hurdlesCostIndirect")
#
# #mustRun
# pkgEnvAntareasH5$varAliasCreated$mustRun$areas <- c("thermalPmin",
# "mustRun",
# "mustRunPartial",
# "mustRunTotal")
#
# pkgEnvAntareasH5$varAliasCreated$mustRun$districts <- c("thermalPmin",
# "mustRun",
# "mustRunPartial",
# "mustRunTotal")
#
# pkgEnvAntareasH5$varAliasCreated$mustRun$clusters <- c("thermalPmin",
# "mustRun",
# "mustRunPartial",
# "mustRunTotal")
#
# pkgEnvAntareasH5$varAliasCreated$thermalModulation$clusters <- c("marginalCostModulation",
# "marketBidModulation",
# "capacityModulation",
# "minGenModulation")

integerVariable <- as.character(unique(pkgEnv$formatName$Name[which(pkgEnv$formatName$digits == 0)]))
integerVariable <- unlist(apply(expand.grid(integerVariable, c("", "_std", "_min", "_max")), 1,
function(X){paste0(X, collapse = "")}))
Expand Down
3 changes: 2 additions & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Release 2.7.1

- To fix problem with cran check (see log "M1mac").
- Add some bug fix (see news.md)
- Add some bug fix (see news.md)
- Fix multiple "path" bug in `setSimulationPath()`


## R CMD check results OK
Expand Down
80 changes: 11 additions & 69 deletions tests/testthat/helper_init.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
#Copyright © 2016 RTE Réseau de transport d’électricité

options("antaresRead.skip_h5_on_cran" = TRUE)
options("antaresRead.skip_h5" = TRUE)
options("antaresRead.skip_h5_on_travis" = TRUE)
options("antaresRead.skip_h5_on_appveyor" = TRUE)


# Copy the test study in a temporary folder

path0 <- tempdir()

#sourcedir <- system.file("inst/testdata", package = "antaresRead")
sourcedir <- system.file("testdata", package = "antaresRead")
testH5 <- TRUE

#if(sourcedir == ""){ }

## force tests to be executed if in dev release which we define as
Expand All @@ -21,7 +15,6 @@ testH5 <- TRUE
if (length(strsplit(packageDescription("antaresRead")$Version, "\\.")[[1]]) > 3) {
Sys.setenv("RunAllAntaresReadTests"="yes")
}
.runH5Test <- FALSE #Sys.getenv("RunAllAntaresReadTests") == "yes"

compareValue <- function(A, B, res = NULL){
if(class(A)[3] == "list"){
Expand Down Expand Up @@ -65,55 +58,6 @@ if (sourcedir != "") {
untar(file.path(sourcedir, studies[s]), exdir = file.path(path0, studies_names[s]))
}

# if(.requireRhdf5_Antares(stopP = FALSE) & .runH5Test){
#
# path_v6 <- file.path(path0, "antares-test-study-v6")
# opts <- setSimulationPath(file.path(path_v6, "/test_case"))
# suppressMessages({
# suppressWarnings({
#
# #On cran we have only 2 threads so nbCore <- 1
# if(.runH5Test){
# nbCoresTestHelper <- 4
# }else{
# nbCoresTestHelper <- 1
# }
# writeAntaresH5(path = path_v6,
# misc = TRUE, thermalAvailabilities = TRUE,
# hydroStorage = TRUE, hydroStorageMaxPower = TRUE, reserve = TRUE,
# linkCapacity = TRUE,mustRun = TRUE, thermalModulation = TRUE,
# overwrite=TRUE, nbCores = nbCoresTestHelper)
# })
# })
#
# #if you change the tar file then you must also change this file
# # h5file <- "20190321-2217eco-test.h5"
# h5file <- "20180423-1734eco-test.h5"
#
# deprintize<-function(f){
# return(function(...) {capture.output(w<-f(...));return(w);});
# }
#
# silentf <- deprintize(showAliases)
#
# alias <- silentf()$name
# alias <- as.character(alias)
#
#
#
# timeStep <- c("hourly", "daily", "weekly", "monthly", "annual")
#
# assign("silentf", silentf, envir = globalenv())
# assign("tpDir", path_v6, envir = globalenv())
# assign("pathF", file.path(path_v6, "/", h5file), envir = globalenv())
# assign("h5file", h5file, envir = globalenv())
# assign("alias", alias, envir = globalenv())
# assign("compareValue", compareValue, envir = globalenv())
# assign("timeStep", timeStep, envir = globalenv())
# assign("optsG", opts, envir = globalenv())
#
# }

assign(
x = "studyPathS",
value = file.path(path0, studies_names, "test_case"),
Expand Down Expand Up @@ -156,18 +100,16 @@ if(sourcedir_V8 != ""){
}




skip_according_to_options <- function() {
if (isTRUE(getOption("antaresRead.skip_h5_on_cran")))
skip_on_cran()
if (isTRUE(getOption("antaresRead.skip_h5")))
skip("h5 test skipped")
if (isTRUE(getOption("antaresRead.skip_h5_on_travis")))
skip_on_travis()
if (isTRUE(getOption("antaresRead.skip_h5_on_appveyor")))
skip_on_appveyor()
}
# skip_according_to_options <- function() {
# if (isTRUE(getOption("antaresRead.skip_h5_on_cran")))
# skip_on_cran()
# if (isTRUE(getOption("antaresRead.skip_h5")))
# skip("h5 test skipped")
# if (isTRUE(getOption("antaresRead.skip_h5_on_travis")))
# skip_on_travis()
# if (isTRUE(getOption("antaresRead.skip_h5_on_appveyor")))
# skip_on_appveyor()
# }

pathAPI <- "http://localhost:8080/studies/antaresStd/"

Expand Down
60 changes: 30 additions & 30 deletions tests/testthat/test-aggregateResult.R
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@


context("Function aggregateResult")

skip("")

pathstd <- tempdir()

opts <- setSimulationPath(studyPathSV8)


test_that("test parallel aggregate", {

mc_all_path <- file.path(opts$simDataPath, "mc-all", "grid", "digest.txt")

mdate_original <- file.mtime(mc_all_path)

parAggregateMCall(opts, nbcl = 2, mcYears = c(1,2), verbose = 0)

expect_true(file.exists(mc_all_path))
expect_false(file.mtime(mc_all_path) == mdate_original)
expect_true(file.size(mc_all_path) > 0)

mdate_original <- file.mtime(mc_all_path)

parAggregateMCall(opts, nbcl = 1, mcYears = c(1,2), verbose = 0)

expect_true(file.exists(mc_all_path))
expect_false(file.mtime(mc_all_path) == mdate_original)
expect_true(file.size(mc_all_path) > 0)

})
# context("Function aggregateResult")
#
# skip("")
#
# pathstd <- tempdir()
#
# opts <- setSimulationPath(studyPathSV8)
#
#
# test_that("test parallel aggregate", {
#
# mc_all_path <- file.path(opts$simDataPath, "mc-all", "grid", "digest.txt")
#
# mdate_original <- file.mtime(mc_all_path)
#
# parAggregateMCall(opts, nbcl = 2, mcYears = c(1,2), verbose = 0)
#
# expect_true(file.exists(mc_all_path))
# expect_false(file.mtime(mc_all_path) == mdate_original)
# expect_true(file.size(mc_all_path) > 0)
#
# mdate_original <- file.mtime(mc_all_path)
#
# parAggregateMCall(opts, nbcl = 1, mcYears = c(1,2), verbose = 0)
#
# expect_true(file.exists(mc_all_path))
# expect_false(file.mtime(mc_all_path) == mdate_original)
# expect_true(file.size(mc_all_path) > 0)
#
# })



Expand Down
Loading

0 comments on commit c2b5ff8

Please sign in to comment.