Skip to content

Commit

Permalink
removeArea() removes only expected files
Browse files Browse the repository at this point in the history
  • Loading branch information
kemihak committed Sep 15, 2023
1 parent f3ecd08 commit 3f9c9b3
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ NEW FEATURES :
* Add deduplicateScenarioBuilder() function to keep the last value if a key is duplicated in settings/scenariobuilder.dat
* Add writeIniHydro() function to make easier the edition of the input/hydro/hydro.ini file
* Call writeIniHydro() in createArea() and removeArea()
* removeArea() removes only expected files in links directory


### Breaking changes
Expand Down
2 changes: 0 additions & 2 deletions R/removeArea.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ removeArea <- function(name, opts = antaresRead::simOptions()) {
}
}
unlink(x = file.path(inputPath, "links", name), recursive = TRUE)
alllinks <- list.files(path = file.path(inputPath, "links"), pattern = name, full.names = TRUE, recursive = TRUE)
lapply(alllinks, unlink, recursive = TRUE)

# Update area list
areas <- readLines(file.path(inputPath, "areas/list.txt"))
Expand Down
73 changes: 73 additions & 0 deletions tests/testthat/test-createArea.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,76 @@ test_that("create area / st-storage in 8.6.0", {
unlink(tmp, recursive = TRUE)
})


test_that("removeArea() in 8.2.0 : check that properties.ini are all there", {

## V8
ant_version <- "8.2.0"
st_test <- paste0("my_study_820_", paste0(sample(letters,5),collapse = ""))
suppressWarnings(opts <- createStudy(path = pathstd, study_name = st_test, antares_version = ant_version))

# prop is taken cause it is a substring included in the char properties.ini
area <- "prop"
area2 <- "zone51"
area3 <- "zone52"

createArea(name = area, opts = opts)
createArea(name = area2, opts = opts)
createArea(name = area3, opts = opts)

suppressWarnings(opts <- setSimulationPath(opts$studyPath, simulation = "input"))

createLink(from = area, to = area2, opts = opts)
createLink(from = area, to = area3, opts = opts)
createLink(from = area2, to = area3, opts = opts)

opts <- setSimulationPath(opts$studyPath, simulation = "input")

removeArea(name = area, opts = opts)

links_path <- file.path(opts$inputPath, "links")
dirs_links <- list.dirs(path = links_path, full.names = TRUE, recursive = FALSE)
files_properties <- list.files(path = links_path, full.names = TRUE, recursive = TRUE, pattern = "properties.ini$")

expect_true(length(dirs_links) == length(files_properties))
expect_true(all(file.exists(file.path(dirs_links, "properties.ini"))))

unlink(opts$studyPath, recursive = TRUE)

## V7
ant_version <- "7.1.0"
st_test <- paste0("my_study_710_", paste0(sample(letters,5),collapse = ""))
suppressWarnings(opts <- createStudy(path = pathstd, study_name = st_test, antares_version = ant_version))

# prop is taken cause it is a substring included in the char properties.ini
area <- "prop"
area2 <- "zone51"
area3 <- "zone52"

createArea(name = area, opts = opts)
createArea(name = area2, opts = opts)
createArea(name = area3, opts = opts)

suppressWarnings(opts <- setSimulationPath(opts$studyPath, simulation = "input"))

createLink(from = area, to = area2, opts = opts)
createLink(from = area, to = area3, opts = opts)
createLink(from = area2, to = area3, opts = opts)

opts <- setSimulationPath(opts$studyPath, simulation = "input")

removeArea(name = area, opts = opts)

links_path <- file.path(opts$inputPath, "links")
dirs_links <- list.dirs(path = links_path, full.names = TRUE, recursive = FALSE)
files_properties <- list.files(path = links_path, full.names = TRUE, recursive = TRUE, pattern = "properties.ini$")

expect_true(length(dirs_links) == length(files_properties))
expect_true(all(file.exists(file.path(dirs_links, "properties.ini"))))

unlink(opts$studyPath, recursive = TRUE)
})




0 comments on commit 3f9c9b3

Please sign in to comment.