Skip to content

Commit

Permalink
cleaning tests
Browse files Browse the repository at this point in the history
  • Loading branch information
berthetclement committed Jun 14, 2024
1 parent ae34820 commit e8573d4
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 82 deletions.
2 changes: 1 addition & 1 deletion tests/testthat/test-.timeIdToDate.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
context(".timeIdToDate")
suppressWarnings(suppressPackageStartupMessages(require(lubridate)))
# suppressWarnings(suppressPackageStartupMessages(require(lubridate)))

describe(".timeIdToDate", {

Expand Down
96 changes: 46 additions & 50 deletions tests/testthat/test-readInputClusters.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----
Expand Down
4 changes: 0 additions & 4 deletions tests/testthat/test-readInputTS.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -122,7 +119,6 @@ test_that("readInputTs must work if we change opts$timeIdMin and opts$timeIdMax"

})

}
})

# read latest version study
Expand Down
3 changes: 0 additions & 3 deletions tests/testthat/test-readLayout.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)", {
Expand All @@ -38,7 +36,6 @@ describe("readLayout", {

file.remove(districtDefFile)
file.rename(paste0(districtDefFile, ".back"), districtDefFile)
}

})

Expand Down
3 changes: 0 additions & 3 deletions tests/testthat/test-read_optim_criteria.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ sapply(studyPathS, function(studyPath){

opts <- setSimulationPath(studyPath, 1)

if(!isH5Opts(opts))
{
describe("readOptimCriteria", {
it("returns an antaresDataTable", {
optimCrit <- readOptimCriteria(opts)
Expand All @@ -16,5 +14,4 @@ describe("readOptimCriteria", {
expect_equal(attr(optimCrit, "timeStep"), "weekly")
})
})
}
})
37 changes: 16 additions & 21 deletions tests/testthat/test-setSimulationPath.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 #####################################################

Expand Down Expand Up @@ -46,42 +46,38 @@ 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]])
}
})

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"))
})

Expand Down Expand Up @@ -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"},
Expand All @@ -131,7 +127,7 @@ test_that("select simulation with negative index", {
# }
# )
# })
#
#
# test_that("select simulation interactively (name)", {
# with_mock(
# scan = function(...) {"eco-test"},
Expand All @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit e8573d4

Please sign in to comment.