diff --git a/DESCRIPTION b/DESCRIPTION index 9f6906c5..85ceba5d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -63,7 +63,8 @@ VignetteBuilder: knitr Config/roxygen2/version: 8.1.0 Config/testthat/edition: 3 -Config/testthat/parallel: false +Config/testthat/parallel: true +Config/testthat/start-first: save_all_plots*, convert_output* Encoding: UTF-8 Language: en-US LazyData: true diff --git a/R/convert_output.R b/R/convert_output.R index 9671f705..b0ad1e3e 100644 --- a/R/convert_output.R +++ b/R/convert_output.R @@ -439,7 +439,7 @@ convert_output <- function( for (i in intersect(tolower(fleet_names), colnames(df3))) { col_name <- glue::glue("exploitation_{i}") df3 <- df3 |> - dplyr::rename(!!col_name := i) + dplyr::rename(!!col_name := dplyr::all_of(i)) } } } @@ -488,7 +488,7 @@ convert_output <- function( if (length(err_col_id) > 0) { uncert_name <- stringr::str_extract(err_col_id, paste0(errors, collapse = "|")) df3 <- df3 |> - dplyr::rename(!!uncert_name := err_col_id) + dplyr::rename(!!uncert_name := dplyr::all_of(err_col_id)) } df4 <- df3 |> tidyr::pivot_longer( diff --git a/R/table_total_catch.R b/R/table_total_catch.R index 8c1f79a5..bb1f3529 100644 --- a/R/table_total_catch.R +++ b/R/table_total_catch.R @@ -116,7 +116,7 @@ table_total_catch <- function( } catch <- catch |> - dplyr::select(-cols_to_remove) + dplyr::select(-dplyr::all_of(cols_to_remove)) if ("uncertainty" %in% colnames(catch)) { catch <- catch |> diff --git a/tests/testthat/helper-test_functions.R b/tests/testthat/helper-test_functions.R new file mode 100644 index 00000000..78688e07 --- /dev/null +++ b/tests/testthat/helper-test_functions.R @@ -0,0 +1,32 @@ +#' Check for the existence and remove .rda files from test environment +#' +#' Checks for the existence of `dir` and `filename` as well as the +#' existence of "captions_alt_text.csv" and "key_quantities.csv". +#' Files are removed upon completion of checks. +#' +#' For testing only. +#' +#' @param filename String. filename of figure/table .rda file +#' @param dir String. directory where filename exists +#' @param figs_or_tables String. whether check for a "figures" or "tables" internal directory +#' +#' DEFAULT: "figures" +#' +check_and_remove_tmp_files <- function(filename, dir=fs::path(getwd()), figs_or_tables="figures"){ + # expect that both figures dir and the abundance_at_age_figure.rda file exist + expect_true(dir.exists(dir)) # this check needs to exist in case save dir isnt getwd() + expect_true(dir.exists(fs::path(dir, figs_or_tables))) + expect_true(file.exists(fs::path(dir, figs_or_tables, filename))) + + # erase temporary testing files + captions_file <- fs::path(dir, "captions_alt_text.csv") + keyquant_file <- fs::path(dir, "key_quantities.csv") + + if(fs::file_exists(captions_file)) + fs::file_delete(captions_file) + + if(fs::file_exists(keyquant_file)) + fs::file_delete(keyquant_file) + + unlink(fs::path(dir, figs_or_tables), recursive = T) +} diff --git a/tests/testthat/test-convert_output.R b/tests/testthat/test-convert_output.R index 1a546672..7d74a56b 100644 --- a/tests/testthat/test-convert_output.R +++ b/tests/testthat/test-convert_output.R @@ -6,11 +6,21 @@ test_that("convert_output works for SS3", { recursive = FALSE ) + model_names <- c( + "Hake_2018", + "platoons", + "Empirical_wtatage_Age_Selex", + "three_area_nomove", + "BigSkate_2019" + ) + + models_to_test <- all_models[grepl(paste0(model_names, collapse="|"), all_models)] + # Loop through each model directory and check convert_output function - for (i in seq_along(all_models)) { + for (i in seq_along(models_to_test)) { # Ensure no errors occur while converting SS3 output expect_no_error(result <- convert_output( - file = file.path(all_models[i], "Report.sso") + file = file.path(models_to_test[i], "Report.sso") )) # Check that the result has exactly 35 columns diff --git a/tests/testthat/test-plot_abundance_at_age.R b/tests/testthat/test-plot_abundance_at_age.R index 8acaca51..64381c1e 100644 --- a/tests/testthat/test-plot_abundance_at_age.R +++ b/tests/testthat/test-plot_abundance_at_age.R @@ -1,7 +1,10 @@ test_that("plot_abundance_at_age generates plots without errors", { # expect error-free plot with minimal arguments expect_no_error( - plot_abundance_at_age(stockplotr::example_data) + plot_abundance_at_age( + stockplotr::example_data, + interactive = FALSE + ) ) # expect error-free plot with many arguments @@ -11,6 +14,7 @@ test_that("plot_abundance_at_age generates plots without errors", { facet = "area", unit_label = "fish", scale_amount = 1000, + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ) @@ -22,6 +26,7 @@ test_that("plot_abundance_at_age generates plots without errors", { stockplotr::example_data, unit_label = "fish", scale_amount = 1, + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ), @@ -29,23 +34,18 @@ test_that("plot_abundance_at_age generates plots without errors", { ) }) -test_that("rda file made when indicated", { - # export rda - plot_abundance_at_age( - stockplotr::example_data, - figures_dir = getwd(), - make_rda = TRUE - ) - - # expect that both figures dir and the abundance_at_age_figure.rda file exist - expect_true(dir.exists(fs::path(getwd(), "figures"))) - expect_true(file.exists(fs::path(getwd(), "figures", "abundance_at_age_figure.rda"))) +# test_that("rda file made when indicated", { +# # export rda +# plot_abundance_at_age( +# stockplotr::example_data, +# figures_dir = getwd(), +# interactive = FALSE, +# make_rda = TRUE +# ) - # erase temporary testing files - file.remove(fs::path(getwd(), "captions_alt_text.csv")) - file.remove(fs::path(getwd(), "key_quantities.csv")) - unlink(fs::path(getwd(), "figures"), recursive = T) -}) +# # expect that both figures dir and the abundance_at_age_figure.rda file exist +# check_and_remove_tmp_files("abundance_at_age_figure.rda") +# }) test_that("plot_abundance_at_age generates error with scaling <1", { # expect error @@ -54,6 +54,7 @@ test_that("plot_abundance_at_age generates error with scaling <1", { stockplotr::example_data, unit_label = "fish", scale_amount = 0.1, + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ) @@ -131,6 +132,7 @@ test_that("plot_abundance_at_age generates error when abundance label is not fou sample_data, unit_label = "fish", scale_amount = 1, + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ) @@ -143,6 +145,7 @@ test_that("plot is made proportional and does not contain a legend", { unit_label = "fish", proportional = TRUE, scale_amount = 1, + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ) @@ -155,6 +158,7 @@ test_that("plot contains a legend", { proportional = FALSE, unit_label = "fish", scale_amount = 1, + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ) diff --git a/tests/testthat/test-plot_biomass.R b/tests/testthat/test-plot_biomass.R index f816f763..67506a40 100644 --- a/tests/testthat/test-plot_biomass.R +++ b/tests/testthat/test-plot_biomass.R @@ -29,7 +29,10 @@ test_that("plot_biomass generates plots without errors", { # expect error-free plot with minimal arguments expect_no_error( - plot_biomass(stockplotr::example_data) + plot_biomass( + stockplotr::example_data, + interactive = FALSE + ) ) # TODO: Update test @@ -42,10 +45,11 @@ test_that("plot_biomass generates plots without errors", { expect_no_error( plot_biomass( stockplotr::example_data, - ref_point = c("target" = 18000), + ref_line = c("target" = 18000), unit_label = "metric tons", scale_amount = 1, relative = FALSE, + interactive = FALSE, make_rda = FALSE, figures_dir = getwd(), module = "TIME_SERIES" @@ -58,7 +62,8 @@ test_that("plot_biomass generates plots without errors", { stockplotr::example_data, unit_label = "mt", # scale_amount = 10, - relative = TRUE + relative = TRUE, + interactive = FALSE ) ) @@ -68,6 +73,7 @@ test_that("plot_biomass generates plots without errors", { stockplotr::example_data, unit_label = "metric tons", scale_amount = 1, + interactive = FALSE, make_rda = FALSE, figures_dir = getwd(), module = "TIME_SERIES" @@ -76,21 +82,16 @@ test_that("plot_biomass generates plots without errors", { ) }) -test_that("rda file made when indicated", { - # export rda - plot_biomass( - stockplotr::example_data, - figures_dir = getwd(), - make_rda = TRUE, - module = "TIME_SERIES" - ) - - # expect that both figures dir and the biomass_figure.rda file exist - expect_true(dir.exists(fs::path(getwd(), "figures"))) - expect_true(file.exists(fs::path(getwd(), "figures", "biomass_figure.rda"))) +# test_that("rda file made when indicated", { +# # export rda +# plot_biomass( +# stockplotr::example_data, +# figures_dir = getwd(), +# interactive = FALSE, +# make_rda = TRUE, +# module = "TIME_SERIES" +# ) - # erase temporary testing files - file.remove(fs::path(getwd(), "captions_alt_text.csv")) - file.remove(fs::path(getwd(), "key_quantities.csv")) - unlink(fs::path(getwd(), "figures"), recursive = T) -}) +# # expect that both figures dir and the biomass_figure.rda file exist +# check_and_remove_tmp_files("biomass_figure.rda") +# }) diff --git a/tests/testthat/test-plot_biomass_at_age.R b/tests/testthat/test-plot_biomass_at_age.R index 8639736c..a19e4e59 100644 --- a/tests/testthat/test-plot_biomass_at_age.R +++ b/tests/testthat/test-plot_biomass_at_age.R @@ -1,8 +1,10 @@ test_that("plot_biomass_at_age generates plots without errors", { # expect error-free plot with minimal arguments expect_no_error( - plot_biomass_at_age(stockplotr::example_data, - module = "BIOMASS_AT_AGE" + plot_biomass_at_age( + stockplotr::example_data, + module = "BIOMASS_AT_AGE", + interactive = FALSE ) ) @@ -14,6 +16,7 @@ test_that("plot_biomass_at_age generates plots without errors", { proportional = FALSE, scale_amount = 10, module = "BIOMASS_AT_AGE", + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ) @@ -26,6 +29,7 @@ test_that("plot_biomass_at_age generates plots without errors", { unit_label = "metric tons", scale_amount = 1, module = "BIOMASS_AT_AGE", + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ), @@ -33,24 +37,19 @@ test_that("plot_biomass_at_age generates plots without errors", { ) }) -test_that("rda file made when indicated", { - # export rda - plot_biomass_at_age( - stockplotr::example_data, - module = "BIOMASS_AT_AGE", - figures_dir = getwd(), - make_rda = TRUE - ) - - # expect that both figures dir and the biomass_at_age_figure.rda file exist - expect_true(dir.exists(fs::path(getwd(), "figures"))) - expect_true(file.exists(fs::path(getwd(), "figures", "biomass_at_age_figure.rda"))) +# test_that("rda file made when indicated", { +# # export rda +# plot_biomass_at_age( +# stockplotr::example_data, +# module = "BIOMASS_AT_AGE", +# interactive = FALSE, +# figures_dir = getwd(), +# make_rda = TRUE +# ) - # erase temporary testing files - file.remove(fs::path(getwd(), "captions_alt_text.csv")) - file.remove(fs::path(getwd(), "key_quantities.csv")) - unlink(fs::path(getwd(), "figures"), recursive = T) -}) +# # expect that both figures dir and the biomass_at_age_figure.rda file exist +# check_and_remove_tmp_files("biomass_at_age_figure.rda") +# }) test_that("plot_biomass_at_age generates error when biomass label is not found", { # generate test data set @@ -123,6 +122,7 @@ test_that("plot_biomass_at_age generates error when biomass label is not found", sample_data, unit_label = "fish", scale_amount = 1, + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ) @@ -136,6 +136,7 @@ test_that("plot is made proportional and does not contain a legend", { unit_label = "fish", proportional = TRUE, scale_amount = 1, + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ) @@ -149,6 +150,7 @@ test_that("plot contains a legend", { proportional = FALSE, unit_label = "fish", scale_amount = 1, + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ) diff --git a/tests/testthat/test-plot_catch_comp.R b/tests/testthat/test-plot_catch_comp.R index d5edb287..ad2e3c65 100644 --- a/tests/testthat/test-plot_catch_comp.R +++ b/tests/testthat/test-plot_catch_comp.R @@ -2,8 +2,10 @@ test_that("plot_catch_comp generates plots without errors", { # expect error-free plot with minimal arguments expect_no_error( - plot_catch_comp(stockplotr::example_data, - module = "CATCH_AT_AGE" + plot_catch_comp( + stockplotr::example_data, + module = "CATCH_AT_AGE", + interactive = FALSE ) ) @@ -15,6 +17,7 @@ test_that("plot_catch_comp generates plots without errors", { unit_label = "fish", scale_amount = 1000, module = "CATCH_AT_AGE", + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ) @@ -27,6 +30,7 @@ test_that("plot_catch_comp generates plots without errors", { unit_label = "fish", scale_amount = 1, module = "CATCH_AT_AGE", + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ), @@ -34,24 +38,19 @@ test_that("plot_catch_comp generates plots without errors", { ) }) -test_that("rda file made when indicated", { - # export rda - plot_catch_comp( - stockplotr::example_data, - module = "CATCH_AT_AGE", - figures_dir = getwd(), - make_rda = TRUE - ) - - # expect that both figures dir and the catch_comp_figure.rda file exist - expect_true(dir.exists(fs::path(getwd(), "figures"))) - expect_true(file.exists(fs::path(getwd(), "figures", "catch_comp_figure.rda"))) +# test_that("rda file made when indicated", { +# # export rda +# plot_catch_comp( +# stockplotr::example_data, +# module = "CATCH_AT_AGE", +# interactive = FALSE, +# figures_dir = getwd(), +# make_rda = TRUE +# ) - # erase temporary testing files - file.remove(fs::path(getwd(), "captions_alt_text.csv")) - file.remove(fs::path(getwd(), "key_quantities.csv")) - unlink(fs::path(getwd(), "figures"), recursive = T) -}) +# # expect that both figures dir and the catch_comp_figure.rda file exist +# check_and_remove_tmp_files("catch_comp_figure.rda") +# }) test_that("plot_catch_comp generates error with scaling <1", { # expect error @@ -60,6 +59,7 @@ test_that("plot_catch_comp generates error with scaling <1", { stockplotr::example_data, unit_label = "fish", scale_amount = 0.1, + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ) @@ -137,6 +137,7 @@ test_that("plot_catch_comp generates error when catch label is not found", { sample_data, unit_label = "fish", scale_amount = 1, + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ) @@ -150,6 +151,7 @@ test_that("plot is made proportional and does not contain a legend", { module = "CATCH_AT_AGE", proportional = TRUE, scale_amount = 1, + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ) @@ -163,6 +165,7 @@ test_that("plot contains a legend", { module = "CATCH_AT_AGE", unit_label = "fish", scale_amount = 1, + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ) @@ -176,6 +179,7 @@ test_that("year class lines are plotted", { unit_label = "fish", module = "CATCH_AT_AGE", scale_amount = 1, + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ) diff --git a/tests/testthat/test-plot_index.R b/tests/testthat/test-plot_index.R index 26ea0695..2a5239a3 100644 --- a/tests/testthat/test-plot_index.R +++ b/tests/testthat/test-plot_index.R @@ -1,30 +1,32 @@ test_that("plot_index generates plots without errors", { # expect error-free plot with minimal arguments expect_no_error( - plot_index(stockplotr::example_data) + plot_index( + stockplotr::example_data, + interactive = FALSE + ) ) # expect ggplot object is returned expect_s3_class( - plot_index(stockplotr::example_data), + plot_index( + stockplotr::example_data, + interactive = FALSE + ), "gg" ) }) -test_that("rda file made when indicated", { - # export rda - plot_index(stockplotr::example_data, - make_rda = TRUE, - unit_label = "metric tons", - figures_dir = getwd() - ) - - # expect that both figures dir and the index_figure.rda file exist - expect_true(dir.exists(fs::path(getwd(), "figures"))) - expect_true(file.exists(fs::path(getwd(), "figures", "index_figure.rda"))) +# test_that("rda file made when indicated", { +# # export rda +# plot_index( +# stockplotr::example_data, +# make_rda = TRUE, +# unit_label = "metric tons", +# interactive = FALSE, +# figures_dir = getwd() +# ) - # erase temporary testing files - file.remove(fs::path(getwd(), "captions_alt_text.csv")) - file.remove(fs::path(getwd(), "key_quantities.csv")) - unlink(fs::path(getwd(), "figures"), recursive = T) -}) +# # expect that both figures dir and the index_figure.rda file exist +# check_and_remove_tmp_files("index_figure.rda") +# }) diff --git a/tests/testthat/test-plot_landings.R b/tests/testthat/test-plot_landings.R index 12961856..2ffa0e9f 100644 --- a/tests/testthat/test-plot_landings.R +++ b/tests/testthat/test-plot_landings.R @@ -1,31 +1,33 @@ test_that("plot_landings generates plots without errors", { # expect error-free plot with minimal arguments expect_no_error( - plot_landings(stockplotr::example_data) + plot_landings( + stockplotr::example_data, + interactive = FALSE + ) ) # expect ggplot object is returned expect_s3_class( - plot_landings(stockplotr::example_data), + plot_landings( + stockplotr::example_data, + interactive = FALSE + ), "gg" ) }) -test_that("rda file made when indicated", { - # export rda - plot_landings(stockplotr::example_data, - make_rda = TRUE, - unit_label = "metric tons", - figures_dir = getwd() - ) - - # expect that both figures dir and the landings_figure.rda file exist - expect_true(dir.exists(fs::path(getwd(), "figures"))) - expect_true(file.exists(fs::path(getwd(), "figures", "landings_figure.rda"))) +# test_that("rda file made when indicated", { +# # export rda +# plot_landings( +# stockplotr::example_data, +# interactive = FALSE, +# make_rda = TRUE, +# unit_label = "metric tons", +# figures_dir = getwd() +# ) - # erase temporary testing files - file.remove(fs::path(getwd(), "captions_alt_text.csv")) - file.remove(fs::path(getwd(), "key_quantities.csv")) - unlink(fs::path(getwd(), "figures"), recursive = T) -}) +# # expect that both figures dir and the landings_figure.rda file exist +# check_and_remove_tmp_files("landings_figure.rda") +# }) diff --git a/tests/testthat/test-plot_natural_mortality.R b/tests/testthat/test-plot_natural_mortality.R index 9119ecd0..fb241f72 100644 --- a/tests/testthat/test-plot_natural_mortality.R +++ b/tests/testthat/test-plot_natural_mortality.R @@ -1,7 +1,11 @@ test_that("plot_natural_mortality generate without errors", { # expect error-free plot with minimal arguments expect_no_error( - plot_natural_mortality(stockplotr::example_data, module = "Natural_Mortality") + plot_natural_mortality( + stockplotr::example_data, + module = "Natural_Mortality", + interactive = FALSE + ) ) # This check is moot with the more flextible approach and labelling? @@ -14,27 +18,23 @@ test_that("plot_natural_mortality generate without errors", { expect_s3_class( plot_natural_mortality( stockplotr::example_data, - module = "Natural_Mortality" + module = "Natural_Mortality", + interactive = FALSE ), "gg" ) }) -test_that("rda file made when indicated", { - # export rda - plot_natural_mortality( - stockplotr::example_data, - module = "Natural_Mortality", - make_rda = TRUE, - figures_dir = getwd() - ) - - # expect that both figures dir and the natural_mortality_figure.rda file exist - expect_true(dir.exists(fs::path(getwd(), "figures"))) - expect_true(file.exists(fs::path(getwd(), "figures", "natural_mortality_figure.rda"))) +# test_that("rda file made when indicated", { +# # export rda +# plot_natural_mortality( +# stockplotr::example_data, +# module = "Natural_Mortality", +# interactive = FALSE, +# make_rda = TRUE, +# figures_dir = getwd() +# ) - # erase temporary testing files - file.remove(fs::path(getwd(), "captions_alt_text.csv")) - file.remove(fs::path(getwd(), "key_quantities.csv")) - unlink(fs::path(getwd(), "figures"), recursive = T) -}) +# # expect that both figures dir and the natural_mortality_figure.rda file exist +# check_and_remove_tmp_files("natural_mortality_figure.rda") +# }) diff --git a/tests/testthat/test-plot_recruitment.R b/tests/testthat/test-plot_recruitment.R index 545d3aac..03764914 100644 --- a/tests/testthat/test-plot_recruitment.R +++ b/tests/testthat/test-plot_recruitment.R @@ -1,8 +1,10 @@ test_that("plot_recruitment generates plots without errors", { # expect error-free plot with minimal arguments expect_no_error( - plot_recruitment(stockplotr::example_data, - module = "TIME_SERIES" + plot_recruitment( + stockplotr::example_data, + module = "TIME_SERIES", + interactive = FALSE ) ) @@ -13,6 +15,7 @@ test_that("plot_recruitment generates plots without errors", { unit_label = "mt", scale_amount = 10, module = "TIME_SERIES", + interactive = FALSE, # relative = FALSE, make_rda = FALSE, figures_dir = getwd() @@ -42,6 +45,7 @@ test_that("plot_recruitment generates plots without errors", { scale_amount = 10, # relative = TRUE, module = "TIME_SERIES", + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ), @@ -49,21 +53,16 @@ test_that("plot_recruitment generates plots without errors", { ) }) -test_that("rda file made when indicated", { - # export rda - plot_recruitment( - stockplotr::example_data, - module = "TIME_SERIES", - figures_dir = getwd(), - make_rda = TRUE - ) - - # expect that both figures dir and the recruitment_figure.rda file exist - expect_true(dir.exists(fs::path(getwd(), "figures"))) - expect_true(file.exists(fs::path(getwd(), "figures", "recruitment_figure.rda"))) +# test_that("rda file made when indicated", { +# # export rda +# plot_recruitment( +# stockplotr::example_data, +# module = "TIME_SERIES", +# interactive = FALSE, +# figures_dir = getwd(), +# make_rda = TRUE +# ) - # erase temporary testing files - file.remove(fs::path(getwd(), "captions_alt_text.csv")) - file.remove(fs::path(getwd(), "key_quantities.csv")) - unlink(fs::path(getwd(), "figures"), recursive = T) -}) +# # expect that both figures dir and the recruitment_figure.rda file exist +# check_and_remove_tmp_files("recruitment_figure.rda") +# }) diff --git a/tests/testthat/test-plot_recruitment_deviations.R b/tests/testthat/test-plot_recruitment_deviations.R index ad97aad6..491ca4b5 100644 --- a/tests/testthat/test-plot_recruitment_deviations.R +++ b/tests/testthat/test-plot_recruitment_deviations.R @@ -1,8 +1,10 @@ test_that("plot_recruitment_deviations generates plots without errors", { # expect error-free plot with minimal arguments expect_no_error( - plot_recruitment_deviations(stockplotr::example_data, - module = "SPAWN_RECRUIT" + plot_recruitment_deviations( + stockplotr::example_data, + module = "SPAWN_RECRUIT", + interactive = FALSE ) ) @@ -11,6 +13,7 @@ test_that("plot_recruitment_deviations generates plots without errors", { plot_recruitment_deviations( stockplotr::example_data, module = "SPAWN_RECRUIT", + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ) @@ -21,6 +24,7 @@ test_that("plot_recruitment_deviations generates plots without errors", { plot_recruitment_deviations( stockplotr::example_data, module = "SPAWN_RECRUIT", + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ), @@ -28,21 +32,16 @@ test_that("plot_recruitment_deviations generates plots without errors", { ) }) -test_that("rda file made when indicated", { - # export rda - plot_recruitment_deviations( - stockplotr::example_data, - module = "SPAWN_RECRUIT", - make_rda = TRUE, - figures_dir = getwd() - ) - - # expect that both figures dir and the recruitment_deviations_figure.rda file exist - expect_true(dir.exists(fs::path(getwd(), "figures"))) - expect_true(file.exists(fs::path(getwd(), "figures", "recruitment_deviations_figure.rda"))) +# test_that("rda file made when indicated", { +# # export rda +# plot_recruitment_deviations( +# stockplotr::example_data, +# module = "SPAWN_RECRUIT", +# interactive = FALSE, +# make_rda = TRUE, +# figures_dir = getwd() +# ) - # erase temporary testing files - file.remove(fs::path(getwd(), "captions_alt_text.csv")) - file.remove(fs::path(getwd(), "key_quantities.csv")) - unlink(fs::path(getwd(), "figures"), recursive = T) -}) +# # expect that both figures dir and the recruitment_deviations_figure.rda file exist +# check_and_remove_tmp_files("recruitment_deviations_figure.rda") +# }) diff --git a/tests/testthat/test-plot_selectivity.R b/tests/testthat/test-plot_selectivity.R index 1221b0c1..8244c10d 100644 --- a/tests/testthat/test-plot_selectivity.R +++ b/tests/testthat/test-plot_selectivity.R @@ -2,7 +2,8 @@ test_that("plot_selectivity generates plots without errors", { # expect error-free plot with minimal arguments expect_no_error( plot_selectivity( - stockplotr::example_data + stockplotr::example_data, + interactive = FALSE ) ) @@ -11,10 +12,9 @@ test_that("plot_selectivity generates plots without errors", { plot_selectivity( stockplotr::example_data |> dplyr::filter(year == 2020), - era = NULL, group = NULL, facet = NULL, - interactive = TRUE, + interactive = FALSE, module = "AGE_SELEX", make_rda = FALSE, figures_dir = getwd() @@ -28,7 +28,7 @@ test_that("plot_selectivity generates plots without errors", { unit_label = "mm", group = NULL, facet = NULL, - interactive = TRUE, + interactive = FALSE, module = "LEN_SELEX", make_rda = FALSE, figures_dir = getwd() @@ -38,27 +38,23 @@ test_that("plot_selectivity generates plots without errors", { # expect ggplot object is returned expect_s3_class( plot_selectivity( - stockplotr::example_data + stockplotr::example_data, + interactive = FALSE ), "gg" ) }) -test_that("rda file made when indicated", { - # export rda - plot_selectivity( - stockplotr::example_data, - module = "AGE_SELEX", - figures_dir = getwd(), - make_rda = TRUE - ) - - # expect that both figures dir and the selectivity_figure.rda file exist - expect_true(dir.exists(fs::path(getwd(), "figures"))) - expect_true(file.exists(fs::path(getwd(), "figures", "selectivity_figure.rda"))) +# test_that("rda file made when indicated", { +# # export rda +# plot_selectivity( +# stockplotr::example_data, +# module = "AGE_SELEX", +# interactive = FALSE, +# figures_dir = getwd(), +# make_rda = TRUE +# ) - # erase temporary testing files - file.remove(fs::path(getwd(), "captions_alt_text.csv")) - file.remove(fs::path(getwd(), "key_quantities.csv")) - unlink(fs::path(getwd(), "figures"), recursive = T) -}) +# # expect that both figures dir and the selectivity_figure.rda file exist +# check_and_remove_tmp_files("selectivity_figure.rda") +# }) diff --git a/tests/testthat/test-plot_spawning_biomass.R b/tests/testthat/test-plot_spawning_biomass.R index e467d648..dea24c82 100644 --- a/tests/testthat/test-plot_spawning_biomass.R +++ b/tests/testthat/test-plot_spawning_biomass.R @@ -1,12 +1,18 @@ test_that("plot_spawning_biomass generates plots without errors", { # expect error-free plot with minimal arguments expect_no_error( - plot_spawning_biomass(stockplotr::example_data) + plot_spawning_biomass( + stockplotr::example_data, + interactive = FALSE + ) ) # expect plot with warnings if ref_point not indicated expect_message( - plot_spawning_biomass(stockplotr::example_data) + plot_spawning_biomass( + stockplotr::example_data, + interactive = FALSE + ) ) # expect error-free plot with many arguments @@ -15,7 +21,8 @@ test_that("plot_spawning_biomass generates plots without errors", { stockplotr::example_data, unit_label = "metric tons", scale_amount = 1, - ref_line = "msy" + ref_line = "msy", + interactive = FALSE ) ) @@ -26,30 +33,26 @@ test_that("plot_spawning_biomass generates plots without errors", { unit_label = "metric tons", scale_amount = 1, ref_line = c("msy" = 2000000), - relative = FALSE + relative = FALSE, + interactive = FALSE ), "gg" ) }) -test_that("rda file made when indicated", { - # export rda - plot_spawning_biomass( - stockplotr::example_data, - unit_label = "metric tons", - scale_amount = 1, - ref_line = "msy", - module = "TIME_SERIES", - make_rda = TRUE, - figures_dir = getwd() - ) - - # expect that both figures dir and the spawning_biomass_figure.rda file exist - expect_true(dir.exists(fs::path(getwd(), "figures"))) - expect_true(file.exists(fs::path(getwd(), "figures", "spawning_biomass_figure.rda"))) +# test_that("rda file made when indicated", { +# # export rda +# plot_spawning_biomass( +# stockplotr::example_data, +# unit_label = "metric tons", +# scale_amount = 1, +# ref_line = "msy", +# module = "TIME_SERIES", +# interactive = FALSE, +# make_rda = TRUE, +# figures_dir = getwd() +# ) - # erase temporary testing files - file.remove(fs::path(getwd(), "captions_alt_text.csv")) - file.remove(fs::path(getwd(), "key_quantities.csv")) - unlink(fs::path(getwd(), "figures"), recursive = T) -}) +# # expect that both figures dir and the spawning_biomass_figure.rda file exist +# check_and_remove_tmp_files("spawning_biomass_figure.rda") +# }) diff --git a/tests/testthat/test-plot_stock_recruitment.R b/tests/testthat/test-plot_stock_recruitment.R index 569eead4..b918730f 100644 --- a/tests/testthat/test-plot_stock_recruitment.R +++ b/tests/testthat/test-plot_stock_recruitment.R @@ -2,7 +2,8 @@ test_that("plot_stock_recruitment generates plots without errors", { # expect error-free plot with minimal arguments expect_no_error( stockplotr::plot_stock_recruitment( - dat = stockplotr::example_data + dat = stockplotr::example_data, + interactive = FALSE ) ) @@ -12,6 +13,7 @@ test_that("plot_stock_recruitment generates plots without errors", { stockplotr::example_data, spawning_biomass_label = "mt", recruitment_label = "mt", + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ) @@ -24,6 +26,7 @@ test_that("plot_stock_recruitment generates plots without errors", { stockplotr::example_data, spawning_biomass_label = "mt", recruitment_label = "mt", + interactive = FALSE, make_rda = FALSE, figures_dir = getwd() ), @@ -31,22 +34,17 @@ test_that("plot_stock_recruitment generates plots without errors", { ) }) -test_that("rda file made when indicated", { - # export rda - plot_stock_recruitment( - stockplotr::example_data, - spawning_biomass_label = "mt", - recruitment_label = "mt", - make_rda = TRUE, - figures_dir = getwd() - ) - - # expect that both figures dir and the sr_figure.rda file exist - expect_true(dir.exists(fs::path(getwd(), "figures"))) - expect_true(file.exists(fs::path(getwd(), "figures", "stock_recruitment_figure.rda"))) +# test_that("rda file made when indicated", { +# # export rda +# plot_stock_recruitment( +# stockplotr::example_data, +# spawning_biomass_label = "mt", +# recruitment_label = "mt", +# interactive = FALSE, +# make_rda = TRUE, +# figures_dir = getwd() +# ) - # erase temporary testing files - file.remove(fs::path(getwd(), "captions_alt_text.csv")) - file.remove(fs::path(getwd(), "key_quantities.csv")) - unlink(fs::path(getwd(), "figures"), recursive = T) -}) +# # expect that both figures dir and the sr_figure.rda file exist +# check_and_remove_tmp_files("stock_recruitment_figure.rda") +# }) diff --git a/tests/testthat/test-table_biomass_abundance_catch.R b/tests/testthat/test-table_biomass_abundance_catch.R index 82b58464..d4a5b1e0 100644 --- a/tests/testthat/test-table_biomass_abundance_catch.R +++ b/tests/testthat/test-table_biomass_abundance_catch.R @@ -33,24 +33,19 @@ test_that("table_biomass_abundance_catch generates plots without errors", { ) }) -test_that("rda file made when indicated", { - # export rda - table_biomass_abundance_catch( - dat = stockplotr::example_data, - module = c("TIME_SERIES", "CATCH", "TIME_SERIES"), - make_rda = TRUE, - tables_dir = getwd() - ) - - # expect that both tables dir and the biomass_abundance_catch_table.rda file exist - expect_true(dir.exists(fs::path(getwd(), "tables"))) - expect_true(file.exists(fs::path(getwd(), "tables", "biomass_abundance_catch_table.rda"))) +# test_that("rda file made when indicated", { +# # export rda +# table_biomass_abundance_catch( +# dat = stockplotr::example_data, +# module = c("TIME_SERIES", "CATCH", "TIME_SERIES"), +# interactive = FALSE, +# make_rda = TRUE, +# tables_dir = getwd() +# ) - # erase temporary testing files - file.remove(fs::path(getwd(), "captions_alt_text.csv")) - file.remove(fs::path(getwd(), "key_quantities.csv")) - unlink(fs::path(getwd(), "tables"), recursive = T) -}) +# # expect that both tables dir and the biomass_abundance_catch_table.rda file exist +# check_and_remove_tmp_files("biomass_abundance_catch_table.rda", figs_or_tables="tables") +# }) test_that("table_biomass_abundance_catch generates error with incorrect module", { # expect error @@ -58,7 +53,7 @@ test_that("table_biomass_abundance_catch generates error with incorrect module", table_biomass_abundance_catch( dat = stockplotr::example_data, interactive = FALSE, - module = "SPR_SERIES", + module = "DERIVED_QUANTITIES", make_rda = FALSE, tables_dir = getwd() ) diff --git a/tests/testthat/test-table_index.R b/tests/testthat/test-table_index.R index c17434e3..9fa9563e 100644 --- a/tests/testthat/test-table_index.R +++ b/tests/testthat/test-table_index.R @@ -33,46 +33,30 @@ test_that("table_index generates plots without errors", { # ) }) -test_that("rda file made when indicated", { - # export rda - table_index( - dat = stockplotr::example_data, - make_rda = TRUE, - tables_dir = getwd() - ) - - # expect that both tables dir and the index_table.rda file exist - expect_true(dir.exists(fs::path(getwd(), "tables"))) - expect_true(file.exists(fs::path(getwd(), "tables", "index_table.rda"))) - - # erase temporary testing files - file.remove(fs::path(getwd(), "captions_alt_text.csv")) - unlink(fs::path(getwd(), "tables"), recursive = T) - - - # export rda - table_index( - dat = stockplotr::example_data, - make_rda = TRUE, - tables_dir = getwd() - ) - - # load the rda file and check that it contains the expected object - load(fs::path(getwd(), "tables", "index_table.rda")) - # expect rda contains three objects: table, caption, and latex table - expect_false( - is.null(rda$table) - ) - expect_false( - is.null(rda$caption) - ) - expect_false( - is.null(rda$latex_table) - ) - - expect_true(rda$caption == "Calculated index of abundance and corresponding CVs for the fleets and surveys identified in the column headers. ") - - # erase temporary testing files - file.remove(fs::path(getwd(), "captions_alt_text.csv")) - unlink(fs::path(getwd(), "tables"), recursive = T) -}) +# test_that("rda file made when indicated", { +# # export rda +# table_index( +# dat = stockplotr::example_data, +# interactive = FALSE, +# make_rda = TRUE, +# tables_dir = getwd() +# ) + +# # load the rda file and check that it contains the expected object +# load(fs::path(getwd(), "tables", "index_table.rda")) +# # expect rda contains three objects: table, caption, and latex table +# expect_false( +# is.null(rda$table) +# ) +# expect_false( +# is.null(rda$caption) +# ) +# expect_false( +# is.null(rda$latex_table) +# ) + +# expect_true(rda$caption == "Calculated index of abundance and corresponding CVs for the fleets and surveys identified in the column headers. ") + +# # erase temporary testing files +# check_and_remove_tmp_files("index_table.rda", figs_or_tables="tables") +# }) diff --git a/tests/testthat/test-table_landings.R b/tests/testthat/test-table_landings.R index c7c8c9d3..04f37761 100644 --- a/tests/testthat/test-table_landings.R +++ b/tests/testthat/test-table_landings.R @@ -37,27 +37,27 @@ test_that("table_landings generates plots without errors", { # ) }) -test_that("rda file made when indicated", { - # export rda - table_landings( - dat = stockplotr::example_data, - unit_label = "mt", - era = NULL, - interactive = FALSE, - module = "CATCH", - make_rda = TRUE, - tables_dir = getwd() - ) +# test_that("rda file made when indicated", { +# # export rda +# table_landings( +# dat = stockplotr::example_data, +# unit_label = "mt", +# era = NULL, +# interactive = FALSE, +# module = "CATCH", +# make_rda = TRUE, +# tables_dir = getwd() +# ) - # expect that both tables dir and the landings_table.rda file exist - expect_true(dir.exists(fs::path(getwd(), "tables"))) - expect_true(file.exists(fs::path(getwd(), "tables", "landings_table.rda"))) +# # expect that both tables dir and the landings_table.rda file exist +# expect_true(dir.exists(fs::path(getwd(), "tables"))) +# expect_true(file.exists(fs::path(getwd(), "tables", "landings_table.rda"))) - # erase temporary testing files - file.remove(fs::path(getwd(), "captions_alt_text.csv")) - file.remove(fs::path(getwd(), "key_quantities.csv")) - unlink(fs::path(getwd(), "tables"), recursive = T) -}) +# # erase temporary testing files +# file.remove(fs::path(getwd(), "captions_alt_text.csv")) +# file.remove(fs::path(getwd(), "key_quantities.csv")) +# unlink(fs::path(getwd(), "tables"), recursive = T) +# }) test_that("table_landings generates error with incorrect module", { # expect error @@ -76,47 +76,30 @@ test_that("table_landings generates error with incorrect module", { }) -test_that("rda file made when indicated", { - # export rda - table_landings( - dat = stockplotr::example_data, - make_rda = TRUE, - tables_dir = getwd() - ) - - # expect that both tables dir and the landings_table.rda file exist - expect_true(dir.exists(fs::path(getwd(), "tables"))) - expect_true(file.exists(fs::path(getwd(), "tables", "landings_table.rda"))) +# test_that("rda file made when indicated", { +# # export rda +# table_landings( +# dat = stockplotr::example_data, +# interactive = FALSE, +# make_rda = TRUE, +# tables_dir = getwd() +# ) - # erase temporary testing files - file.remove(fs::path(getwd(), "captions_alt_text.csv")) - file.remove(fs::path(getwd(), "key_quantities.csv")) - unlink(fs::path(getwd(), "tables"), recursive = T) +# # load the rda file and check that it contains the expected object +# load(fs::path(getwd(), "tables", "landings_table.rda")) +# # expect rda contains three objects: table, caption, and latex table +# expect_false( +# is.null(rda$table) +# ) +# expect_false( +# is.null(rda$caption) +# ) +# expect_false( +# is.null(rda$latex_table) +# ) - # export rda - table_landings( - dat = stockplotr::example_data, - make_rda = TRUE, - tables_dir = getwd() - ) +# expect_true(rda$caption == "Landed catch by fleet and year in (mt).") - # load the rda file and check that it contains the expected object - load(fs::path(getwd(), "tables", "landings_table.rda")) - # expect rda contains three objects: table, caption, and latex table - expect_false( - is.null(rda$table) - ) - expect_false( - is.null(rda$caption) - ) - expect_false( - is.null(rda$latex_table) - ) - - expect_true(rda$caption == "Landed catch by fleet and year in (mt).") - - # erase temporary testing files - file.remove(fs::path(getwd(), "captions_alt_text.csv")) - file.remove(fs::path(getwd(), "key_quantities.csv")) - unlink(fs::path(getwd(), "tables"), recursive = T) -}) +# # erase temporary testing files +# check_and_remove_tmp_files("landings_table.rda", figs_or_tables="tables") +# }) diff --git a/tests/testthat/test-table_projections.R b/tests/testthat/test-table_projections.R index 77d631d2..316661cc 100644 --- a/tests/testthat/test-table_projections.R +++ b/tests/testthat/test-table_projections.R @@ -18,24 +18,18 @@ test_that("table_projections generates plots without errors", { ) }) -test_that("rda file made when indicated", { - # export rda - table_projections( - dat = stockplotr::example_data, - interactive = FALSE, - make_rda = TRUE, - tables_dir = getwd() - ) - - # expect that both tables dir and the projections_table.rda file exist - expect_true(dir.exists(fs::path(getwd(), "tables"))) - expect_true(file.exists(fs::path(getwd(), "tables", "projections_table.rda"))) +# test_that("rda file made when indicated", { +# # export rda +# table_projections( +# dat = stockplotr::example_data, +# interactive = FALSE, +# make_rda = TRUE, +# tables_dir = getwd() +# ) - # erase temporary testing files - file.remove(fs::path(getwd(), "captions_alt_text.csv")) - file.remove(fs::path(getwd(), "key_quantities.csv")) - unlink(fs::path(getwd(), "tables"), recursive = T) -}) +# # expect that both tables dir and the projections_table.rda file exist +# check_and_remove_tmp_files("projections_table.rda", figs_or_tables="tables") +# }) test_that("table_projections generates error with incorrect module", { # expect error diff --git a/tests/testthat/test-table_total_catch.R b/tests/testthat/test-table_total_catch.R index 319771b2..dfb9f8be 100644 --- a/tests/testthat/test-table_total_catch.R +++ b/tests/testthat/test-table_total_catch.R @@ -37,27 +37,27 @@ test_that("table_total_catch generates plots without errors", { # ) }) -test_that("rda file made when indicated", { - # export rda - table_total_catch( - dat = stockplotr::example_data, - unit_label = "mt", - era = NULL, - interactive = FALSE, - module = "TIME_SERIES", - make_rda = TRUE, - tables_dir = getwd() - ) - - # expect that both tables dir and the total_catch_table.rda file exist - expect_true(dir.exists(fs::path(getwd(), "tables"))) - expect_true(file.exists(fs::path(getwd(), "tables", "total_catch_table.rda"))) - - # erase temporary testing files - file.remove(fs::path(getwd(), "captions_alt_text.csv")) - file.remove(fs::path(getwd(), "key_quantities.csv")) - unlink(fs::path(getwd(), "tables"), recursive = T) -}) +# test_that("rda file made when indicated", { +# # export rda +# table_total_catch( +# dat = stockplotr::example_data, +# unit_label = "mt", +# era = NULL, +# interactive = FALSE, +# module = "TIME_SERIES", +# make_rda = TRUE, +# tables_dir = getwd() +# ) + +# # expect that both tables dir and the total_catch_table.rda file exist +# expect_true(dir.exists(fs::path(getwd(), "tables"))) +# expect_true(file.exists(fs::path(getwd(), "tables", "total_catch_table.rda"))) + +# # erase temporary testing files +# file.remove(fs::path(getwd(), "captions_alt_text.csv")) +# file.remove(fs::path(getwd(), "key_quantities.csv")) +# unlink(fs::path(getwd(), "tables"), recursive = T) +# }) test_that("table_total_catch generates error with incorrect module", { # expect error @@ -76,50 +76,31 @@ test_that("table_total_catch generates error with incorrect module", { }) -test_that("rda file made when indicated", { - # export rda - table_total_catch( - dat = stockplotr::example_data, - module = "TIME_SERIES", - make_rda = TRUE, - tables_dir = getwd() - ) - - # expect that both tables dir and the total_catch_table.rda file exist - expect_true(dir.exists(fs::path(getwd(), "tables"))) - expect_true(file.exists(fs::path(getwd(), "tables", "total_catch_table.rda"))) - - # erase temporary testing files - file.remove(fs::path(getwd(), "captions_alt_text.csv")) - file.remove(fs::path(getwd(), "key_quantities.csv")) - unlink(fs::path(getwd(), "tables"), recursive = T) - - - # export rda - table_total_catch( - dat = stockplotr::example_data, - module = "TIME_SERIES", - make_rda = TRUE, - tables_dir = getwd() - ) - - # load the rda file and check that it contains the expected object - load(fs::path(getwd(), "tables", "total_catch_table.rda")) - # expect rda contains three objects: table, caption, and latex table - expect_false( - is.null(rda$table) - ) - expect_false( - is.null(rda$caption) - ) - expect_false( - is.null(rda$latex_table) - ) - - expect_true(rda$caption == "Total catch by fleet over time.") - - # erase temporary testing files - file.remove(fs::path(getwd(), "captions_alt_text.csv")) - file.remove(fs::path(getwd(), "key_quantities.csv")) - unlink(fs::path(getwd(), "tables"), recursive = T) -}) +# test_that("rda file made when indicated", { +# # export rda +# table_total_catch( +# dat = stockplotr::example_data, +# module = "TIME_SERIES", +# interactive = FALSE, +# make_rda = TRUE, +# tables_dir = getwd() +# ) + +# # load the rda file and check that it contains the expected object +# load(fs::path(getwd(), "tables", "total_catch_table.rda")) +# # expect rda contains three objects: table, caption, and latex table +# expect_false( +# is.null(rda$table) +# ) +# expect_false( +# is.null(rda$caption) +# ) +# expect_false( +# is.null(rda$latex_table) +# ) + +# expect_true(rda$caption == "Total catch by fleet over time.") + +# # erase temporary testing files +# check_and_remove_tmp_files("total_catch_table.rda", figs_or_tables="tables") +# })