Skip to content
Snippets Groups Projects
Commit eaa3be0b authored by Marco Matthies's avatar Marco Matthies
Browse files

Fix failing unit tests

parent 6b3aee6e
No related branches found
No related tags found
No related merge requests found
......@@ -46,7 +46,7 @@ end
Combines all configuration options to produce a single settings dict.
Precedence: function arguments - commandline parameters - user config file - default values
"""
function getsettings(configfile::String, userparams::Dict{String,Any}=Dict())
function getsettings(configfile::String, userparams::Dict{String,Any}=Dict{String,Any}())
# read in and merge configurations from the commandline, the default config file
# and a config file supplied by the user (via the --configfile option)
defaults::Dict{String, Any} = TOML.parsefile(PARAMFILE) |> flattenTOML
......
......@@ -17,7 +17,7 @@ function initcropmodel(cropmodel::AbstractString, cropdirectory::AbstractString)
elseif cropmodel == "simple"
Tcroptype = SimpleCrop.CropType
Tcropstate = SimpleCrop.CropState
crops_almass = ALMaSS.readcropparameters(cropfile, growthfile)
crops_almass = ALMaSS.readcropparameters(cropdirectory)
crops = Dict(name => SimpleCrop.CropType(ct.name, ct.group, ct.minsowdate, ct.maxsowdate)
for (name, ct) in crops_almass)
else
......
......@@ -47,4 +47,3 @@ insectmodel = ["season", "habitat", "pesticides", "weather"] # factors affecting
[crop]
cropmodel = "almass" # crop growth model to use, "almass", "aquacrop", or "simple"
cropdirectory = "data/crops/almass" # the directory storing all data files for the selected crop model
......@@ -6,13 +6,13 @@
const TESTPARAM_ALMASS = joinpath(pkgdir(Persefone), "test", "test_parameters_almass.toml")
const TESTPARAM_SIMPLECROP = joinpath(pkgdir(Persefone), "test", "test_parameters_simplecrop.toml")
@testset for paramfile in (TESTPARAM_ALMASS, TESTPARAM_SIMPLECROP)
@testset for configfile in (TESTPARAM_ALMASS, TESTPARAM_SIMPLECROP)
@testset "Model initialisation" begin
model = initialise(paramfile)
model = initialise(; configfile)
@test model isa AgricultureModel
end
@testset "Time step" begin
model = initialise(paramfile)
model = initialise(; configfile)
stepsimulation!(model)
@test model isa AgricultureModel
end
......
......@@ -95,7 +95,7 @@ end
end
@testset "Output visualisation" begin
model = initialise(TESTPARAMETERS)
model = initialise(; configfile=TESTPARAMETERS)
stepsimulation!(model)
@test_logs((:debug, "Visualising output."),
min_level=Logging.Debug, match_mode=:any,
......
......@@ -44,8 +44,7 @@ function inittestmodel(smallmap=true)
TESTSETTINGS["core.startdate"],
TESTSETTINGS["core.enddate"])
# TODO: support other crop models besides ALMaSS
crops = Ps.ALMaSS.readcropparameters(TESTSETTINGS["crop.cropfile"],
TESTSETTINGS["crop.growthfile"])
crops = Ps.ALMaSS.readcropparameters(TESTSETTINGS["crop.cropdirectory"])
farmers = Vector{Farmer}()
farmplots = Vector{Ps.FarmPlot{Ps.ALMaSS.CropState}}()
model = AgricultureModel{Ps.ALMaSS.CropType,Ps.ALMaSS.CropState}(
......
......@@ -4,7 +4,7 @@
###
@testset "Model initialisation" begin
model = initialise(TESTPARAMETERS, params=Dict("core.visualise"=>false))
model = initialise(; configfile=TESTPARAMETERS, params=Dict{String,Any}("core.visualise"=>false))
@test typeof(model.settings) == Dict{String, Any}
@test @param(core.visualise) == false
@test model.date == Date(2022,2,1)
......@@ -48,7 +48,8 @@ end
Random.seed!(1)
rand1 = rand()
Random.seed!(1)
model = initialise(TESTPARAMETERS, 218)
model = initialise(; configfile=TESTPARAMETERS,
params=Dict{String,Any}("core.seed" => 218))
@test rand() == rand1
Random.seed!(1)
@test @param(core.seed) == 218
......
......@@ -41,5 +41,4 @@ insectmodel = ["season", "habitat", "pesticides"] # which factors affect insect
[crop]
cropmodel = "almass" # crop growth model to use, "almass", "aquacrop", or "simple"
cropfile = "crop_data_general.csv" # file with general crop parameters
growthfile = "almass_crop_growth_curves.csv" # file with crop growth parameters
\ No newline at end of file
cropdirectory = "test/cropparams-almass/" # the directory storing all data files for the selected crop model
......@@ -41,6 +41,4 @@ insectmodel = ["season", "habitat", "pesticides"] # which factors affect insect
[crop]
cropmodel = "almass" # crop growth model to use, "almass", "aquacrop", or "simple"
cropfile = "crop_data_general.csv" # file with general crop parameters
growthfile = "almass_crop_growth_curves.csv" # file with crop growth parameters
cropdirectory = "test/cropparams-almass/" # the directory storing all data files for the selected crop model
......@@ -41,7 +41,4 @@ insectmodel = ["season", "habitat", "pesticides"] # which factors affect insect
[crop]
cropmodel = "simple" # crop growth model to use, "almass", "aquacrop", or "simple"
cropfile = "crop_data_general.csv" # file with general crop parameters
# TODO: this parameter should be unnecessary, but removing it
# currently gives an error
growthfile = "almass_crop_growth_curves.csv" # file with crop growth parameters
cropdirectory = "test/cropparams-almass/" # the directory storing all data files for the selected crop model
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment