diff --git a/tests/testthat/test-get_files_list.R b/tests/testthat/test-get_files_list.R index 8c2ffda5..326d79ab 100644 --- a/tests/testthat/test-get_files_list.R +++ b/tests/testthat/test-get_files_list.R @@ -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")) @@ -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 + ) +}) diff --git a/tests/testthat/test-rewrite-xml-files.R b/tests/testthat/test-rewrite-xml-files.R new file mode 100644 index 00000000..df1f3cec --- /dev/null +++ b/tests/testthat/test-rewrite-xml-files.R @@ -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 + ) + ) +})