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,
testthat (>= 3.0.0),
vdiffr,
mockery
withr
VignetteBuilder:
knitr
Config/testthat/edition: 3

View file

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

View file

@ -47,41 +47,28 @@ test_that("palette_gen returns appropriate function types", {
expect_true(is.function(div_fn))
})
test_that("palette_gen forwards arguments to appropriate function", {
# Skip the test if mockery is not available
skip_if_not_installed("mockery")
skip_if_not(exists("with_mocked_bindings"))
test_that("palette_gen dispatches to correct function types", {
# Test for categorical type
cat_result <- palette_gen("cat_5_main", "categorical", direction = -1)
expect_true(is.function(cat_result))
# Create a mock for palette_gen_categorical
mockery::with_mocked_bindings(
palette_gen_categorical = function(palette, direction) {
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")
# Verify it behaves like a categorical palette function
expect_equal(length(cat_result(3)), 3)
expect_type(cat_result(3), "character")
# Test sequential forwarding
result <- palette_gen("seq_palette", "sequential", direction = -1)
expect_equal(result$palette, "seq_palette")
expect_equal(result$direction, -1)
expect_equal(result$type, "sequential")
}
)
# Test for sequential type
seq_result <- palette_gen("cat_5_main", "sequential", direction = -1)
expect_true(is.function(seq_result))
# 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", {