@@ -29,3 +29,99 @@ test_that("`do_conversions` able to call met.process if the input tag has met, u
2929 expect_true(file.exists(file.path(getwd(), " pecan.METProcess.xml" )))
3030 })
3131})
32+
33+ test_that(" `do_conversions` silently converts character inputs to NULL" , {
34+ withr :: with_tempdir({
35+ settings <- list (
36+ host = list (name = " localhost" ),
37+ outdir = getwd(),
38+ database = list (dbfiles = getwd()),
39+ run = list (inputs = " some_legacy_string" )
40+ )
41+ # Should not error, and inputs should be treated as NULL (loop skipped)
42+ ret <- do_conversions(settings )
43+ # needsave stays FALSE, no METProcess.xml written, settings returned as-is
44+ expect_false(file.exists(file.path(getwd(), " pecan.METProcess.xml" )))
45+ })
46+ })
47+
48+ test_that(" `do_conversions` skips input when path exists and force is NULL" , {
49+ withr :: with_tempdir({
50+ mocked_met <- mockery :: mock(list (path = " should_not_be_called" ))
51+ mockery :: stub(do_conversions , " PEcAn.data.atmosphere::met.process" , mocked_met )
52+ settings <- list (
53+ host = list (name = " localhost" ),
54+ database = list (dbfiles = getwd()),
55+ outdir = getwd(),
56+ run = list (
57+ site = list (id = 0 ),
58+ inputs = list (met = list (path = " /existing/path" )) # path exists, force is NULL
59+ )
60+ )
61+ ret <- do_conversions(settings )
62+ # met.process should NOT have been called
63+ mockery :: expect_called(mocked_met , 0 )
64+ # path should be unchanged
65+ expect_equal(ret $ run $ inputs $ met $ path , " /existing/path" )
66+ # needsave FALSE so no xml written
67+ expect_false(file.exists(file.path(getwd(), " pecan.METProcess.xml" )))
68+ })
69+ })
70+
71+ test_that(" `do_conversions` does NOT skip input when path exists but force is set" , {
72+ withr :: with_tempdir({
73+ mocked_met <- mockery :: mock(list (path = " new_path" ))
74+ mockery :: stub(do_conversions , " PEcAn.data.atmosphere::met.process" , mocked_met )
75+ mockery :: stub(do_conversions , " PEcAn.utils::status.check" , mockery :: mock(0 ))
76+ settings <- list (
77+ host = list (name = " localhost" ),
78+ database = list (dbfiles = getwd()),
79+ outdir = getwd(),
80+ run = list (
81+ site = list (id = 0 ),
82+ inputs = list (met = list (path = " /existing/path" , force = TRUE ))
83+ )
84+ )
85+ ret <- do_conversions(settings )
86+ # met.process SHOULD have been called because force is set
87+ mockery :: expect_called(mocked_met , 1 )
88+ expect_equal(ret $ run $ inputs $ met $ path , " new_path" )
89+ })
90+ })
91+
92+ test_that(" `do_conversions` returns settings unchanged when inputs is empty list" , {
93+ withr :: with_tempdir({
94+ settings <- list (
95+ host = list (name = " localhost" ),
96+ outdir = getwd(),
97+ database = list (dbfiles = getwd()),
98+ run = list (inputs = list ())
99+ )
100+ ret <- do_conversions(settings )
101+ # Empty inputs — needsave stays FALSE, no xml written
102+ expect_false(file.exists(file.path(getwd(), " pecan.METProcess.xml" )))
103+ expect_equal(ret $ run $ inputs , list ())
104+ })
105+ })
106+
107+ test_that(" `do_conversions` reads pecan.METProcess.xml when needsave is FALSE and file exists" , {
108+ withr :: with_tempdir({
109+ # Write a settings xml with a sentinel value
110+ xml_path <- file.path(getwd(), " pecan.METProcess.xml" )
111+ writeLines(
112+ " <pecan>
113+ <outdir>sentinel_value</outdir>
114+ </pecan>" ,
115+ xml_path
116+ )
117+ settings <- list (
118+ host = list (name = " localhost" ),
119+ outdir = getwd(),
120+ database = list (dbfiles = getwd()),
121+ run = list (inputs = list ()) # empty inputs → needsave stays FALSE
122+ )
123+ ret <- do_conversions(settings )
124+ # Should have read from xml and returned the sentinel value
125+ expect_equal(ret $ outdir , " sentinel_value" )
126+ })
127+ })
0 commit comments