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