### Persefone.jl - a model of agricultural landscapes and ecosystems in Europe. ### ### This is the top-level file of the Persefone test suite. Execute this to run all tests. ### using Pkg Pkg.activate("..") using Dates using DataFrames using Logging using LoggingExtras using Persefone using Random using StableRNGs using Test const Ps = Persefone const TESTPARAMETERS = joinpath(pkgdir(Persefone), "test/test_parameters.toml") const TESTSETTINGS = Ps.getsettings(TESTPARAMETERS) import Unitful: @u_str, cm, m, km, ha, mg, g, kg, Length, Area, Mass const m² = m^2 const km² = km^2 """ inittestmodel(smallmap=true) Initialise an SimulationModel for testing purposes. `smallmap`: use a hypothetical small landscape rather than a real one? """ function inittestmodel(smallmap=true) if smallmap landscape = smalltestlandscape() else landscape = Ps.initlandscape(TESTSETTINGS["world.mapdirectory"], TESTSETTINGS["world.landcovermap"], TESTSETTINGS["world.farmfieldsmap"], TESTSETTINGS["world.soiltypesmap"]) end weather = Ps.initweather(joinpath(TESTSETTINGS["world.mapdirectory"], TESTSETTINGS["world.weatherfile"]), TESTSETTINGS["core.startdate"], TESTSETTINGS["core.enddate"]) # TODO: support other crop models besides ALMaSS crops = Ps.ALMaSS.readcropparameters(TESTSETTINGS["crop.cropdirectory"]) model = AgricultureModel{Ps.ALMaSS.CropType,Ps.ALMaSS.CropState}(; settings = copy(TESTSETTINGS), rng = StableRNG(TESTSETTINGS["core.seed"]), logger = global_logger(), date = TESTSETTINGS["core.startdate"], landscape, weather, crops ) model end """ smalltestlandscape() Create a 8x8 landscape with five land cover types for testing: A A A A A A A A A A A A A A A A A A A A A A A A A A A A A W A A F F G G G G G G F F G G G G G G F F G G G G G G B B B B B B B B """ function smalltestlandscape() landscape = Matrix{Pixel}(undef, 8, 8) for x in 1:8 for y in 1:8 (y in (1:4)) ? lc = Ps.agriculture : (x in (1:2)) ? lc = Ps.forest : (y == 8) ? lc = Ps.builtup : lc = Ps.grass landscape[x,y] = Pixel(lc) end end landscape[6,4] = Pixel(Ps.water, 0) landscape end @testset "Persefone Tests" begin @testset "Core model" begin include("io_tests.jl") include("landscape_tests.jl") include("simulation_tests.jl") end @testset "Weather model" begin include("weather_tests.jl") end @testset "Nature model" begin include("nature_tests.jl") end @testset "Crop growth model" begin include("crop_tests.jl") end @testset "Farm model" begin include("farm_tests.jl") end rm(TESTSETTINGS["core.outdir"], force=true, recursive=true) end # NOTE: Due to an issue with Julia (https://github.com/JuliaLang/julia/issues/48456), # whenever we are using `@test_logs` with a function that takes a model object, we have # to wrap that model object in `Ps.withtestlogger()`. (For an example, see the "Model # simulation" testset in simulation_tests.jl.)