Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion tests/testthat/test-get_files_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ test_that("mod files do not exist in files", {
)
})

# add tests for getting a sublist according to file types
context("Getting a sublist according to file type")
test_that("finit files", {
usms_files <- get_files_list(workspace_path, file_type = c("finit"))
Expand All @@ -85,3 +84,46 @@ test_that("finit files", {
length(usms_files[["bou00t1"]][["paths"]]) == 1
)
})


context("Test if is 'exist' field consistent with files existence")
test_that("exist files", {
usms_files <- get_files_list(workspace_path, usm = "bou00t1")
expect_equal(
all(file.exists(usms_files$bou00t1$paths)),
all(usms_files$bou00t1$exist)
)
})


context("Test if usms selection is consistent")
test_that("usms match", {
usms_files <- get_files_list(workspace_path, usm = usms_list[1:3])
expect_equal(
names(usms_files),
usms_list[1:3]
)
})

context("Test if usms selection and file type are consistent")
test_that("usms match", {
usms_files <- get_files_list(
workspace_path,
usm = usms_list[1:3],
file_type = "finit"
)
expect_equal(
names(usms_files),
usms_list[1:3]
)
expect_true(
length(
grep(
pattern = "\\_ini.xml$",
x = usms_files[["bou00t1"]][["paths"]]
)
) >
0 &
length(usms_files[["bou00t1"]][["paths"]]) == 1
)
})
37 changes: 37 additions & 0 deletions tests/testthat/test-rewrite-xml-files.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
xml_path <- get_examples_path("xml")

usms_file <- file.path(xml_path, "usms.xml")
usms_list <- get_usms_list(usms_file)
sols_file <- file.path(xml_path, "sols.xml")
sols_list <- get_soils_list(sols_file)

context("Rewriting xml files")
test_that("usms.xml", {
SticsRFiles:::rewrite_usms_file(
usms_file = usms_file,
out_dir = tempdir(),
usm = usms_list[1:3]
)
expect_equal(get_usms_list(file.path(tempdir(), "usms.xml")), usms_list[1:3])
})

test_that("sols.xml", {
SticsRFiles:::rewrite_sols_file(
sols_file = sols_file,
usms_file = usms_file,
out_dir = tempdir(),
usm = usms_list[1:3]
)
expect_equal(
get_soils_list(file.path(tempdir(), "sols.xml")),
unlist(
get_param_xml(
file = usms_file,
param = "nomsol",
select = "usm",
select_value = usms_list[1:3]
),
use.names = FALSE
)
)
})
Loading