Skip to content

Commit

Permalink
Remove test_select_bind_one()
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr authored and aviator-bot committed Dec 17, 2023
1 parent 1e5e456 commit 9c33f9f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 78 deletions.
73 changes: 12 additions & 61 deletions R/spec-meta-bind-.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ test_select_bind <- function(
...,
cast_fun = identity,
requires_names = NULL) {

force(bind_values)
test_expr <- run_bind_tester$fun(bind_values = bind_values, ...)

placeholder_funs <- get_placeholder_funs(ctx, requires_names)

lapply(
placeholder_funs,
test_select_bind_one,
con = con,
bind_values = bind_values,
is_null_check = ctx$tweaks$is_null_check,
cast_fun = cast_fun,
allow_na_rows_affected = ctx$tweaks$allow_na_rows_affected,
...
)
force(con)
is_null_check <- ctx$tweaks$is_null_check
force(cast_fun)
allow_na_rows_affected <- ctx$tweaks$allow_na_rows_affected

for (placeholder_fun in placeholder_funs) {
rlang::eval_bare(test_expr)
}
}

get_placeholder_funs <- function(ctx, requires_names = NULL) {
Expand Down Expand Up @@ -52,57 +54,6 @@ get_placeholder_funs <- function(ctx, requires_names = NULL) {
placeholder_funs
}

test_select_bind_one <- function(
# Run time
con,
placeholder_fun,
...,
is_null_check,
cast_fun = identity,
allow_na_rows_affected = FALSE,
# Spec time
bind_values,
query = TRUE,
skip_fun = NULL,
check_return_value = NULL,
patch_bind_values = NULL,
bind_error = NA,
is_repeated = FALSE,
is_premature_clear = FALSE,
is_untouched = FALSE) {

rlang::check_dots_empty()

test_expr <- run_bind_tester$fun(
bind_values = bind_values,
query = query,
skip_fun = skip_fun,
check_return_value = check_return_value,
patch_bind_values = patch_bind_values,
bind_error = bind_error,
is_repeated = is_repeated,
is_premature_clear = is_premature_clear,
is_untouched = is_untouched
)

rm(bind_values)
rm(query)
rm(skip_fun)
rm(check_return_value)
rm(patch_bind_values)
rm(bind_error)
rm(is_repeated)
rm(is_premature_clear)
rm(is_untouched)

force(placeholder_fun)
force(is_null_check)
force(cast_fun)
force(allow_na_rows_affected)

rlang::eval_bare(test_expr)
}


# make_placeholder_fun ----------------------------------------------------

Expand Down
33 changes: 16 additions & 17 deletions R/spec-meta-bind-runner.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ run_bind_tester <- list()
#' \pkg{DBI} clients execute parametrized statements as follows:
#'
run_bind_tester$fun <- function(
...,
# Spec time
bind_values,
query,
skip_fun,
check_return_value,
patch_bind_values,
bind_error,
is_repeated,
is_premature_clear,
is_untouched) {
...,
query = TRUE,
skip_fun = NULL,
check_return_value = NULL,
patch_bind_values = NULL,
bind_error = NA,
is_repeated = FALSE,
is_premature_clear = FALSE,
is_untouched = FALSE) {
rlang::check_dots_empty()
force(bind_values)
force(query)
Expand Down Expand Up @@ -193,12 +192,6 @@ run_bind_tester$fun <- function(
!!retrieve_expr
})

#' 1. Close the result set via [dbClearResult()].
clear_now_expr <- rlang::expr({
expect_error(dbClearResult(res), NA)
res <- NULL
})

early_exit <-
is_premature_clear ||
!is.na(bind_error) ||
Expand All @@ -207,7 +200,12 @@ run_bind_tester$fun <- function(
post_bind_expr <- if (!early_exit) rlang::expr({
!!not_untouched_expr
!!repeated_expr
!!clear_now_expr
})

#' 1. Close the result set via [dbClearResult()].
clear_now_expr <- if (!is_premature_clear) rlang::expr({
expect_error(dbClearResult(res), NA)
res <- NULL
})

test_expr <- rlang::expr({
Expand All @@ -219,6 +217,7 @@ run_bind_tester$fun <- function(
!!clear_expr
!!bind_expr
!!post_bind_expr
!!clear_now_expr
})

test_expr
Expand Down

0 comments on commit 9c33f9f

Please sign in to comment.