Skip to content

Commit 70a7edf

Browse files
committed
tests(pkg-r): Test that cleanup is correctly set in querychat_app()
1 parent 5e4aa7b commit 70a7edf

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

pkg-r/R/QueryChat.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ querychat_app <- function(
680680
cleanup <-
681681
is.data.frame(data_source) &&
682682
!in_shiny_session() &&
683-
interactive()
683+
is_interactive()
684684
}
685685

686686
qc <- QueryChat$new(

pkg-r/tests/testthat/test-QueryChat.R

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,39 @@ describe("normalize_data_source()", {
306306
})
307307
})
308308
})
309+
310+
test_that("querychat_app() only cleans up data frame sources on exit", {
311+
local_mocked_r6_class(
312+
QueryChat,
313+
public = list(
314+
initialize = function(..., cleanup) {
315+
# have to use an option because the code is evaluated in a far-away env
316+
options(.test_cleanup = cleanup)
317+
},
318+
app = function(...) {}
319+
)
320+
)
321+
withr::local_options(rlang_interactive = TRUE)
322+
323+
withr::with_options(list(.test_cleanup = NULL), {
324+
test_df <- new_test_df()
325+
querychat_app(test_df)
326+
cleanup_result <- getOption(".test_cleanup")
327+
expect_true(cleanup_result)
328+
})
329+
330+
withr::with_options(list(.test_cleanup = NULL), {
331+
test_ds <- local_data_frame_source(new_test_df())
332+
querychat_app(test_ds)
333+
cleanup_result <- getOption(".test_cleanup")
334+
expect_false(cleanup_result)
335+
})
336+
337+
withr::with_options(list(.test_cleanup = NULL), {
338+
con <- local_sqlite_connection(new_test_df())
339+
test_ds <- DBISource$new(con$conn, "test_table")
340+
querychat_app(test_ds)
341+
cleanup_result <- getOption(".test_cleanup")
342+
expect_false(cleanup_result)
343+
})
344+
})

0 commit comments

Comments
 (0)