diff --git a/test/io_tests.jl b/test/io_tests.jl index c7d10ceba58f7060c186f226a34e0c0fb71427df..19a66376f75a37c2133196b038c74566991e1f57 100644 --- a/test/io_tests.jl +++ b/test/io_tests.jl @@ -3,4 +3,27 @@ ### This tests the core input and output functions. ### -#TODO +@testset "Model configuration" begin + # `test_parameters.toml` is read in in `runtests.jl` + @test param("core.configfile") == TESTPARAMETERS + @test param("core.startdate") == Date(2020, 1, 1) + @test param("nature.targetspecies") == ["Wolpertinger", "Wyvern"] + #TODO test commandline parameters +end + +@testset "Output functions" begin + # test that the output directory is created with all files + logstring = "Setting up output directory results_testsuite_$(Dates.today())_s1" + @test_logs (:info, logstring) Persephone.setupdatadir() + @test isdir(param("core.outdir")) + @test isfile(joinpath(param("core.outdir"), param("core.landcovermap"))) + @test isfile(joinpath(param("core.outdir"), param("core.farmfieldsmap"))) + @test isfile(joinpath(param("core.outdir"), param("core.configfile"))) + @test isfile(joinpath(param("core.outdir"), Persephone.LOGFILE)) + # check whether the overwrite warning/protection works + logstring = "Overwriting existing output directory $(param("core.outdir"))." + @test_logs (:warn, logstring) match_mode=:any Persephone.setupdatadir() + #TODO test overwrite protection (requires parameter mutability) + rm(param("core.outdir"), force=true, recursive=true) + #TODO test that creating a DataOutput works, and outputs data with the required frequency +end diff --git a/test/runtests.jl b/test/runtests.jl index 5af8e83a7c9962701d96ab17d9fedbf11b2e448c..e185c554be424dbe2be3c4eb9cee76a0ea78a341 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -9,10 +9,13 @@ Pkg.activate("..") using Persephone using Test using Random +using Dates using Agents +const TESTPARAMETERS = "test_parameters.toml" + @testset "Persephone Tests" begin - Persephone.initsettings("test_parameters.toml") + Persephone.initsettings(TESTPARAMETERS) @testset "Core model" begin include("io_tests.jl") include("landscape_tests.jl") diff --git a/test/test_parameters.toml b/test/test_parameters.toml index f03b079b06ba7f6a9189ea0641b522af9c5f2262..464a6a9bcc194e610b9afa093c1a691ee4f7d802 100644 --- a/test/test_parameters.toml +++ b/test/test_parameters.toml @@ -8,7 +8,8 @@ configfile = "test_parameters.toml" # location of the configuration file landcovermap = "landcover_jena.tif" # location of the landcover map farmfieldsmap = "fields_jena.tif" # location of the field geometry map outdir = "results_testsuite" # location and name of the output folder -loglevel = "debug" # verbosity level: "debug", "info", "quiet" +overwrite = true # overwrite the output directory? (true/false/"ask") +loglevel = "info" # verbosity level: "debug", "info", "quiet" seed = 1 # seed value for the RNG (0 -> random value) # dates to start and end the simulation startdate = 2020-01-01