From 6acfa2e451bb0c88d1b3fdf6119870e564c77ce1 Mon Sep 17 00:00:00 2001 From: simon-smart88 Date: Thu, 25 Jul 2024 10:13:47 +0100 Subject: [PATCH] see whether errors are caused by the file already existing --- tests/testthat.R | 2 +- tests/testthat/test-agg_uniform.R | 6 ++++++ tests/testthat/test-agg_upload.R | 6 ++++++ tests/testthat/test-agg_worldpop.R | 6 ++++++ tests/testthat/test-cov_access.R | 6 ++++++ tests/testthat/test-cov_bioclim.R | 6 ++++++ tests/testthat/test-cov_landuse.R | 6 ++++++ tests/testthat/test-cov_upload.R | 12 +++++++++++- tests/testthat/test-resp_combine.R | 6 ++++++ tests/testthat/test-resp_download.R | 6 ++++++ tests/testthat/test-resp_edit.R | 6 ++++++ tests/testthat/test-resp_simplify.R | 6 ++++++ tests/testthat/test-save_load.R | 21 +++++++++++++++++++++ 13 files changed, 93 insertions(+), 2 deletions(-) diff --git a/tests/testthat.R b/tests/testthat.R index 09ebe9a..077f96a 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -3,4 +3,4 @@ library(testthat) library(disagapp) library(shinytest2) -#test_check("disagapp") +test_check("disagapp") diff --git a/tests/testthat/test-agg_uniform.R b/tests/testthat/test-agg_uniform.R index 12ef446..d7c66be 100644 --- a/tests/testthat/test-agg_uniform.R +++ b/tests/testthat/test-agg_uniform.R @@ -19,6 +19,12 @@ test_that("{shinytest2} recording: e2e_agg_uniform", { app$click("agg_uniform-run") + if (is_ci){ + save_path <- tempfile(fileext = ".rds") + } else { + save_path <- "~/temprds/saved_file.rds" + } + app$set_inputs(main = "Save") save_file <- app$get_download("core_save-save_session", filename = save_path) common <- readRDS(save_file) diff --git a/tests/testthat/test-agg_upload.R b/tests/testthat/test-agg_upload.R index 69dbbfd..2ba3ee7 100644 --- a/tests/testthat/test-agg_upload.R +++ b/tests/testthat/test-agg_upload.R @@ -24,6 +24,12 @@ test_that("{shinytest2} recording: e2e_agg_upload", { app$upload_file("agg_upload-agg" = aggdf$datapath) app$click("agg_upload-run") + if (is_ci){ + save_path <- tempfile(fileext = ".rds") + } else { + save_path <- "~/temprds/saved_file.rds" + } + app$set_inputs(main = "Save") save_file <- app$get_download("core_save-save_session", filename = save_path) common <- readRDS(save_file) diff --git a/tests/testthat/test-agg_worldpop.R b/tests/testthat/test-agg_worldpop.R index a9dc584..a35feab 100644 --- a/tests/testthat/test-agg_worldpop.R +++ b/tests/testthat/test-agg_worldpop.R @@ -56,6 +56,12 @@ test_that("{shinytest2} recording: e2e_agg_worldpop", { app$click(selector = "#agg_worldpop-run") app$wait_for_value(input = "agg_worldpop-complete") + if (is_ci){ + save_path <- tempfile(fileext = ".rds") + } else { + save_path <- "~/temprds/saved_file.rds" + } + app$set_inputs(main = "Save") save_file <- app$get_download("core_save-save_session", filename = save_path) common <- readRDS(save_file) diff --git a/tests/testthat/test-cov_access.R b/tests/testthat/test-cov_access.R index d9e5490..7af9e76 100644 --- a/tests/testthat/test-cov_access.R +++ b/tests/testthat/test-cov_access.R @@ -22,6 +22,12 @@ test_that("{shinytest2} recording: e2e_cov_access", { app$click(selector = "#cov_access-run") app$wait_for_value(input = "cov_access-complete") + if (is_ci){ + save_path <- tempfile(fileext = ".rds") + } else { + save_path <- "~/temprds/saved_file.rds" + } + app$set_inputs(main = "Save") save_file <- app$get_download("core_save-save_session", filename = save_path) common <- readRDS(save_file) diff --git a/tests/testthat/test-cov_bioclim.R b/tests/testthat/test-cov_bioclim.R index a2c2689..f5a1995 100644 --- a/tests/testthat/test-cov_bioclim.R +++ b/tests/testthat/test-cov_bioclim.R @@ -48,6 +48,12 @@ test_that("{shinytest2} recording: e2e_cov_bioclim", { app$click(selector = "#cov_bioclim-run") app$wait_for_value(input = "cov_bioclim-complete") + if (is_ci){ + save_path <- tempfile(fileext = ".rds") + } else { + save_path <- "~/temprds/saved_file.rds" + } + app$set_inputs(main = "Save") save_file <- app$get_download("core_save-save_session", filename = save_path) common <- readRDS(save_file) diff --git a/tests/testthat/test-cov_landuse.R b/tests/testthat/test-cov_landuse.R index 14d71a3..7616dbc 100644 --- a/tests/testthat/test-cov_landuse.R +++ b/tests/testthat/test-cov_landuse.R @@ -37,6 +37,12 @@ test_that("{shinytest2} recording: e2e_cov_landuse", { common <- app$get_value(export = "common") expect_is(common$shape, "sf") + if (is_ci){ + save_path <- tempfile(fileext = ".rds") + } else { + save_path <- "~/temprds/saved_file.rds" + } + app$set_inputs(main = "Save") save_file <- app$get_download("core_save-save_session", filename = save_path) common <- readRDS(save_file) diff --git a/tests/testthat/test-cov_upload.R b/tests/testthat/test-cov_upload.R index b4ffef2..b3e6a5f 100644 --- a/tests/testthat/test-cov_upload.R +++ b/tests/testthat/test-cov_upload.R @@ -38,7 +38,17 @@ test_that("{shinytest2} recording: e2e_cov_upload", { app$upload_file("cov_upload-cov" = covdf$datapath) app$click("cov_upload-run") - common <- app$get_value(export = "common") + + if (is_ci){ + save_path <- tempfile(fileext = ".rds") + } else { + save_path <- "~/temprds/saved_file.rds" + } + + app$set_inputs(main = "Save") + save_file <- app$get_download("core_save-save_session", filename = save_path) + common <- readRDS(save_file) + common$covs <- unwrap_terra(common$covs) expect_is(common$covs[[1]], "SpatRaster") expect_equal(length(common$covs), 4) }) diff --git a/tests/testthat/test-resp_combine.R b/tests/testthat/test-resp_combine.R index 680e72a..865861c 100644 --- a/tests/testthat/test-resp_combine.R +++ b/tests/testthat/test-resp_combine.R @@ -24,6 +24,12 @@ test_that("{shinytest2} recording: e2e_resp_combine", { app$set_inputs("resp_combine-shape_area_column" = shape_area_column) app$click("resp_combine-run") + if (is_ci){ + save_path <- tempfile(fileext = ".rds") + } else { + save_path <- "~/temprds/saved_file.rds" + } + app$set_inputs(main = "Save") save_file <- app$get_download("core_save-save_session", filename = save_path) common <- readRDS(save_file) diff --git a/tests/testthat/test-resp_download.R b/tests/testthat/test-resp_download.R index 312647b..1d3e539 100644 --- a/tests/testthat/test-resp_download.R +++ b/tests/testthat/test-resp_download.R @@ -53,6 +53,12 @@ test_that("{shinytest2} recording: e2e_resp_download", { app$set_inputs("resp_download-admin" = "ADM1") app$click("resp_download-run") + if (is_ci){ + save_path <- tempfile(fileext = ".rds") + } else { + save_path <- "~/temprds/saved_file.rds" + } + app$set_inputs(main = "Save") save_file <- app$get_download("core_save-save_session", filename = save_path) common <- readRDS(save_file) diff --git a/tests/testthat/test-resp_edit.R b/tests/testthat/test-resp_edit.R index e09ddd0..d1e4d10 100644 --- a/tests/testthat/test-resp_edit.R +++ b/tests/testthat/test-resp_edit.R @@ -23,6 +23,12 @@ test_that("{shinytest2} recording: e2e_resp_shape", { app$set_inputs("resp_edit-type" = "outside") app$click("resp_edit-run") + if (is_ci){ + save_path <- tempfile(fileext = ".rds") + } else { + save_path <- "~/temprds/saved_file.rds" + } + app$set_inputs(main = "Save") save_file <- app$get_download("core_save-save_session", filename = save_path) common <- readRDS(save_file) diff --git a/tests/testthat/test-resp_simplify.R b/tests/testthat/test-resp_simplify.R index 33d72d5..850e28e 100644 --- a/tests/testthat/test-resp_simplify.R +++ b/tests/testthat/test-resp_simplify.R @@ -21,6 +21,12 @@ test_that("{shinytest2} recording: e2e_resp_simplify", { app$set_inputs("resp_simplify-distance" = 1000) app$click("resp_simplify-run") + if (is_ci){ + save_path <- tempfile(fileext = ".rds") + } else { + save_path <- "~/temprds/saved_file.rds" + } + app$set_inputs(main = "Save") save_file <- app$get_download("core_save-save_session", filename = save_path) common <- readRDS(save_file) diff --git a/tests/testthat/test-save_load.R b/tests/testthat/test-save_load.R index 7052ca7..c019e95 100644 --- a/tests/testthat/test-save_load.R +++ b/tests/testthat/test-save_load.R @@ -2,6 +2,13 @@ test_that("{shinytest2} recording: e2e_empty_save", { app <- shinytest2::AppDriver$new(app_dir = system.file("shiny", package = "disagapp"), name = "e2e_empty_save") app$set_inputs(tabs = "resp") app$set_inputs(main = "Save") + + if (is_ci){ + save_path <- tempfile(fileext = ".rds") + } else { + save_path <- "~/temprds/saved_file.rds" + } + save_file <- app$get_download("core_save-save_session", filename = save_path) common <- readRDS(save_file) expect_length(common$covs, 0) @@ -25,6 +32,13 @@ test_that("{shinytest2} recording: e2e_shape_save", { app$set_inputs("resp_shape-resp_var" = "inc") app$click("resp_shape-run") app$set_inputs(main = "Save") + + if (is_ci){ + save_path <- tempfile(fileext = ".rds") + } else { + save_path <- "~/temprds/saved_file.rds" + } + save_file <- app$get_download("core_save-save_session", filename = save_path) common <- readRDS(save_file) expect_is(common$shape, "sf") @@ -56,6 +70,13 @@ test_that("{shinytest2} recording: e2e_settings_save", { app$set_inputs("agg_worldpop-country" = "Liechtenstein") app$set_inputs("agg_worldpop-resolution" = "100m") app$set_inputs(main = "Save") + + if (is_ci){ + save_path <- tempfile(fileext = ".rds") + } else { + save_path <- "~/temprds/saved_file.rds" + } + save_file <- app$get_download("core_save-save_session", filename = save_path) common <- readRDS(save_file) expect_equal(common$state$resp_example$dataset, "scot")