Skip to content

Commit 61741aa

Browse files
authored
GH-48145: [R] Update to testthat 3.3.0 and use its expect_r6_class() (#49333)
### Rationale for this change testthat 3.3.0 added several new expectation functions that we can use instead of our custom implementations or verbose patterns. ### What changes are included in this PR? - Bump testthat requirement from >= 3.1.0 to >= 3.3.0 - Remove custom `expect_r6_class()` from helper-expectation.R in favor of testthat's version - Replace `expect_true(all(...))` with `expect_all_true()` - Replace `expect_false(any(...))` / `expect_true(all(!...))` with `expect_all_false()` - Replace `expect_identical(dim(...), c(...))` with `expect_shape(..., dim = c(...))` ### Are these changes tested? Existing tests pass with the new expectations. ### Are there any user-facing changes? No. --- This PR was generated by Claude. All outputs were reviewed and confirmed before pushing. * GitHub Issue: #48145 Authored-by: Nic Crane <thisisnic@gmail.com> Signed-off-by: Nic Crane <thisisnic@gmail.com>
1 parent 84a5701 commit 61741aa

12 files changed

Lines changed: 16 additions & 24 deletions

r/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Suggests:
6868
stringi,
6969
stringr,
7070
sys,
71-
testthat (>= 3.1.0),
71+
testthat (>= 3.3.0),
7272
tibble,
7373
tzdb,
7474
withr

r/tests/testthat/helper-expectation.R

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ expect_equal_data_frame <- function(x, y, ...) {
2424
expect_equal(as.data.frame(x), as.data.frame(y), ...)
2525
}
2626

27-
expect_r6_class <- function(object, class) {
28-
expect_s3_class(object, class)
29-
expect_s3_class(object, "R6")
30-
}
31-
3227
#' Mask `testthat::expect_equal()` in order to compare ArrowObjects using their
3328
#' `Equals` methods from the C++ library.
3429
expect_equal <- function(object, expected, ignore_attr = FALSE, ..., info = NULL, label = NULL) {

r/tests/testthat/test-Array.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ test_that("Timezone handling in Arrow roundtrip (ARROW-3543)", {
332332
)
333333
if (!identical(Sys.timezone(), "Pacific/Marquesas")) {
334334
# Confirming that the columns are in fact different
335-
expect_false(any(df$no_tz == df$yes_tz))
335+
expect_all_false(df$no_tz == df$yes_tz)
336336
}
337337
feather_file <- tempfile()
338338
on.exit(unlink(feather_file))

r/tests/testthat/test-RecordBatch.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ test_that("[[<- assignment", {
204204
# can use $
205205
batch$new <- NULL
206206
expect_null(as.vector(batch$new))
207-
expect_identical(dim(batch), c(10L, 4L))
207+
expect_shape(batch, dim = c(10L, 4L))
208208

209209
batch$int <- 1:10
210210
expect_as_vector(batch$int, 1:10)
@@ -328,8 +328,7 @@ test_that("record_batch(schema=) does some basic consistency checking of the sch
328328

329329
test_that("RecordBatch dim() and nrow() (ARROW-3816)", {
330330
batch <- record_batch(x = 1:10, y = 1:10)
331-
expect_equal(dim(batch), c(10L, 2L))
332-
expect_equal(nrow(batch), 10L)
331+
expect_shape(batch, dim = c(10L, 2L))
333332
})
334333

335334
test_that("record_batch() handles Array", {

r/tests/testthat/test-Table.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ test_that("[[<- assignment", {
144144
# can use $
145145
tab$new <- NULL
146146
expect_null(as.vector(tab$new))
147-
expect_identical(dim(tab), c(10L, 4L))
147+
expect_shape(tab, dim = c(10L, 4L))
148148

149149
tab$int <- 1:10
150150
expect_as_vector(tab$int, 1:10)

r/tests/testthat/test-chunked-array.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,7 @@ test_that("ChunkedArray$View() (ARROW-6542)", {
391391
b <- a$View(float32())
392392
expect_equal(b$type, float32())
393393
expect_equal(length(b), 7L)
394-
expect_true(all(
395-
sapply(b$chunks, function(.x) .x$type == float32())
396-
))
394+
expect_all_true(sapply(b$chunks, function(.x) .x$type == float32()))
397395
# Input validation
398396
expect_error(a$View("not a type"), "type must be a DataType, not character")
399397
})

r/tests/testthat/test-compute-aggregate.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test_that("list_compute_functions", {
2020
expect_false(all(grepl("min", allfuncs)))
2121
justmins <- list_compute_functions("^min")
2222
expect_true(length(justmins) > 0)
23-
expect_true(all(grepl("min", justmins)))
23+
expect_all_true(grepl("min", justmins))
2424
no_hash_funcs <- list_compute_functions("^hash")
2525
expect_true(length(no_hash_funcs) == 0)
2626
})

r/tests/testthat/test-compute-no-bindings.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ test_that("non-bound compute kernels using PartitionNthOptions", {
127127
)
128128
# Order of indices on either side of the pivot is not deterministic
129129
# (depends on C++ standard library implementation)
130-
expect_true(all(as.vector(result[1:3]) < 3))
131-
expect_true(all(as.vector(result[4:10]) >= 3))
130+
expect_all_true(as.vector(result[1:3]) < 3)
131+
expect_all_true(as.vector(result[4:10]) >= 3)
132132
})
133133

134134

r/tests/testthat/test-dataset.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ test_that("IPC/Feather format data", {
5151
expect_r6_class(ds$format, "IpcFileFormat")
5252
expect_r6_class(ds$filesystem, "LocalFileSystem")
5353
expect_named(ds, c(names(df1), "part"))
54-
expect_identical(dim(ds), c(20L, 7L))
54+
expect_shape(ds, dim = c(20L, 7L))
5555

5656
expect_equal(
5757
ds |>
@@ -370,12 +370,12 @@ test_that("Can set schema on dataset", {
370370

371371
test_that("as.data.frame.Dataset", {
372372
ds <- open_dataset(dataset_dir, partitioning = schema(part = uint8()))
373-
expect_identical(dim(as.data.frame(ds)), c(20L, 7L))
373+
expect_shape(as.data.frame(ds), dim = c(20L, 7L))
374374
})
375375

376376
test_that("dim method returns the correct number of rows and columns", {
377377
ds <- open_dataset(dataset_dir, partitioning = schema(part = uint8()))
378-
expect_identical(dim(ds), c(20L, 7L))
378+
expect_shape(ds, dim = c(20L, 7L))
379379
})
380380

381381
test_that("dimnames, colnames on Dataset objects", {

r/tests/testthat/test-duckdb.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,10 @@ test_that("Joining, auto-cleanup enabled", {
223223
expect_identical(dim(res), c(9L, 14L))
224224

225225
# clean up cleans up the tables
226-
expect_true(all(c(table_one_name, table_two_name) %in% duckdb::duckdb_list_arrow(con)))
226+
expect_all_true(c(table_one_name, table_two_name) %in% duckdb::duckdb_list_arrow(con))
227227
rm(table_one, table_two)
228228
gc()
229-
expect_false(any(c(table_one_name, table_two_name) %in% duckdb::duckdb_list_arrow(con)))
229+
expect_all_false(c(table_one_name, table_two_name) %in% duckdb::duckdb_list_arrow(con))
230230
})
231231

232232
test_that("Joining, auto-cleanup disabled", {

0 commit comments

Comments
 (0)