From d9e375951752144fd4b802b5dc6d9e7745b4941e Mon Sep 17 00:00:00 2001 From: aho Date: Wed, 29 Mar 2023 15:26:50 +0200 Subject: [PATCH 1/2] Change saving module test to neglect the file order --- tests/testthat/test-decadal_monthly_1.R | 10 ++++++---- tests/testthat/test-decadal_monthly_2.R | 9 ++++++--- tests/testthat/test-seasonal_monthly.R | 10 ++++++---- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/tests/testthat/test-decadal_monthly_1.R b/tests/testthat/test-decadal_monthly_1.R index b76a216c..1c0c418f 100644 --- a/tests/testthat/test-decadal_monthly_1.R +++ b/tests/testthat/test-decadal_monthly_1.R @@ -258,11 +258,12 @@ tolerance = 0.0001 test_that("4. Saving", { expect_equal( -list.files(outdir), +all(list.files(outdir) %in% c("plots", "tas_19911101.nc", "tas_19921101.nc", "tas_19931101.nc", "tas_19941101.nc", "tas_20211101.nc", "tas-obs_19911101.nc", "tas-obs_19921101.nc", "tas-obs_19931101.nc", "tas-obs_19941101.nc", "tas-percentiles_month11.nc", "tas-probs_19911101.nc", "tas-probs_19921101.nc", - "tas-probs_19931101.nc", "tas-probs_19941101.nc", "tas-probs_20211101.nc", "tas-skill_month11.nc") + "tas-probs_19931101.nc", "tas-probs_19941101.nc", "tas-probs_20211101.nc", "tas-skill_month11.nc")), +TRUE ) # open the files and check values/attributes? #expect_equal( @@ -274,9 +275,10 @@ c("plots", "tas_19911101.nc", "tas_19921101.nc", "tas_19931101.nc", "tas_1994110 test_that("5. Visualization", { expect_equal( -list.files(paste0(outdir, "/plots/")), +all(list.files(paste0(outdir, "/plots/")) %in% c("forecast_ensemble_mean.png", "forecast_most_likely_tercile.png", - "rpss.png") + "rpss.png")), +TRUE ) }) diff --git a/tests/testthat/test-decadal_monthly_2.R b/tests/testthat/test-decadal_monthly_2.R index cdab57f3..f4a60b1e 100644 --- a/tests/testthat/test-decadal_monthly_2.R +++ b/tests/testthat/test-decadal_monthly_2.R @@ -252,11 +252,12 @@ tolerance = 0.0001 test_that("4. Saving", { expect_equal( -list.files(outdir), +all(list.files(outdir) %in% c("plots", "tas_19901101.nc", "tas_19911101.nc", "tas_19921101.nc", "tas_20201101.nc", "tas_20211101.nc", "tas-obs_19901101.nc", "tas-obs_19911101.nc", "tas-obs_19921101.nc", "tas-percentiles_month11.nc", "tas-probs_19901101.nc", "tas-probs_19911101.nc", - "tas-probs_19921101.nc", "tas-probs_20201101.nc", "tas-probs_20211101.nc", "tas-skill_month11.nc") + "tas-probs_19921101.nc", "tas-probs_20201101.nc", "tas-probs_20211101.nc", "tas-skill_month11.nc")), +TRUE ) }) @@ -264,8 +265,10 @@ c("plots", "tas_19901101.nc", "tas_19911101.nc", "tas_19921101.nc", "tas_2020110 test_that("5. Visualization", { expect_equal( -list.files(paste0(outdir, "/plots/")), +all(list.files(paste0(outdir, "/plots/")) %in% c("bss10_specs.png", "enscorr_specs.png", "forecast_ensemble_mean_2020.png", "forecast_ensemble_mean_2021.png", "forecast_most_likely_tercile_2020.png", "forecast_most_likely_tercile_2021.png", "frps_specs.png", "frps.png", "rpss_specs.png") +), +TRUE ) }) diff --git a/tests/testthat/test-seasonal_monthly.R b/tests/testthat/test-seasonal_monthly.R index de03bf73..569ea4dd 100644 --- a/tests/testthat/test-seasonal_monthly.R +++ b/tests/testthat/test-seasonal_monthly.R @@ -214,22 +214,24 @@ rep(FALSE, 3) test_that("4. Saving", { expect_equal( -list.files(outdir), +all(list.files(outdir) %in% c("plots", "tas_19931101.nc", "tas_19941101.nc", "tas_19951101.nc", "tas_19961101.nc", "tas_20201101.nc", "tas-corr_month11.nc", "tas-obs_19931101.nc", "tas-obs_19941101.nc", "tas-obs_19951101.nc", "tas-obs_19961101.nc", "tas-percentiles_month11.nc", "tas-probs_19931101.nc", "tas-probs_19941101.nc", "tas-probs_19951101.nc", "tas-probs_19961101.nc", - "tas-probs_20201101.nc", "tas-skill_month11.nc") + "tas-probs_20201101.nc", "tas-skill_month11.nc")), +TRUE ) }) test_that("5. Visualization", { expect_equal( -list.files(paste0(outdir, "/plots/")), +all(list.files(paste0(outdir, "/plots/")) %in% c("crpss.png", "enscorr_specs.png", "enscorr.png", "forecast_ensemble_mean.png", - "forecast_most_likely_tercile.png", "rpss.png") + "forecast_most_likely_tercile.png", "rpss.png")), +TRUE ) }) -- GitLab From c869a3b3f7e597344263aef62eb9202a47aedeef Mon Sep 17 00:00:00 2001 From: aho Date: Wed, 29 Mar 2023 15:36:26 +0200 Subject: [PATCH 2/2] add extra check for file amount --- tests/testthat/test-decadal_monthly_1.R | 8 ++++++++ tests/testthat/test-decadal_monthly_2.R | 9 +++++++++ tests/testthat/test-seasonal_monthly.R | 8 ++++++++ 3 files changed, 25 insertions(+) diff --git a/tests/testthat/test-decadal_monthly_1.R b/tests/testthat/test-decadal_monthly_1.R index 1c0c418f..10684298 100644 --- a/tests/testthat/test-decadal_monthly_1.R +++ b/tests/testthat/test-decadal_monthly_1.R @@ -269,6 +269,10 @@ TRUE #expect_equal( #) +expect_equal( +length(list.files(outdir)), +17 +) }) @@ -280,6 +284,10 @@ c("forecast_ensemble_mean.png", "forecast_most_likely_tercile.png", "rpss.png")), TRUE ) +expect_equal( +length(list.files(paste0(outdir, "/plots/"))), +3 +) }) diff --git a/tests/testthat/test-decadal_monthly_2.R b/tests/testthat/test-decadal_monthly_2.R index f4a60b1e..d981a6de 100644 --- a/tests/testthat/test-decadal_monthly_2.R +++ b/tests/testthat/test-decadal_monthly_2.R @@ -259,6 +259,11 @@ c("plots", "tas_19901101.nc", "tas_19911101.nc", "tas_19921101.nc", "tas_2020110 "tas-probs_19921101.nc", "tas-probs_20201101.nc", "tas-probs_20211101.nc", "tas-skill_month11.nc")), TRUE ) +expect_equal( +length(list.files(outdir)), +16 +) + }) #====================================== @@ -270,6 +275,10 @@ c("bss10_specs.png", "enscorr_specs.png", "forecast_ensemble_mean_2020.png", "fo ), TRUE ) +expect_equal( +length(list.files(paste0(outdir, "/plots/"))), +9 +) }) diff --git a/tests/testthat/test-seasonal_monthly.R b/tests/testthat/test-seasonal_monthly.R index 569ea4dd..06ec3730 100644 --- a/tests/testthat/test-seasonal_monthly.R +++ b/tests/testthat/test-seasonal_monthly.R @@ -223,6 +223,10 @@ c("plots", "tas_19931101.nc", "tas_19941101.nc", "tas_19951101.nc", "tas-probs_20201101.nc", "tas-skill_month11.nc")), TRUE ) +expect_equal( +length(list.files(outdir)), +18 +) }) @@ -233,6 +237,10 @@ c("crpss.png", "enscorr_specs.png", "enscorr.png", "forecast_ensemble_mean.png", "forecast_most_likely_tercile.png", "rpss.png")), TRUE ) +expect_equal( +length(list.files(paste0(outdir, "/plots/"))), +6 +) }) -- GitLab