Skip to content

Commit

Permalink
Update removeLink() to make it compatible v8Fix conflict after pulli…
Browse files Browse the repository at this point in the history
…ng from master
  • Loading branch information
KKamel67 authored Aug 24, 2023
1 parent 452b09e commit 1f1158e
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ NEW FEATURES (Antares v8.6) :
* `deleteStudy()` no longer requires user confirmation
* `api_command_execute()` displays an error message and causes the program to stop following an http error code. The error message is completed with the API error description
* `getPlaylist()` is compatible with the new format returned by `readIniAPI()`
* `removeLink()` delete properly data for an Antares version >= 820


BUGFIXES :
Expand Down
13 changes: 11 additions & 2 deletions R/removeLink.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,18 @@ removeLink <- function(from, to, opts = antaresRead::simOptions()) {
pathIni = file.path(inputPath, "links", from, "properties.ini"),
overwrite = TRUE
)

# check version
v820 <- is_antares_v820(opts)

# remove initialization data
unlink(x = file.path(inputPath, "links", from, paste0(to, ".txt")), recursive = TRUE)
# Remove files
if (v820) {
unlink(x = file.path(inputPath, "links", from, "capacities", paste0(to, "_direct.txt")), recursive = TRUE)
unlink(x = file.path(inputPath, "links", from, "capacities", paste0(to, "_indirect.txt")), recursive = TRUE)
unlink(x = file.path(inputPath, "links", from, paste0(to, "_parameters.txt")), recursive = TRUE)
} else {
unlink(x = file.path(inputPath, "links", from, paste0(to, ".txt")), recursive = TRUE)
}

# Maj simulation
suppressWarnings({
Expand Down
68 changes: 68 additions & 0 deletions tests/testthat/test-createLink.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,71 @@ sapply(studies, function(study) {
})


test_that("removeLink() in 8.2.0 : check if the expected files are deleted/updated", {

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))
area <- "zone51"
area2 <- "aone51"
createArea(area)
createArea(area2)
opts <- setSimulationPath(opts$studyPath, simulation = "input")


# with alphabetical order
from <- min(area, area2)
to <- max(area, area2)
createLink(from = from, to = to, opts = opts)
properties_links <- readIniFile(
file = file.path(opts$inputPath, "links", from, "properties.ini")
)

expect_true(paste(c(from,to), collapse = " - ") %in% levels(antaresRead::getLinks()))
expect_true(to %in% names(properties_links))
expect_true(file.exists(file.path(opts$inputPath, "links", from, paste0(to,"_parameters.txt"))))
expect_true(file.exists(file.path(opts$inputPath, "links", from, "capacities", paste0(to,"_direct.txt"))))
expect_true(file.exists(file.path(opts$inputPath, "links", from, "capacities", paste0(to,"_indirect.txt"))))

removeLink(from = from, to = to, opts = opts)
properties_links <- readIniFile(
file = file.path(opts$inputPath, "links", from, "properties.ini")
)

expect_false(paste(c(from,to), collapse = " - ") %in% levels(antaresRead::getLinks()))
expect_false(to %in% names(properties_links))
expect_false(file.exists(file.path(opts$inputPath, "links", from, paste0(to,"_parameters.txt"))))
expect_false(file.exists(file.path(opts$inputPath, "links", from, "capacities", paste0(to,"_direct.txt"))))
expect_false(file.exists(file.path(opts$inputPath, "links", from, "capacities", paste0(to,"_indirect.txt"))))


# without alphabetical order
from <- max(area, area2)
to <- min(area, area2)
createLink(from = from, to = to, opts = opts)
properties_links <- readIniFile(
file = file.path(opts$inputPath, "links", to, "properties.ini")
)

expect_true(paste(c(to,from), collapse = " - ") %in% levels(antaresRead::getLinks()))
expect_true(from %in% names(properties_links))
expect_true(file.exists(file.path(opts$inputPath, "links", to, paste0(from,"_parameters.txt"))))
expect_true(file.exists(file.path(opts$inputPath, "links", to, "capacities", paste0(from,"_direct.txt"))))
expect_true(file.exists(file.path(opts$inputPath, "links", to, "capacities", paste0(from,"_indirect.txt"))))

removeLink(from = from, to = to, opts = opts)
properties_links <- readIniFile(
file = file.path(opts$inputPath, "links", to, "properties.ini")
)

expect_false(paste(c(to,from), collapse = " - ") %in% levels(antaresRead::getLinks()))
expect_false(from %in% names(properties_links))
expect_false(file.exists(file.path(opts$inputPath, "links", to, paste0(from,"_parameters.txt"))))
expect_false(file.exists(file.path(opts$inputPath, "links", to, "capacities", paste0(from,"_direct.txt"))))
expect_false(file.exists(file.path(opts$inputPath, "links", to, "capacities", paste0(from,"_indirect.txt"))))


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


0 comments on commit 1f1158e

Please sign in to comment.