Skip to content

Commit

Permalink
basic tests for pal removal and addition
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpcouch committed Oct 10, 2024
1 parent afbdbfc commit d466e8c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
7 changes: 7 additions & 0 deletions R/pal-add-remove.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ pal_remove <- function(role) {
pal_env(),
c(paste0("system_prompt_", role), paste0("rs_pal_", role))
)


if (paste0(".last_pal_", role) %in% names(pal_env())) {
env_unbind(pal_env(), paste0(".last_pal_", role))
}

invisible()
}

supported_interfaces <- c("replace", "prefix", "suffix")
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/pal-add-remove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# pal addition and removal works

Code
pal_boopery
Message
-- A boopery pal using claude-3-5-sonnet-20240620.

26 changes: 26 additions & 0 deletions tests/testthat/test-pal-add-remove.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
test_that("pal addition and removal works", {
skip_if(identical(Sys.getenv("ANTHROPIC_API_KEY"), ""))
skip_if_not_installed("withr")
withr::local_options(.pal_fn = NULL, .pal_args = NULL)

boop_prompt <- "just reply with beep bop boop regardless of input"
pal_add("boopery", boop_prompt)

expect_equal(system_prompt_boopery, boop_prompt)
expect_true(is_function(rs_pal_boopery))
expect_true("system_prompt_boopery" %in% names(pal_env()))
expect_true("rs_pal_boopery" %in% names(pal_env()))

pal_boopery <- pal("boopery")
expect_snapshot(pal_boopery)
expect_true(".last_pal_boopery" %in% names(pal_env()))

res <- pal_boopery$chat("hey there")
expect_true(grepl("bop", res))

pal_remove("boopery")

expect_false(".last_pal_boopery" %in% names(pal_env()))
expect_false("system_prompt_boopery" %in% names(pal_env()))
expect_false("rs_pal_boopery" %in% names(pal_env()))
})

0 comments on commit d466e8c

Please sign in to comment.