Skip to content

Commit

Permalink
Merge branch 'f-test-select-dots' into f-inline-test-select
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Mar 30, 2024
2 parents da2601d + 5c43686 commit 9c82ad9
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions R/expectations.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ expect_invisible_true <- function(code) {

expect_equal_df <- function(actual, expected) {
factor_cols <- map_lgl(expected, is.factor)
expected[factor_cols] <- lapply(expected[factor_cols], as.character)
expected[factor_cols] <- map(expected[factor_cols], as.character)

asis_cols <- map_lgl(expected, inherits, "AsIs")
expected[asis_cols] <- lapply(expected[asis_cols], unclass)
expected[asis_cols] <- map(expected[asis_cols], unclass)

list_cols <- map_lgl(expected, is.list)

Expand Down
4 changes: 2 additions & 2 deletions R/run.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ get_skip_names <- function(skip) {
}
names_all <- names(spec_all)
names_all <- names_all[names_all != ""]
skip_flags_all <- lapply(paste0("(?:^(?:", skip, ")(?:|_[0-9]+)$)"), grepl, names_all, perl = TRUE)
skip_flags_all <- map(paste0("(?:^(?:", skip, ")(?:|_[0-9]+)$)"), grepl, names_all, perl = TRUE)
skip_used <- map_lgl(skip_flags_all, any)
if (!all(skip_used)) {
warning("Unused skip expressions: ", paste(skip[!skip_used], collapse = ", "),
Expand All @@ -129,7 +129,7 @@ get_run_only_tests <- function(tests, run_only) {
return(tests)
}

run_only_flags_all <- lapply(paste0("(?:^(?:", run_only, ")$)"), grepl, names_all, perl = TRUE)
run_only_flags_all <- map(paste0("(?:^(?:", run_only, ")$)"), grepl, names_all, perl = TRUE)
run_only_flag_all <- Reduce(`|`, run_only_flags_all)
run_only_tests <- names_all[run_only_flag_all]

Expand Down
8 changes: 4 additions & 4 deletions R/spec-arrow-append-table-arrow.R
Original file line number Diff line number Diff line change
Expand Up @@ -465,16 +465,16 @@ spec_arrow_append_table_arrow <- list(
arrow_append_table_arrow_roundtrip_mixed = function(con) {
#' Mixing column types in the same table is supported.
data <- list("a", 1L, 1.5)
data <- lapply(data, c, NA)
data <- map(data, c, NA)
expanded <- expand.grid(a = data, b = data, c = data)
tbl_in_list <- lapply(
tbl_in_list <- map(
seq_len(nrow(expanded)),
function(i) {
data.frame(lapply(expanded[i, ], unlist, recursive = FALSE))
data.frame(map(expanded[i, ], unlist, recursive = FALSE))
}
)

lapply(tbl_in_list, test_arrow_roundtrip, con = con)
map(tbl_in_list, test_arrow_roundtrip, con = con)
},

arrow_append_table_arrow_name = function(ctx, con) {
Expand Down
8 changes: 4 additions & 4 deletions R/spec-arrow-write-table-arrow.R
Original file line number Diff line number Diff line change
Expand Up @@ -698,16 +698,16 @@ spec_arrow_write_table_arrow <- list(
arrow_write_table_arrow_roundtrip_mixed = function(ctx, con) {
#' Mixing column types in the same table is supported.
data <- list("a", 1L, 1.5)
data <- lapply(data, c, NA)
data <- map(data, c, NA)
expanded <- expand.grid(a = data, b = data, c = data)
tbl_in_list <- lapply(
tbl_in_list <- map(
seq_len(nrow(expanded)),
function(i) {
as.data.frame(lapply(expanded[i, ], unlist, recursive = FALSE))
as.data.frame(map(expanded[i, ], unlist, recursive = FALSE))
}
)

lapply(tbl_in_list, test_arrow_roundtrip, con = con)
map(tbl_in_list, test_arrow_roundtrip, con = con)
},

#
Expand Down
4 changes: 2 additions & 2 deletions R/spec-driver-data-type.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ test_data_type <- function(ctx, dbObj) {
}
)

lapply(
map(
compact(expected_data_types),
expect_has_data_type
)
Expand All @@ -96,7 +96,7 @@ test_data_type <- function(ctx, dbObj) {

#' As-is objects (i.e., wrapped by [I()]) must be
#' supported and return the same results as their unwrapped counterparts.
lapply(
map(
compact(expected_data_types),
function(value) {
if (!is.null(value)) {
Expand Down
2 changes: 1 addition & 1 deletion R/spec-meta-bind-.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ test_select_bind_expr <- function(
get_placeholder_funs <- function(ctx, requires_names = NULL) {
placeholder_fun <- ctx$tweaks$placeholder_pattern
if (is.character(placeholder_fun)) {
placeholder_funs <- lapply(placeholder_fun, make_placeholder_fun)
placeholder_funs <- map(placeholder_fun, make_placeholder_fun)
} else if (is.function(placeholder_fun)) {
placeholder_funs <- list(placeholder_fun)
} else {
Expand Down
2 changes: 1 addition & 1 deletion R/spec-meta-bind-expr.R
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ spec_meta_bind_expr <- function(
test_select_bind_expr(
arrow = arrow,
bind = bind,
lapply(c(get_texts(), NA_character_), factor),
map(c(get_texts(), NA_character_), factor),
warn = if (bind == "df") TRUE,
dbitest_version = if (arrow == "query" && bind == "df") "1.7.99.13"
)
Expand Down
18 changes: 9 additions & 9 deletions R/spec-result-roundtrip.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ spec_result_roundtrip <- list(
data_date = function(ctx, con) {
#' - coercible using [as.Date()] for dates,
as_date_equals_to <- function(x) {
lapply(x, function(xx) {
map(x, function(xx) {
function(value) as.Date(value) == xx
})
}
Expand All @@ -87,7 +87,7 @@ spec_result_roundtrip <- list(
data_time = function(ctx, con) {
#' - coercible using [hms::as_hms()] for times,
as_hms_equals_to <- function(x) {
lapply(x, function(xx) {
map(x, function(xx) {
function(value) hms::as_hms(value) == xx
})
}
Expand Down Expand Up @@ -148,7 +148,7 @@ spec_result_roundtrip <- list(
}

char_values <- paste0("2015-01-", sprintf("%.2d", 1:12))
values <- lapply(char_values, as_numeric_date)
values <- map(char_values, as_numeric_date)
sql_names <- ctx$tweaks$date_cast(char_values)

test_select_with_null(.ctx = ctx, con, !!!setNames(values, sql_names))
Expand Down Expand Up @@ -202,7 +202,7 @@ spec_result_roundtrip <- list(
#' to the true value
data_64_bit_numeric = function(ctx, con) {
as_numeric_identical_to <- function(x) {
lapply(x, function(xx) {
map(x, function(xx) {
function(value) as.numeric(value) == xx
})
}
Expand All @@ -216,7 +216,7 @@ spec_result_roundtrip <- list(
#' - Loss of precision when converting to numeric gives a warning
data_64_bit_numeric_warning = function(ctx, con) {
as_numeric_equals_to <- function(x) {
lapply(x, function(xx) {
map(x, function(xx) {
function(value) isTRUE(all.equal(as.numeric(value), xx))
})
}
Expand Down Expand Up @@ -246,7 +246,7 @@ spec_result_roundtrip <- list(
#' of the data
data_64_bit_lossless = function(ctx, con) {
as_character_equals_to <- function(x) {
lapply(x, function(xx) {
map(x, function(xx) {
function(value) as.character(value) == xx
})
}
Expand Down Expand Up @@ -280,8 +280,8 @@ test_select <- function(
values <- list2(...)

value_is_formula <- map_lgl(values, is.call)
names(values)[value_is_formula] <- lapply(values[value_is_formula], "[[", 2L)
values[value_is_formula] <- lapply(
names(values)[value_is_formula] <- map(values[value_is_formula], "[[", 2L)
values[value_is_formula] <- map(
values[value_is_formula],
function(x) {
eval(x[[3]], envir = .envir)
Expand Down Expand Up @@ -398,7 +398,7 @@ coercible_to_time <- function(x) {
}

as_timestamp_equals_to <- function(x) {
lapply(x, function(xx) {
map(x, function(xx) {
function(value) as.POSIXct(value) == xx
})
}
Expand Down
8 changes: 4 additions & 4 deletions R/spec-sql-append-table.R
Original file line number Diff line number Diff line change
Expand Up @@ -470,16 +470,16 @@ spec_sql_append_table <- list(
append_roundtrip_mixed = function(con) {
#' Mixing column types in the same table is supported.
data <- list("a", 1L, 1.5)
data <- lapply(data, c, NA)
data <- map(data, c, NA)
expanded <- expand.grid(a = data, b = data, c = data)
tbl_in_list <- lapply(
tbl_in_list <- map(
seq_len(nrow(expanded)),
function(i) {
as.data.frame(lapply(expanded[i, ], unlist, recursive = FALSE))
as.data.frame(map(expanded[i, ], unlist, recursive = FALSE))
}
)

lapply(tbl_in_list, test_table_roundtrip, con = con)
map(tbl_in_list, test_table_roundtrip, con = con)
},

append_table_name = function(ctx, con) {
Expand Down
2 changes: 1 addition & 1 deletion R/spec-sql-list-objects.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec_sql_list_objects <- list(
#' The `table` column is of type list.
expect_equal(typeof(objects$table), "list")
#' Each object in this list is suitable for use as argument in [dbQuoteIdentifier()].
expect_error(lapply(objects$table, dbQuoteIdentifier, conn = con), NA)
expect_error(map(objects$table, dbQuoteIdentifier, conn = con), NA)

#' The `is_prefix` column is a logical.
expect_type(objects$is_prefix, "logical")
Expand Down
4 changes: 2 additions & 2 deletions R/spec-sql-quote-literal.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ spec_sql_quote_literal <- list(
expect_equal(nrow(x_out), 1L)

is_logical <- map_lgl(x, is.logical)
x_out[is_logical] <- lapply(x_out[is_logical], as.logical)
x_out[is_logical] <- map(x_out[is_logical], as.logical)
is_numeric <- map_lgl(x, is.numeric)
x_out[is_numeric] <- lapply(x_out[is_numeric], as.numeric)
x_out[is_numeric] <- map(x_out[is_numeric], as.numeric)
expect_equal(as.list(unname(x_out)), x)
}

Expand Down
8 changes: 4 additions & 4 deletions R/spec-sql-write-table.R
Original file line number Diff line number Diff line change
Expand Up @@ -676,16 +676,16 @@ spec_sql_write_table <- list(
roundtrip_mixed = function(ctx, con) {
#' Mixing column types in the same table is supported.
data <- list("a", 1L, 1.5)
data <- lapply(data, c, NA)
data <- map(data, c, NA)
expanded <- expand.grid(a = data, b = data, c = data)
tbl_in_list <- lapply(
tbl_in_list <- map(
seq_len(nrow(expanded)),
function(i) {
as.data.frame(lapply(expanded[i, ], unlist, recursive = FALSE))
as.data.frame(map(expanded[i, ], unlist, recursive = FALSE))
}
)

lapply(tbl_in_list, test_table_roundtrip, con = con)
map(tbl_in_list, test_table_roundtrip, con = con)
},

#'
Expand Down
2 changes: 1 addition & 1 deletion R/spec-stress-connection.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ spec_stress_connection <- list(
simultaneous_connections = function(ctx) {
#' Open 50 simultaneous connections
cons <- list()
on.exit(try_silent(lapply(cons, dbDisconnect)), add = TRUE)
on.exit(try_silent(map(cons, dbDisconnect)), add = TRUE)
for (i in seq_len(50L)) {
cons <- c(cons, connect(ctx))
}
Expand Down
2 changes: 1 addition & 1 deletion R/tweaks.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
make_tweaks <- function(envir = parent.frame()) {
fmls <- tweak_names[-length(tweak_names)]

tweak_quoted <- lapply(setNames(nm = names(fmls)), as.name)
tweak_quoted <- map(setNames(nm = names(fmls)), as.name)
tweak_quoted <- c(tweak_quoted)
list_call <- as.call(c(quote(list), tweak_quoted[-1]))

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-consistency.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ test_that("no unnamed specs", {
vicinity <- NULL
if (any(names(tests) == "")) {
vicinity <- sort(unique(unlist(
lapply(which(names(tests) == ""), "+", -1:1)
map(which(names(tests) == ""), "+", -1:1)
)))
vicinity <- vicinity[names(tests)[vicinity] != ""]
}
Expand Down

0 comments on commit 9c82ad9

Please sign in to comment.