From e8573d427c7c93bae3486d46b670a7a4ebc4291a Mon Sep 17 00:00:00 2001 From: berthetclement Date: Fri, 14 Jun 2024 13:11:35 +0200 Subject: [PATCH] cleaning tests --- tests/testthat/test-.timeIdToDate.R | 2 +- tests/testthat/test-readInputClusters.R | 96 +++++++++++------------ tests/testthat/test-readInputTS.R | 4 - tests/testthat/test-readLayout.R | 3 - tests/testthat/test-read_optim_criteria.R | 3 - tests/testthat/test-setSimulationPath.R | 37 ++++----- 6 files changed, 63 insertions(+), 82 deletions(-) diff --git a/tests/testthat/test-.timeIdToDate.R b/tests/testthat/test-.timeIdToDate.R index a55d4aad..f6ceb07e 100644 --- a/tests/testthat/test-.timeIdToDate.R +++ b/tests/testthat/test-.timeIdToDate.R @@ -1,5 +1,5 @@ context(".timeIdToDate") -suppressWarnings(suppressPackageStartupMessages(require(lubridate))) +# suppressWarnings(suppressPackageStartupMessages(require(lubridate))) describe(".timeIdToDate", { diff --git a/tests/testthat/test-readInputClusters.R b/tests/testthat/test-readInputClusters.R index 7d6c7310..e897b99d 100644 --- a/tests/testthat/test-readInputClusters.R +++ b/tests/testthat/test-readInputClusters.R @@ -5,59 +5,55 @@ sapply(studyPathS, function(studyPath){ opts <- setSimulationPath(studyPath) + test_that("Thermal availabilities importation works", { + # read /series files (default) + input <- readInputThermal(clusters = "peak_must_run_partial", + showProgress = FALSE) + expect_is(input, "antaresDataTable") + expect_gt(nrow(input), 0) + expect_equal(nrow(input) %% (24 * 7 * nweeks), 0) + }) - if(!isH5Opts(opts)){ - - test_that("Thermal availabilities importation works", { - # read /series files (default) + test_that("Thermal modulation importation works", { + # read /series + /prepro/modulation.txt input <- readInputThermal(clusters = "peak_must_run_partial", - showProgress = FALSE) - expect_is(input, "antaresDataTable") - expect_gt(nrow(input), 0) - expect_equal(nrow(input) %% (24 * 7 * nweeks), 0) - }) - - test_that("Thermal modulation importation works", { - # read /series + /prepro/modulation.txt - input <- readInputThermal(clusters = "peak_must_run_partial", - thermalModulation = TRUE, - showProgress = FALSE) - expect_is(input, "antaresDataList") - expect_is(input$thermalModulation, "antaresDataTable") - expect_gt(nrow(input$thermalModulation), 0) - expect_equal(nrow(input$thermalModulation) %% (24 * 7 * nweeks), 0) - }) - - test_that("Thermal data importation works", { - # read /series + /prepro/data.txt - input <- readInputThermal(clusters = "peak_must_run_partial", - thermalData = TRUE, - showProgress = FALSE) - expect_is(input, "antaresDataList") - expect_is(input$thermalData, "antaresDataTable") - expect_gt(nrow(input$thermalData), 0) - expect_equal(nrow(input$thermalData) %% (24 * 7 * nweeks), 0) - }) - - test_that("Wrong area", { - expect_error(readInputThermal(areas = "BAD_AREA", - clusters = "peak_must_run_partial"), - regexp = "areas are not available") - }) - - test_that("Wrong cluster", { - expect_error(readInputThermal(areas = "all", - clusters = "BAD_CLUSTER"), - regexp = "clusters are not available") - }) - - test_that("No thermal data selected", { - expect_error(readInputThermal(clusters = "peak_must_run_partial", - thermalAvailabilities = FALSE), - regexp = "one type of data should be selected") - }) + thermalModulation = TRUE, + showProgress = FALSE) + expect_is(input, "antaresDataList") + expect_is(input$thermalModulation, "antaresDataTable") + expect_gt(nrow(input$thermalModulation), 0) + expect_equal(nrow(input$thermalModulation) %% (24 * 7 * nweeks), 0) + }) + + test_that("Thermal data importation works", { + # read /series + /prepro/data.txt + input <- readInputThermal(clusters = "peak_must_run_partial", + thermalData = TRUE, + showProgress = FALSE) + expect_is(input, "antaresDataList") + expect_is(input$thermalData, "antaresDataTable") + expect_gt(nrow(input$thermalData), 0) + expect_equal(nrow(input$thermalData) %% (24 * 7 * nweeks), 0) + }) + + test_that("Wrong area", { + expect_error(readInputThermal(areas = "BAD_AREA", + clusters = "peak_must_run_partial"), + regexp = "areas are not available") + }) + + test_that("Wrong cluster", { + expect_error(readInputThermal(areas = "all", + clusters = "BAD_CLUSTER"), + regexp = "clusters are not available") + }) + + test_that("No thermal data selected", { + expect_error(readInputThermal(clusters = "peak_must_run_partial", + thermalAvailabilities = FALSE), + regexp = "one type of data should be selected") + }) - } }) # >= v870 ---- diff --git a/tests/testthat/test-readInputTS.R b/tests/testthat/test-readInputTS.R index 1fbc3e81..e9b06f9a 100644 --- a/tests/testthat/test-readInputTS.R +++ b/tests/testthat/test-readInputTS.R @@ -7,9 +7,6 @@ sapply(studyPathS, function(studyPath){ opts <- setSimulationPath(studyPath) - -if(!isH5Opts(opts)){ - test_that("Load importation works", { input <- readInputTS(load = "all", showProgress = FALSE) expect_is(input, "antaresDataTable") @@ -122,7 +119,6 @@ test_that("readInputTs must work if we change opts$timeIdMin and opts$timeIdMax" }) -} }) # read latest version study diff --git a/tests/testthat/test-readLayout.R b/tests/testthat/test-readLayout.R index 0870c4c5..eb2269e0 100644 --- a/tests/testthat/test-readLayout.R +++ b/tests/testthat/test-readLayout.R @@ -18,8 +18,6 @@ describe("readLayout", { }) - if(!isH5Opts(opts)) - { districtDefFile <- file.path(opts$inputPath, "areas/sets.ini") it("still works when there is no district (#50)", { @@ -38,7 +36,6 @@ describe("readLayout", { file.remove(districtDefFile) file.rename(paste0(districtDefFile, ".back"), districtDefFile) - } }) diff --git a/tests/testthat/test-read_optim_criteria.R b/tests/testthat/test-read_optim_criteria.R index 0c313bce..ec33f190 100644 --- a/tests/testthat/test-read_optim_criteria.R +++ b/tests/testthat/test-read_optim_criteria.R @@ -5,8 +5,6 @@ sapply(studyPathS, function(studyPath){ opts <- setSimulationPath(studyPath, 1) -if(!isH5Opts(opts)) -{ describe("readOptimCriteria", { it("returns an antaresDataTable", { optimCrit <- readOptimCriteria(opts) @@ -16,5 +14,4 @@ describe("readOptimCriteria", { expect_equal(attr(optimCrit, "timeStep"), "weekly") }) }) -} }) diff --git a/tests/testthat/test-setSimulationPath.R b/tests/testthat/test-setSimulationPath.R index eb5e21f1..c4c79d3a 100644 --- a/tests/testthat/test-setSimulationPath.R +++ b/tests/testthat/test-setSimulationPath.R @@ -5,8 +5,8 @@ context("Setup functions") # v710---- sapply(studyPathS, function(studyPath){ -suppressPackageStartupMessages(require(lubridate)) -suppressWarnings(suppressPackageStartupMessages(require(data.table))) +# suppressPackageStartupMessages(require(lubridate)) +# suppressWarnings(suppressPackageStartupMessages(require(data.table))) # Reading of study options ##################################################### @@ -46,21 +46,17 @@ test_that("R option 'antares' is set", { opts <- setSimulationPath(studyPath) expect_identical(opts, getOption("antares")) }) -opts <- setSimulationPath(studyPath) -if(!isH5Opts(opts)) -{ + test_that("setSimulationPath fails if path is not an antares Ouput directory", { expect_error(setSimulationPath(file.path(studyPath, "../.."))) }) -} opts <- setSimulationPath(studyPath) -if(!isH5Opts(opts)) -{ + test_that("setSimulationPath can read info in input", { opts <- setSimulationPath(studyPath, "input") for (v in c("studyName", "areaList", "districtList", "linkList", - "areasWithClusters", "timeIdMin", "timeIdMax", "start", + "areasWithClusters", "timeIdMin", "timeIdMax", "start", "firstWeekday")) { expect_equal(opts[[v]], trueOpts[[v]]) } @@ -68,20 +64,20 @@ test_that("setSimulationPath can read info in input", { test_that("setSimulationPath works if synthesis and some MC years are not saved (#31)", { opts <- setSimulationPath(studyPath) - - file.rename(file.path(opts$simDataPath, "mc-all"), + + file.rename(file.path(opts$simDataPath, "mc-all"), file.path(opts$simDataPath, "mc-all_back")) - file.rename(file.path(opts$simDataPath, "mc-ind/00001"), + file.rename(file.path(opts$simDataPath, "mc-ind/00001"), file.path(opts$simDataPath, "mc-ind/00001_back")) - + opts <- setSimulationPath(studyPath) trueOpts$synthesis <- FALSE trueOpts$mcYears <- 2 expect_equal(opts[names(trueOpts)], trueOpts) - - file.rename(file.path(opts$simDataPath, "mc-all_back"), + + file.rename(file.path(opts$simDataPath, "mc-all_back"), file.path(opts$simDataPath, "mc-all")) - file.rename(file.path(opts$simDataPath, "mc-ind/00001_back"), + file.rename(file.path(opts$simDataPath, "mc-ind/00001_back"), file.path(opts$simDataPath, "mc-ind/00001")) }) @@ -121,7 +117,7 @@ test_that("select simulation with negative index", { opts <- setSimulationPath(studyPath, -2) expect_equal(opts[names(trueOpts)], trueOpts) }) -# +# # test_that("select simulation interactively (number)", { # with_mock( # `base::scan` = function(...) {"1"}, @@ -131,7 +127,7 @@ test_that("select simulation with negative index", { # } # ) # }) -# +# # test_that("select simulation interactively (name)", { # with_mock( # scan = function(...) {"eco-test"}, @@ -156,12 +152,12 @@ describe("No simulation", { it("Error if the user tries to read simulation results", { expect_error(setSimulationPath(studyPath, 1)) }) - + it("User can read input data", { expect_silent(opts <- setSimulationPath(studyPath, 0)) expect_equal(opts$mode, "Input") }) - + it("Read input data by default", { expect_silent(opts <- setSimulationPath(studyPath)) expect_equal(opts$mode, "Input") @@ -176,7 +172,6 @@ test_that("Folder 'maps' is not interpreted as a study (#49)", { expect_silent(opts <- setSimulationPath(studyPath, -1)) }) -} test_that("No meta info areas with a ST cluster < 860", { opts <- setSimulationPath(studyPath, "input")