From 98d7023764fd1e2566278b88aebe7fede255f5b8 Mon Sep 17 00:00:00 2001 From: VisruthSK <67435125+VisruthSK@users.noreply.github.com> Date: Sun, 7 Dec 2025 18:49:15 -0800 Subject: [PATCH 1/6] Gitignored code-oss settings folder --- .Rbuildignore | 1 + .gitignore | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.Rbuildignore b/.Rbuildignore index 031ffa55..6d67ff72 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -14,5 +14,6 @@ images/* book/* docs/* Rplots.pdf +.vscode/* ^\.github$ ^release-prep\.R$ diff --git a/.gitignore b/.gitignore index 7e658a14..695e6e77 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,6 @@ revdep/* CRAN-RELEASE CRAN-SUBMISSION release-prep.R + +# vscode/positron/etc settings +.vscode/* From 42c2872e8013b96e20cc0b58bc7989b43e1ca79a Mon Sep 17 00:00:00 2001 From: VisruthSK <67435125+VisruthSK@users.noreply.github.com> Date: Sun, 7 Dec 2025 18:54:59 -0800 Subject: [PATCH 2/6] Removed context() and library(bayesplot) in tests --- DESCRIPTION | 3 ++- tests/testthat/test-aesthetics.R | 4 ---- tests/testthat/test-available_ppc.R | 4 ---- tests/testthat/test-bayesplot_grid.R | 3 --- tests/testthat/test-convenience-functions.R | 3 --- tests/testthat/test-example-draws.R | 3 --- tests/testthat/test-extractors.R | 3 --- tests/testthat/test-helpers-mcmc.R | 5 ----- tests/testthat/test-helpers-ppc.R | 3 --- tests/testthat/test-helpers-shared.R | 3 --- tests/testthat/test-mcmc-combo.R | 3 --- tests/testthat/test-mcmc-diagnostics.R | 3 --- tests/testthat/test-mcmc-distributions.R | 3 --- tests/testthat/test-mcmc-intervals.R | 4 ---- tests/testthat/test-mcmc-nuts.R | 3 --- tests/testthat/test-mcmc-recover.R | 3 --- tests/testthat/test-mcmc-scatter-and-parcoord.R | 3 --- tests/testthat/test-mcmc-traces.R | 3 --- tests/testthat/test-pp_check.R | 3 --- tests/testthat/test-ppc-censoring.R | 3 --- tests/testthat/test-ppc-discrete.R | 2 -- tests/testthat/test-ppc-distributions.R | 3 --- tests/testthat/test-ppc-errors.R | 3 --- tests/testthat/test-ppc-input-validation.R | 3 --- tests/testthat/test-ppc-intervals.R | 3 --- tests/testthat/test-ppc-loo.R | 3 --- tests/testthat/test-ppc-scatterplots.R | 3 --- tests/testthat/test-ppc-test-statistics.R | 3 --- 28 files changed, 2 insertions(+), 86 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a1a3a5e1..df6b5f7d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -56,9 +56,10 @@ Suggests: scales, shinystan (>= 2.3.0), survival, - testthat (>= 2.0.0), + testthat (>= 3.0.0), vdiffr (>= 1.0.2) RoxygenNote: 7.3.3 VignetteBuilder: knitr Encoding: UTF-8 Roxygen: list(markdown = TRUE) +Config/testthat/edition: 3 diff --git a/tests/testthat/test-aesthetics.R b/tests/testthat/test-aesthetics.R index 21b054de..fade8bcf 100644 --- a/tests/testthat/test-aesthetics.R +++ b/tests/testthat/test-aesthetics.R @@ -1,7 +1,3 @@ -library(bayesplot) -context("Aesthetics") - - # color scheme stuff ------------------------------------------------------ prepare_colors_for_test <- function(scheme) { diff --git a/tests/testthat/test-available_ppc.R b/tests/testthat/test-available_ppc.R index 68a6e316..9fe05e31 100644 --- a/tests/testthat/test-available_ppc.R +++ b/tests/testthat/test-available_ppc.R @@ -1,7 +1,3 @@ -library(bayesplot) -context("available_mcmc and available_ppc") - - test_that("available_mcmc works", { a <- available_mcmc() expect_s3_class(a, "bayesplot_function_list") diff --git a/tests/testthat/test-bayesplot_grid.R b/tests/testthat/test-bayesplot_grid.R index c2146800..ac4373d0 100644 --- a/tests/testthat/test-bayesplot_grid.R +++ b/tests/testthat/test-bayesplot_grid.R @@ -1,6 +1,3 @@ -library(bayesplot) -context("bayesplot_grid") - skip_if_not_installed("gridExtra") y <- example_y_data() diff --git a/tests/testthat/test-convenience-functions.R b/tests/testthat/test-convenience-functions.R index 068e24a9..3505211d 100644 --- a/tests/testthat/test-convenience-functions.R +++ b/tests/testthat/test-convenience-functions.R @@ -1,7 +1,4 @@ -library(bayesplot) library(ggplot2) -context("Convenience functions (for ggplot objects)") - # abline_01, vline_ and hline_ ------------------------------------------ test_that("abline_01 returns the correct object", { diff --git a/tests/testthat/test-example-draws.R b/tests/testthat/test-example-draws.R index 399c4281..cc4317aa 100644 --- a/tests/testthat/test-example-draws.R +++ b/tests/testthat/test-example-draws.R @@ -1,6 +1,3 @@ -library(bayesplot) -context("Example draws") - test_that("example_mcmc_draws throws correct errors", { expect_error(example_mcmc_draws(chains = 5), "chains <= 4") expect_error(example_mcmc_draws(chains = 0), "chains >= 1") diff --git a/tests/testthat/test-extractors.R b/tests/testthat/test-extractors.R index 5cb990ce..236f6704 100644 --- a/tests/testthat/test-extractors.R +++ b/tests/testthat/test-extractors.R @@ -1,6 +1,3 @@ -library(bayesplot) -context("Extractors") - if (requireNamespace("rstanarm", quietly = TRUE)) { ITER <- 1000 CHAINS <- 3 diff --git a/tests/testthat/test-helpers-mcmc.R b/tests/testthat/test-helpers-mcmc.R index 3f181426..26fbcdd3 100644 --- a/tests/testthat/test-helpers-mcmc.R +++ b/tests/testthat/test-helpers-mcmc.R @@ -1,10 +1,5 @@ -library(bayesplot) -context("MCMC: misc. functions") - source(test_path("data-for-mcmc-tests.R")) - - # melt_mcmc ---------------------------------------------------------------- test_that("melt_mcmc does not convert integer parameter names to integers #162", { mat2 <- mat[, 1:2] diff --git a/tests/testthat/test-helpers-ppc.R b/tests/testthat/test-helpers-ppc.R index 73daf4ae..36f921d3 100644 --- a/tests/testthat/test-helpers-ppc.R +++ b/tests/testthat/test-helpers-ppc.R @@ -1,6 +1,3 @@ -library(bayesplot) -context("PPC: misc. functions") - source(test_path("data-for-ppc-tests.R")) source(test_path("data-for-mcmc-tests.R")) diff --git a/tests/testthat/test-helpers-shared.R b/tests/testthat/test-helpers-shared.R index 9badd2eb..35e1cb2b 100644 --- a/tests/testthat/test-helpers-shared.R +++ b/tests/testthat/test-helpers-shared.R @@ -1,6 +1,3 @@ -library(bayesplot) -context("Shared: misc. functions") - # suggested packages ------------------------------------------------------ test_that("suggested_package throws correct errors", { expect_error(suggested_package("NOPACKAGE"), diff --git a/tests/testthat/test-mcmc-combo.R b/tests/testthat/test-mcmc-combo.R index f657c1a9..bbf18eeb 100644 --- a/tests/testthat/test-mcmc-combo.R +++ b/tests/testthat/test-mcmc-combo.R @@ -1,6 +1,3 @@ -library(bayesplot) -context("MCMC: combo") - source(test_path("data-for-mcmc-tests.R")) test_that("mcmc_combo returns a gtable object", { diff --git a/tests/testthat/test-mcmc-diagnostics.R b/tests/testthat/test-mcmc-diagnostics.R index 3ebe0c37..5e95f46b 100644 --- a/tests/testthat/test-mcmc-diagnostics.R +++ b/tests/testthat/test-mcmc-diagnostics.R @@ -1,6 +1,3 @@ -library(bayesplot) -context("MCMC: diagnostics") - source(test_path("data-for-mcmc-tests.R")) test_that("rhat and neff plots return a ggplot object", { diff --git a/tests/testthat/test-mcmc-distributions.R b/tests/testthat/test-mcmc-distributions.R index 7b2ae9fa..5a6f670a 100644 --- a/tests/testthat/test-mcmc-distributions.R +++ b/tests/testthat/test-mcmc-distributions.R @@ -1,6 +1,3 @@ -library(bayesplot) -context("MCMC: distributions") - source(test_path("data-for-mcmc-tests.R")) get_palette <- function(ggplot, n) { diff --git a/tests/testthat/test-mcmc-intervals.R b/tests/testthat/test-mcmc-intervals.R index ee4a8bc4..88854753 100644 --- a/tests/testthat/test-mcmc-intervals.R +++ b/tests/testthat/test-mcmc-intervals.R @@ -1,9 +1,5 @@ -library(bayesplot) -context("MCMC: intervals") - source(test_path("data-for-mcmc-tests.R")) - test_that("mcmc_intervals_data computes quantiles", { xs <- melt_mcmc(merge_chains(prepare_mcmc_array(arr, pars = "beta[1]"))) d <- mcmc_intervals_data(arr, pars = "beta[1]", diff --git a/tests/testthat/test-mcmc-nuts.R b/tests/testthat/test-mcmc-nuts.R index c9f52a98..841a6bc4 100644 --- a/tests/testthat/test-mcmc-nuts.R +++ b/tests/testthat/test-mcmc-nuts.R @@ -1,6 +1,3 @@ -library(bayesplot) -context("MCMC: nuts") - if (requireNamespace("rstanarm", quietly = TRUE)) { ITER <- 1000 CHAINS <- 3 diff --git a/tests/testthat/test-mcmc-recover.R b/tests/testthat/test-mcmc-recover.R index a545caa8..2c8dd3eb 100644 --- a/tests/testthat/test-mcmc-recover.R +++ b/tests/testthat/test-mcmc-recover.R @@ -1,6 +1,3 @@ -library(bayesplot) -context("MCMC: recover") - set.seed(123) draws <- matrix(rnorm(4 * 1000), nrow = 1000) colnames(draws) <- c("alpha", "beta[1]", "beta[2]", "sigma") diff --git a/tests/testthat/test-mcmc-scatter-and-parcoord.R b/tests/testthat/test-mcmc-scatter-and-parcoord.R index b737515d..a0d22358 100644 --- a/tests/testthat/test-mcmc-scatter-and-parcoord.R +++ b/tests/testthat/test-mcmc-scatter-and-parcoord.R @@ -1,6 +1,3 @@ -library(bayesplot) -context("MCMC: scatter, hex, and parallel coordinates plots") - source(test_path("data-for-mcmc-tests.R")) if (requireNamespace("rstanarm", quietly = TRUE)) { diff --git a/tests/testthat/test-mcmc-traces.R b/tests/testthat/test-mcmc-traces.R index 2faec4b6..7d02b4ee 100644 --- a/tests/testthat/test-mcmc-traces.R +++ b/tests/testthat/test-mcmc-traces.R @@ -1,6 +1,3 @@ -library(bayesplot) -context("MCMC: traces") - source(test_path("data-for-mcmc-tests.R")) test_that("mcmc_trace returns a ggplot object", { diff --git a/tests/testthat/test-pp_check.R b/tests/testthat/test-pp_check.R index 0e56574a..b1a8ab81 100644 --- a/tests/testthat/test-pp_check.R +++ b/tests/testthat/test-pp_check.R @@ -1,6 +1,3 @@ -library(bayesplot) -context("PPC: pp_check generic and default method") - test_that("default pp_check method works", { y <- example_y_data() yrep <- example_yrep_draws() diff --git a/tests/testthat/test-ppc-censoring.R b/tests/testthat/test-ppc-censoring.R index d733c0ee..2224df7b 100644 --- a/tests/testthat/test-ppc-censoring.R +++ b/tests/testthat/test-ppc-censoring.R @@ -1,6 +1,3 @@ -library(bayesplot) -context("PPC: censoring") - source(test_path("data-for-ppc-tests.R")) test_that("ppc_km_overlay returns a ggplot object", { diff --git a/tests/testthat/test-ppc-discrete.R b/tests/testthat/test-ppc-discrete.R index c8e749a8..4bf788d0 100644 --- a/tests/testthat/test-ppc-discrete.R +++ b/tests/testthat/test-ppc-discrete.R @@ -1,6 +1,4 @@ -library(bayesplot) # suppressPackageStartupMessages(library(rstanarm)) -context("PPC: discrete") source(test_path("data-for-ppc-tests.R")) load(test_path("data-for-ordinal.rda")) diff --git a/tests/testthat/test-ppc-distributions.R b/tests/testthat/test-ppc-distributions.R index 6ab88d6e..c156223b 100644 --- a/tests/testthat/test-ppc-distributions.R +++ b/tests/testthat/test-ppc-distributions.R @@ -1,6 +1,3 @@ -library(bayesplot) -context("PPC: distributions") - source(test_path("data-for-ppc-tests.R")) test_that("ppc_dens_overlay returns a ggplot object", { diff --git a/tests/testthat/test-ppc-errors.R b/tests/testthat/test-ppc-errors.R index 1792e7b7..de4322aa 100644 --- a/tests/testthat/test-ppc-errors.R +++ b/tests/testthat/test-ppc-errors.R @@ -1,6 +1,3 @@ -library(bayesplot) -context("PPC: predictive errors") - source(test_path("data-for-ppc-tests.R")) test_that("ppc_error_hist and ppc_error_scatter return ggplot object", { diff --git a/tests/testthat/test-ppc-input-validation.R b/tests/testthat/test-ppc-input-validation.R index c0b77955..c32a6cfe 100644 --- a/tests/testthat/test-ppc-input-validation.R +++ b/tests/testthat/test-ppc-input-validation.R @@ -1,6 +1,3 @@ -library(bayesplot) -context("PPC: input validation") - source(test_path("data-for-ppc-tests.R")) test_that("validate_y works", { diff --git a/tests/testthat/test-ppc-intervals.R b/tests/testthat/test-ppc-intervals.R index d1d7aa9d..a1499303 100644 --- a/tests/testthat/test-ppc-intervals.R +++ b/tests/testthat/test-ppc-intervals.R @@ -1,6 +1,3 @@ -library(bayesplot) -context("PPC: intervals & ribbon") - source(test_path("data-for-ppc-tests.R")) test_that("ppc_intervals returns ggplot object", { diff --git a/tests/testthat/test-ppc-loo.R b/tests/testthat/test-ppc-loo.R index 6e3f34ca..9381692f 100644 --- a/tests/testthat/test-ppc-loo.R +++ b/tests/testthat/test-ppc-loo.R @@ -1,6 +1,3 @@ -library(bayesplot) -context("PPC: loo") - options(useFancyQuotes = FALSE) if (requireNamespace("rstanarm", quietly = TRUE) && diff --git a/tests/testthat/test-ppc-scatterplots.R b/tests/testthat/test-ppc-scatterplots.R index 9116b115..02494796 100644 --- a/tests/testthat/test-ppc-scatterplots.R +++ b/tests/testthat/test-ppc-scatterplots.R @@ -1,6 +1,3 @@ -library(bayesplot) -context("PPC: scatterplots") - source(test_path("data-for-ppc-tests.R")) test_that("ppc_scatter returns ggplot object", { diff --git a/tests/testthat/test-ppc-test-statistics.R b/tests/testthat/test-ppc-test-statistics.R index 73acbe79..bc95ccc3 100644 --- a/tests/testthat/test-ppc-test-statistics.R +++ b/tests/testthat/test-ppc-test-statistics.R @@ -1,6 +1,3 @@ -library(bayesplot) -context("PPC: test-statistics") - source(test_path("data-for-ppc-tests.R")) q25 <- function(x) quantile(x, 0.25) From a5e97675aedd02b31a2c0465163ee0e7ebb25e28 Mon Sep 17 00:00:00 2001 From: VisruthSK <67435125+VisruthSK@users.noreply.github.com> Date: Sun, 7 Dec 2025 19:09:20 -0800 Subject: [PATCH 3/6] Used new environment ignoring argument, tolerance instead of tol, and expect_equal() with ignore_attr = TRUE instead of equivalent --- tests/testthat/test-aesthetics.R | 18 +++++++++--------- tests/testthat/test-convenience-functions.R | 18 +++++++++--------- tests/testthat/test-example-draws.R | 2 +- tests/testthat/test-extractors.R | 6 +++--- tests/testthat/test-helpers-mcmc.R | 4 ++-- tests/testthat/test-mcmc-intervals.R | 4 ++-- .../testthat/test-mcmc-scatter-and-parcoord.R | 12 ++++++------ tests/testthat/test-pp_check.R | 4 ++-- tests/testthat/test-ppc-discrete.R | 6 +++--- tests/testthat/test-ppc-input-validation.R | 2 +- 10 files changed, 38 insertions(+), 38 deletions(-) diff --git a/tests/testthat/test-aesthetics.R b/tests/testthat/test-aesthetics.R index fade8bcf..1ab27c92 100644 --- a/tests/testthat/test-aesthetics.R +++ b/tests/testthat/test-aesthetics.R @@ -9,12 +9,12 @@ prepare_colors_for_test <- function(scheme) { test_that("getting and setting the color scheme works", { color_scheme_set("red") - expect_equivalent(color_scheme_get(), prepare_colors_for_test("red")) + expect_equal(color_scheme_get(), prepare_colors_for_test("red"), ignore_attr = TRUE) expect_named(prepare_colors_for_test("blue"), scheme_level_names()) expect_named(color_scheme_get(), scheme_level_names()) for (clr in names(master_color_list)) { color_scheme_set(clr) - expect_equivalent(color_scheme_get(), prepare_colors_for_test(clr), + expect_equal(color_scheme_get(), prepare_colors_for_test(clr, ignore_attr = TRUE), info = clr) expect_named(color_scheme_get(), scheme_level_names()) } @@ -24,7 +24,7 @@ test_that("getting and setting the color scheme works", { expect_gg(plot(color_scheme_get("mix-blue-green"))) color_scheme_set("blue") - expect_equivalent(color_scheme_get("teal"), prepare_colors_for_test("teal")) + expect_equal(color_scheme_get("teal"), prepare_colors_for_test("teal"), ignore_attr = TRUE) # error if not character expect_error(color_scheme_set(7), "'scheme' should be a character vector of length 1 or 6") @@ -56,10 +56,10 @@ test_that("color_scheme_get with i argument works", { test_that("setting mixed scheme works", { color_scheme_set("mix-gray-blue") - expect_equivalent(color_scheme_get(), mixed_scheme("gray", "blue")) + expect_equal(color_scheme_get(), mixed_scheme("gray", "blue"), ignore_attr = TRUE) color_scheme_set("mix-blue-gray") - expect_equivalent(color_scheme_get(), mixed_scheme("blue", "gray")) + expect_equal(color_scheme_get(), mixed_scheme("blue", "gray"), ignore_attr = TRUE) expect_error(color_scheme_set("mix-green-reds"), "should be one of") expect_error(color_scheme_set("mix-greens-red"), "should be one of") @@ -68,9 +68,9 @@ test_that("setting mixed scheme works", { test_that("setting brewer scheme works", { skip_if_not_installed("RColorBrewer") color_scheme_set("brewer-Blues") - expect_equivalent(unlist(color_scheme_get()), RColorBrewer::brewer.pal(6, "Blues")) + expect_equal(unlist(color_scheme_get()), RColorBrewer::brewer.pal(6, "Blues"), ignore_attr = TRUE) color_scheme_set("brewer-Spectral") - expect_equivalent(unlist(color_scheme_get()), RColorBrewer::brewer.pal(6, "Spectral")) + expect_equal(unlist(color_scheme_get()), RColorBrewer::brewer.pal(6, "Spectral"), ignore_attr = TRUE) expect_error(color_scheme_set("brewer-FAKE"), "FAKE is not a valid palette") }) @@ -102,11 +102,11 @@ test_that("mixed_scheme internal function doesn't error", { test_that("custom color schemes work", { color_scheme_set(orange_scheme_ok) expect_named(color_scheme_get()) - expect_equivalent(unlist(color_scheme_get()), orange_scheme_ok) + expect_equal(unlist(color_scheme_get()), orange_scheme_ok, ignore_attr = TRUE) random_scheme <- colors()[sample(length(colors()), 6)] color_scheme_set(random_scheme) - expect_equivalent(unlist(color_scheme_get()), random_scheme) + expect_equal(unlist(color_scheme_get()), random_scheme, ignore_attr = TRUE) }) test_that("get_color returns correct color values", { diff --git a/tests/testthat/test-convenience-functions.R b/tests/testthat/test-convenience-functions.R index 3505211d..3b6fe9f6 100644 --- a/tests/testthat/test-convenience-functions.R +++ b/tests/testthat/test-convenience-functions.R @@ -5,35 +5,35 @@ test_that("abline_01 returns the correct object", { a <- abline_01(color = "green", linetype = 2) b <- geom_abline(intercept = 0, slope = 1, color = "green", linetype = 2, na.rm = TRUE) a$constructor <- b$constructor <- NULL - expect_equal(a, b, check.environment = FALSE) + expect_equal(a, b, ignore_function_env = TRUE) }) test_that("vline_* and hline_* return correct objects", { a <- vline_0(color = "red") b <- geom_vline(xintercept = 0, color = "red", na.rm = TRUE) a$constructor <- b$constructor <- NULL - expect_equal(a, b, check.environment = FALSE) + expect_equal(a, b, ignore_function_env = TRUE) a <- hline_0(linewidth = 2, linetype = 3) b <- geom_hline(yintercept = 0, linewidth = 2, linetype = 3, na.rm = TRUE) a$constructor <- b$constructor <- NULL - expect_equal(a, b, check.environment = FALSE) + expect_equal(a, b, ignore_function_env = TRUE) a <- vline_at(c(3,4), na.rm = FALSE) b <- geom_vline(xintercept = c(3,4)) a$constructor <- b$constructor <- NULL - expect_equal(a, b, check.environment = FALSE) + expect_equal(a, b, ignore_function_env = TRUE) a <- hline_at(c(3,4), na.rm = FALSE) b <- geom_hline(yintercept = c(3,4)) a$constructor <- b$constructor <- NULL - expect_equal(a, b, check.environment = FALSE) + expect_equal(a, b, ignore_function_env = TRUE) }) test_that("vline_at with 'fun' works", { x <- example_mcmc_draws(chains = 1) a <- vline_at(x, colMeans) b <- geom_vline(xintercept = colMeans(x), na.rm = TRUE) a$constructor <- b$constructor <- NULL - expect_equal(a, b, check.environment = FALSE) + expect_equal(a, b, ignore_function_env = TRUE) }) test_that("calc_v (internal function) works", { a <- 1:4 @@ -96,13 +96,13 @@ test_that("facet_bg returns correct theme object", { test_that("legend_none returns correct theme object", { none <- legend_none() expect_s3_class(none, "theme") - expect_equivalent(none, list(legend.position = "none")) + expect_equal(none, list(legend.position = "none"), ignore_attr = TRUE) expect_false(attr(none, "complete")) }) test_that("legend_move returns correct theme object", { left <- legend_move("left") expect_s3_class(left, "theme") - expect_equivalent(left, list(legend.position = "left")) + expect_equal(left, list(legend.position = "left"), ignore_attr = TRUE) expect_false(attr(left, "complete")) pos <- legend_move(c(0.25, 0.5)) @@ -182,7 +182,7 @@ test_that("overlay_function returns the correct object", { a <- overlay_function(fun = "dnorm") b <- stat_function(fun = "dnorm", inherit.aes = FALSE) a$constructor <- b$constructor <- NULL - expect_equal(a, b, check.environment = FALSE) + expect_equal(a, b, ignore_function_env = TRUE) }) diff --git a/tests/testthat/test-example-draws.R b/tests/testthat/test-example-draws.R index cc4317aa..c36e82af 100644 --- a/tests/testthat/test-example-draws.R +++ b/tests/testthat/test-example-draws.R @@ -23,7 +23,7 @@ test_that("example ppc data works", { yrep <- example_yrep_draws() expect_type(yrep, "double") - expect_is(yrep, "matrix") + expect_true(is.matrix(yrep)) expect_equal(ncol(yrep), length(y)) group <- example_group_data() diff --git a/tests/testthat/test-extractors.R b/tests/testthat/test-extractors.R index 236f6704..53e9862c 100644 --- a/tests/testthat/test-extractors.R +++ b/tests/testthat/test-extractors.R @@ -81,7 +81,7 @@ test_that("neff_ratio.stanreg returns correct structure", { ratio <- neff_ratio(fit) expect_named(ratio) ans <- summary(fit)[1:length(ratio), "n_eff"] / (floor(ITER / 2) * CHAINS) - expect_equal(ratio, ans, tol = 0.001) + expect_equal(ratio, ans, tolerance = 0.001) }) test_that("rhat.stanfit returns correct structure", { @@ -104,12 +104,12 @@ test_that("neff_ratio.stanreg returns correct structure", { ratio <- neff_ratio(fit$stanfit) expect_named(ratio) ans <- summary(fit)[, "n_eff"] / denom - expect_equal(ratio, ans, tol = 0.001) + expect_equal(ratio, ans, tolerance = 0.001) ratio2 <- neff_ratio(fit$stanfit, pars = c("wt", "sigma")) expect_named(ratio2) ans2 <- summary(fit, pars = c("wt", "sigma"))[, "n_eff"] / denom - expect_equal(ratio2, ans2, tol = 0.001) + expect_equal(ratio2, ans2, tolerance = 0.001) }) test_that("cmdstanr methods work", { diff --git a/tests/testthat/test-helpers-mcmc.R b/tests/testthat/test-helpers-mcmc.R index 26fbcdd3..04f1aee4 100644 --- a/tests/testthat/test-helpers-mcmc.R +++ b/tests/testthat/test-helpers-mcmc.R @@ -298,7 +298,7 @@ test_that("diagnostic_factor.rhat works", { high = 1.2, high = 1.7)) r <- diagnostic_factor(unname(rhats)) - expect_equivalent(r, as.factor(names(rhats))) + expect_equal(r, as.factor(names(rhats)), ignore_attr = TRUE) expect_identical(levels(r), c("low", "ok", "high")) }) test_that("diagnostic_factor.neff_ratio works", { @@ -307,7 +307,7 @@ test_that("diagnostic_factor.neff_ratio works", { high = 0.51, high = 0.99, high = 1)) r <- diagnostic_factor(unname(ratios)) - expect_equivalent(r, as.factor(names(ratios))) + expect_equal(r, as.factor(names(ratios)), ignore_attr = TRUE) expect_identical(levels(r), c("low", "ok", "high")) }) diff --git a/tests/testthat/test-mcmc-intervals.R b/tests/testthat/test-mcmc-intervals.R index 88854753..907d8997 100644 --- a/tests/testthat/test-mcmc-intervals.R +++ b/tests/testthat/test-mcmc-intervals.R @@ -7,7 +7,7 @@ test_that("mcmc_intervals_data computes quantiles", { qs <- unlist(d[, c("ll", "l", "m", "h", "hh")]) by_hand <- quantile(xs$Value, c(.25, .35, .5, .65, .75)) - expect_equivalent(qs, by_hand) + expect_equal(qs, by_hand, ignore_attr = TRUE) expect_equal(d$parameter, factor("beta[1]")) expect_equal(d$outer_width, .5) @@ -26,7 +26,7 @@ test_that("mcmc_intervals_data computes point estimates", { d <- mcmc_intervals_data(arr, pars = "beta[2]", prob = .3, prob_outer = .5, point_est = "mean") - expect_equivalent(d$m, mean(xs$Value)) + expect_equal(d$m, mean(xs$Value), ignore_attr = TRUE) expect_equal(d$parameter, factor("beta[2]")) expect_equal(d$point_est, "mean") diff --git a/tests/testthat/test-mcmc-scatter-and-parcoord.R b/tests/testthat/test-mcmc-scatter-and-parcoord.R index a0d22358..570e06e8 100644 --- a/tests/testthat/test-mcmc-scatter-and-parcoord.R +++ b/tests/testthat/test-mcmc-scatter-and-parcoord.R @@ -210,40 +210,40 @@ test_that("pairs_condition returns correct structure", { # default cond0 <- pairs_condition() expect_s3_class(cond0, "pairs_condition") - expect_equivalent(unclass(cond0), list()) + expect_equal(unclass(cond0), list(), ignore_attr = TRUE) expect_equal(attr(cond0, "type"), "default") # chains cond1 <- pairs_condition(chains = 1:4) expect_s3_class(cond1, "integer") expect_s3_class(cond1, "pairs_condition") - expect_equivalent(unclass(cond1), 1:4) + expect_equal(unclass(cond1), 1:4, ignore_attr = TRUE) expect_equal(attr(cond1, "type"), "chain_vector") cond2 <- pairs_condition(chains = list(1:4, 5:6)) expect_s3_class(cond2, "list") expect_s3_class(cond2, "pairs_condition") - expect_equivalent(unclass(cond2), list(upper=1:4, lower=5:6)) + expect_equal(unclass(cond2), list(upper=1:4, lower=5:6), ignore_attr = TRUE) expect_equal(attr(cond2, "type"), "chain_list") # draws cond3 <- pairs_condition(draws = 0.7) expect_s3_class(cond3, "numeric") expect_s3_class(cond3, "pairs_condition") - expect_equivalent(unclass(cond3), 0.7) + expect_equal(unclass(cond3), 0.7, ignore_attr = TRUE) expect_equal(attr(cond3, "type"), "draws_proportion") cond4 <- pairs_condition(draws = c(T, F, T)) expect_s3_class(cond4, "logical") expect_s3_class(cond4, "pairs_condition") - expect_equivalent(unclass(cond4), c(T, F, T)) + expect_equal(unclass(cond4), c(T, F, T), ignore_attr = TRUE) expect_equal(attr(cond4, "type"), "draws_selection") # nuts cond5 <- pairs_condition(nuts = "lp__") expect_s3_class(cond5, "character") expect_s3_class(cond5, "pairs_condition") - expect_equivalent(unclass(cond5), "lp__") + expect_equal(unclass(cond5), "lp__", ignore_attr = TRUE) expect_equal(attr(cond5, "type"), "nuts") }) diff --git a/tests/testthat/test-pp_check.R b/tests/testthat/test-pp_check.R index b1a8ab81..d4bcb598 100644 --- a/tests/testthat/test-pp_check.R +++ b/tests/testthat/test-pp_check.R @@ -6,12 +6,12 @@ test_that("default pp_check method works", { expect_equal( pp_check(y, yrep[1:50, ], ppc_dens_overlay), ppc_dens_overlay(y, yrep[1:50, ]), - check.environment = FALSE + ignore_function_env = TRUE ) expect_equal( pp_check(y, yrep, fun = "stat_grouped", group = g, stat = "median"), ppc_stat_grouped(y, yrep, group = g, stat = "median"), - check.environment = FALSE + ignore_function_env = TRUE ) }) diff --git a/tests/testthat/test-ppc-discrete.R b/tests/testthat/test-ppc-discrete.R index 4bf788d0..005fdc94 100644 --- a/tests/testthat/test-ppc-discrete.R +++ b/tests/testthat/test-ppc-discrete.R @@ -72,9 +72,9 @@ test_that("ppc_bars_data includes all levels", { d3 <- ppc_bars_data(y_ord, yrep_ord2) expect_equal(d3$x, 1:4) expect_equal(d3$y_obs, tab) - expect_equivalent(d3$l[2], 0) - expect_equivalent(d3$m[2], 0) - expect_equivalent(d3$h[2], 0) + expect_equal(d3$l[2], 0, ignore_attr = TRUE) + expect_equal(d3$m[2], 0, ignore_attr = TRUE) + expect_equal(d3$h[2], 0, ignore_attr = TRUE) }) diff --git a/tests/testthat/test-ppc-input-validation.R b/tests/testthat/test-ppc-input-validation.R index c32a6cfe..d9740976 100644 --- a/tests/testthat/test-ppc-input-validation.R +++ b/tests/testthat/test-ppc-input-validation.R @@ -20,7 +20,7 @@ test_that("validate_predictions works", { expect_equal(validate_predictions(yrep2, length(y2)), yrep2) colnames(yrep) <- paste0("yrep", 1:ncol(yrep)) - expect_equivalent(validate_predictions(yrep, length(y)), unname(yrep)) + expect_equal(validate_predictions(yrep, length(y)), unname(yrep), ignore_attr = TRUE) }) test_that("validate_predictions throws errors", { expect_error(validate_predictions(as.matrix(LETTERS), length(y)), "numeric") From 12efa67a85fbe74dd269fb3269c3ac0c16f58262 Mon Sep 17 00:00:00 2001 From: VisruthSK <67435125+VisruthSK@users.noreply.github.com> Date: Sun, 7 Dec 2025 19:24:04 -0800 Subject: [PATCH 4/6] Straggler replacements and fixed some tests for compat with ggplot 4 --- tests/testthat/test-aesthetics.R | 4 ++-- tests/testthat/test-convenience-functions.R | 14 ++++++++------ tests/testthat/test-helpers-mcmc.R | 12 ++++++++++-- tests/testthat/test-mcmc-intervals.R | 4 ++-- tests/testthat/test-ppc-distributions.R | 2 +- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/tests/testthat/test-aesthetics.R b/tests/testthat/test-aesthetics.R index 1ab27c92..067d44c0 100644 --- a/tests/testthat/test-aesthetics.R +++ b/tests/testthat/test-aesthetics.R @@ -14,8 +14,8 @@ test_that("getting and setting the color scheme works", { expect_named(color_scheme_get(), scheme_level_names()) for (clr in names(master_color_list)) { color_scheme_set(clr) - expect_equal(color_scheme_get(), prepare_colors_for_test(clr, ignore_attr = TRUE), - info = clr) + expect_equal(color_scheme_get(), prepare_colors_for_test(clr), + info = clr, ignore_attr = TRUE) expect_named(color_scheme_get(), scheme_level_names()) } diff --git a/tests/testthat/test-convenience-functions.R b/tests/testthat/test-convenience-functions.R index 3b6fe9f6..7b197f27 100644 --- a/tests/testthat/test-convenience-functions.R +++ b/tests/testthat/test-convenience-functions.R @@ -96,20 +96,21 @@ test_that("facet_bg returns correct theme object", { test_that("legend_none returns correct theme object", { none <- legend_none() expect_s3_class(none, "theme") - expect_equal(none, list(legend.position = "none"), ignore_attr = TRUE) + expect_equal(none$legend.position, "none", ignore_attr = TRUE) expect_false(attr(none, "complete")) }) test_that("legend_move returns correct theme object", { left <- legend_move("left") expect_s3_class(left, "theme") - expect_equal(left, list(legend.position = "left"), ignore_attr = TRUE) + expect_equal(left$legend.position, "left", ignore_attr = TRUE) expect_false(attr(left, "complete")) pos <- legend_move(c(0.25, 0.5)) expect_s3_class(pos, "theme") - expect_equivalent( + expect_equal( pos$legend.position.inside %||% pos$legend.position, - c(0.25, 0.5) + c(0.25, 0.5), + ignore_attr = TRUE ) expect_false(attr(pos, "complete")) }) @@ -130,9 +131,10 @@ test_that("xaxis_text returns correct theme object", { }) test_that("yaxis_text returns correct theme object", { expect_identical(yaxis_text(FALSE), theme(axis.text.y = element_blank())) - expect_equivalent( + expect_equal( yaxis_text(face = "bold", angle = 30), - theme(axis.text.y = element_text(face = "bold", angle = 30)) + theme(axis.text.y = element_text(face = "bold", angle = 30)), + ignore_attr = TRUE ) }) test_that("facet_text returns correct theme object", { diff --git a/tests/testthat/test-helpers-mcmc.R b/tests/testthat/test-helpers-mcmc.R index 04f1aee4..63a532f3 100644 --- a/tests/testthat/test-helpers-mcmc.R +++ b/tests/testthat/test-helpers-mcmc.R @@ -298,7 +298,11 @@ test_that("diagnostic_factor.rhat works", { high = 1.2, high = 1.7)) r <- diagnostic_factor(unname(rhats)) - expect_equal(r, as.factor(names(rhats)), ignore_attr = TRUE) + expect_equal( + r, + factor(names(rhats), levels = c("low", "ok", "high")), + ignore_attr = TRUE + ) expect_identical(levels(r), c("low", "ok", "high")) }) test_that("diagnostic_factor.neff_ratio works", { @@ -307,7 +311,11 @@ test_that("diagnostic_factor.neff_ratio works", { high = 0.51, high = 0.99, high = 1)) r <- diagnostic_factor(unname(ratios)) - expect_equal(r, as.factor(names(ratios)), ignore_attr = TRUE) + expect_equal( + r, + factor(names(ratios), levels = c("low", "ok", "high")), + ignore_attr = TRUE + ) expect_identical(levels(r), c("low", "ok", "high")) }) diff --git a/tests/testthat/test-mcmc-intervals.R b/tests/testthat/test-mcmc-intervals.R index 907d8997..e1794bf0 100644 --- a/tests/testthat/test-mcmc-intervals.R +++ b/tests/testthat/test-mcmc-intervals.R @@ -130,8 +130,8 @@ test_that("mcmc_areas_data computes density", { densities <- lapply(raw_values, do_dens, 1, 1024) for (name in names(by_parameter)) { - expect_equivalent(by_parameter[[name]][["density"]], - densities[[name]][["y"]]) + expect_equal(by_parameter[[name]][["density"]], + densities[[name]][["y"]], ignore_attr = TRUE) } }) diff --git a/tests/testthat/test-ppc-distributions.R b/tests/testthat/test-ppc-distributions.R index c156223b..5f7293c8 100644 --- a/tests/testthat/test-ppc-distributions.R +++ b/tests/testthat/test-ppc-distributions.R @@ -36,7 +36,7 @@ test_that("ppc_dens,pp_hist,ppc_freqpoly,ppc_boxplot return ggplot objects", { expect_gg(p <- ppc_hist(y, yrep[1:8, ], binwidth = 3)) if (utils::packageVersion("ggplot2") >= "3.0.0") { facet_var <- vars(rep_label) - expect_equal(p$facet$params$facets[[1]], facet_var[[1]]) + expect_equal(p$facet$params$facets[[1]], facet_var[[1]], ignore_function_env = TRUE, ignore_formula_env = TRUE) } # ppd versions From fa244b92ac090332eebe4f433e7bdc7536616ae6 Mon Sep 17 00:00:00 2001 From: VisruthSK <67435125+VisruthSK@users.noreply.github.com> Date: Sun, 7 Dec 2025 20:07:19 -0800 Subject: [PATCH 5/6] Setup parallel testing and selected some slow tests to run first --- DESCRIPTION | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DESCRIPTION b/DESCRIPTION index df6b5f7d..31f240d4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -63,3 +63,5 @@ VignetteBuilder: knitr Encoding: UTF-8 Roxygen: list(markdown = TRUE) Config/testthat/edition: 3 +Config/testthat/parallel: true +Config/testthat/start-first: mcmc-scatter-and-parcoord, ppc-distributions, mcmc-intervals, extractors From 1da4d233eef1067da8086a6d2eaca65b0e957e9f Mon Sep 17 00:00:00 2001 From: jgabry Date: Mon, 8 Dec 2025 11:28:09 -0700 Subject: [PATCH 6/6] see if disabling parallel tests fixes GHA issue --- DESCRIPTION | 2 -- 1 file changed, 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 31f240d4..df6b5f7d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -63,5 +63,3 @@ VignetteBuilder: knitr Encoding: UTF-8 Roxygen: list(markdown = TRUE) Config/testthat/edition: 3 -Config/testthat/parallel: true -Config/testthat/start-first: mcmc-scatter-and-parcoord, ppc-distributions, mcmc-intervals, extractors