Commit 344db094 authored by Dorchies David's avatar Dorchies David
Browse files

feat(loadConfig): rsic2 configuration handling

Fix #1
Showing with 115 additions and 0 deletions
+115 -0
...@@ -10,7 +10,13 @@ License: What license is it under? ...@@ -10,7 +10,13 @@ License: What license is it under?
Encoding: UTF-8 Encoding: UTF-8
LazyData: true LazyData: true
Suggests: Suggests:
R.utils,
RandomFields,
testthat (>= 3.0.0) testthat (>= 3.0.0)
Config/testthat/edition: 3 Config/testthat/edition: 3
Depends: Depends:
R (>= 2.10) R (>= 2.10)
RoxygenNote: 7.1.1
Roxygen: list(markdown = TRUE)
Imports:
terra
NAMESPACE 0 → 100644
# Generated by roxygen2: do not edit by hand
export(loadConfig)
default:
sic:
path: "*** The path of your installation of SIC should be defined ***"
edisic: "exe/EdiSIC.exe"
talweg: "exe/TALWEG.exe"
fluvia: "exe/FLUVIA.exe"
sirene: "exe/SIRENE.exe"
export: "exe/SicExport.exe"
fortran:
prms:
INTERF: "0"
project:
path: "*** The path of your XML project file should be defined ***"
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/loadConfig.R
\name{loadConfig}
\alias{loadConfig}
\title{Read default configuration of the package and complete it with eventual user config}
\usage{
loadConfig(
sic_path = NULL,
xml_path = NULL,
userFile = "config.yml",
pathDefaultCfg = system.file("config.yml", package = "rsic2")
)
}
\arguments{
\item{userFile}{location of the user config YML file}
\item{pathDefaultCfg}{The location of the default configuration (located in "inst/config.yml" of the package by default)}
}
\value{
A configuration as it is returned by \link[config:get]{config::get}.
Configuration of RSIC2 as the following structure:
\itemize{
\item sic
\itemize{
\item path: Path of local SIC installation (should be defined by \code{sic_path} parameter or in the user config file)
\item edisic: sub-path to EdiSIC program
\item talweg: sub-path to TALWEG program
\item fluvia: sub-path to FLUVIA program
\item sirene: sub-path to SIRENE program
\item export: sub-path to SicExport program
\item fortran:
\itemize{
\item prms:
\itemize{
\item INTERF: default \code{INTERF} parameter injected in command line arguments of TALWEG, FLUVIA, SIRENE
}
}
}
\item project
\itemize{
\item path: Path to the XML project file (should be defined by \code{xml_path} parameter or in the user config file)
}
}
}
\description{
Read default configuration of the package and complete it with eventual user config
}
\examples{
library(sic2)
sic_path <- tempdir(check = TRUE)
xml_path <- R.utils::tmpfile()
cfg <- loadConfig(sic_path, xml_path)
str(cfg)
}
...@@ -18,3 +18,4 @@ StripTrailingWhitespace: Yes ...@@ -18,3 +18,4 @@ StripTrailingWhitespace: Yes
BuildType: Package BuildType: Package
PackageUseDevtools: Yes PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace
library(testthat)
library(rsic2)
test_check("rsic2")
test_that("incomplete config throw an error", {
expect_error(loadConfig())
})
sic_path <- tempdir(check = TRUE)
xml_path <- tempfile(fileext = ".xml")
writeLines("<XML>Fake project</XML>", xml_path)
test_that("Wrong SIC path throw an error", {
expect_error(loadConfig(file.path(sic_path, "fake"), xml_path))
})
test_that("Wrong XML path throw an error", {
expect_error(loadConfig(sic_path, file.path(xml_path, "fake.xml")))
})
test_that("SIC and XML paths injected by parameters should be provided in cfg", {
cfg <- loadConfig(sic_path, xml_path)
expect_equal(cfg$sic$path, sic_path)
expect_equal(cfg$project$path, xml_path)
})
test_that("SIC and XML paths injected by user yml file should be provided in cfg", {
tmpCfgPath <- tempfile(fileext = ".yml")
ymlCfg <- list(default = list(
sic = list(path = sic_path),
project = list(path = xml_path)
))
yaml::write_yaml(ymlCfg, tmpCfgPath)
cfg <- loadConfig(userFile = tmpCfgPath)
expect_equal(cfg$sic$path, sic_path)
expect_equal(cfg$project$path, xml_path)
})
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment