Skip to content

Commit

Permalink
Fix a bunch of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
willgearty committed Jul 30, 2024
1 parent aa0adcd commit cca83e6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
29 changes: 24 additions & 5 deletions tests/testthat/test-add_phylopic.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,31 @@ test_that("add_phylopic works", {
plot(p)
})

p <- ggplot(data.frame(cat.x = posx, cat.y = posy), aes(cat.x, cat.y)) +
geom_blank()
cat_svg <- get_phylopic("23cd6aa4-9587-4a2e-8e26-de42885004c9")
# Expect error
expect_error(add_phylopic(img = "cat"))
expect_error(add_phylopic(cat, name = "cat"))
expect_error(add_phylopic(cat_svg, name = "cat"))
expect_error(add_phylopic())
expect_error(add_phylopic(cat, alpha = 3))
expect_error(add_phylopic(name = 42))
expect_error(add_phylopic(name = "bueller"))
expect_error(add_phylopic(uuid = 42))
expect_error({
plot(p + add_phylopic(cat_svg, alpha = 3, x = 5, y = 5))
})
expect_error({
plot(p + add_phylopic(cat_svg, hjust = 3, x = 5, y = 5))
})
expect_error({
plot(p + add_phylopic(cat_svg, vjust = 3, x = 5, y = 5))
})
expect_error({
plot(p + add_phylopic(name = 42, x = 5, y = 5, verbose = TRUE))
})
expect_error({
plot(p + add_phylopic(uuid = 42, x = 5, y = 5, verbose = TRUE))
})

# Expect warning
expect_warning({
plot(p + add_phylopic(name = "bueller", x = 5, y = 5, verbose = TRUE))
})
})
14 changes: 8 additions & 6 deletions tests/testthat/test-add_phylopic_base.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,20 @@ test_that("add_phylopic_base works", {
verbose = TRUE)))
expect_warning(add_phylopic_base(uuid = "jkl;daf", filter = "by"))

cat_svg <- get_phylopic("23cd6aa4-9587-4a2e-8e26-de42885004c9")
lifecycle::expect_deprecated({
add_phylopic_base(name = "Felis silvestris catus", ysize = .7)
add_phylopic_base(cat_svg, ysize = .7)
})

# Expect error
expect_error(add_phylopic_base(img = "cat"))
expect_error(add_phylopic_base(img = cat, verbose = "yes"))
expect_error(add_phylopic_base(cat, name = "cat"))
expect_error(add_phylopic_base(img = cat_svg, verbose = "yes"))
expect_error(add_phylopic_base(cat_svg, name = "cat"))
expect_error(add_phylopic_base())
expect_error(add_phylopic_base(cat, alpha = 3))
expect_error(add_phylopic_base(cat_svg, alpha = 3))
expect_error(add_phylopic_base(name = 42))
expect_error(add_phylopic_base(uuid = 42))
expect_error(add_phylopic_base(name = "Felis silvestris catus",
height = 5, width = 5))
expect_error(add_phylopic_base(cat_svg, height = 5, width = 5))
expect_error(add_phylopic_base(cat_svg, hjust = 5))
expect_error(add_phylopic_base(cat_svg, vjust = 5))
})
6 changes: 6 additions & 0 deletions tests/testthat/test-geom_phylopic.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ test_that("geom_phylopic works", {
gg <- ggplot(df) +
geom_phylopic(aes(x = x, y = y), img = -5)
expect_error(plot(gg))
gg <- ggplot(df) +
geom_phylopic(aes(x = x, y = y, uuid = uuid), hjust = 5)
expect_error(plot(gg))
gg <- ggplot(df) +
geom_phylopic(aes(x = x, y = y, uuid = uuid), vjust = 5)
expect_error(plot(gg))
gg <- ggplot(df) +
geom_phylopic(aes(x = x, y = y), name = "asdfghjkl", verbose = TRUE)
expect_warning(plot(gg))
Expand Down

0 comments on commit cca83e6

Please sign in to comment.