Replace mockery with withr in Suggests and tests

This commit is contained in:
gnoblet 2025-07-02 13:34:11 +02:00
parent 201fe39973
commit 1584bdca30
3 changed files with 22 additions and 34 deletions

View file

@ -36,7 +36,7 @@ Suggests:
roxygen2, roxygen2,
testthat (>= 3.0.0), testthat (>= 3.0.0),
vdiffr, vdiffr,
mockery withr
VignetteBuilder: VignetteBuilder:
knitr knitr
Config/testthat/edition: 3 Config/testthat/edition: 3

View file

@ -47,4 +47,5 @@ vdiffr
VignetteBuilder VignetteBuilder
viridisLite viridisLite
visualizeR visualizeR
withr
zaclys zaclys

View file

@ -47,41 +47,28 @@ test_that("palette_gen returns appropriate function types", {
expect_true(is.function(div_fn)) expect_true(is.function(div_fn))
}) })
test_that("palette_gen forwards arguments to appropriate function", { test_that("palette_gen dispatches to correct function types", {
# Skip the test if mockery is not available # Test for categorical type
skip_if_not_installed("mockery") cat_result <- palette_gen("cat_5_main", "categorical", direction = -1)
skip_if_not(exists("with_mocked_bindings")) expect_true(is.function(cat_result))
# Create a mock for palette_gen_categorical # Verify it behaves like a categorical palette function
mockery::with_mocked_bindings( expect_equal(length(cat_result(3)), 3)
palette_gen_categorical = function(palette, direction) { expect_type(cat_result(3), "character")
return(list(
palette = palette,
direction = direction,
type = "categorical"
))
},
palette_gen_sequential = function(palette, direction, ...) {
return(list(
palette = palette,
direction = direction,
type = "sequential"
))
},
code = {
# Test categorical forwarding
result <- palette_gen("cat_palette", "categorical", direction = -1)
expect_equal(result$palette, "cat_palette")
expect_equal(result$direction, -1)
expect_equal(result$type, "categorical")
# Test sequential forwarding # Test for sequential type
result <- palette_gen("seq_palette", "sequential", direction = -1) seq_result <- palette_gen("cat_5_main", "sequential", direction = -1)
expect_equal(result$palette, "seq_palette") expect_true(is.function(seq_result))
expect_equal(result$direction, -1)
expect_equal(result$type, "sequential") # Verify it behaves like a sequential palette function
} expect_equal(length(seq_result(5)), 5)
) expect_type(seq_result(5), "character")
# Test for divergent type - should work like sequential
div_result <- palette_gen("div_5_orange_blue", "divergent", direction = -1)
expect_true(is.function(div_result))
expect_equal(length(div_result(7)), 7)
expect_type(div_result(7), "character")
}) })
test_that("palette_gen_categorical validates parameters", { test_that("palette_gen_categorical validates parameters", {