Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use drop=TRUE in rows check? #400

Open
MichaelChirico opened this issue Mar 17, 2025 · 0 comments
Open

Use drop=TRUE in rows check? #400

MichaelChirico opened this issue Mar 17, 2025 · 0 comments

Comments

@MichaelChirico
Copy link
Contributor

MichaelChirico commented Mar 17, 2025

eval(bquote(expect_identical(rows[1L, .(i)], .(value_or_testfun))))

We have a backend that always returns tbl_df/tbl/data.frame, which uses drop=FALSE by default, however, that runs into issues here (and perhaps other places?) where it's assumed that [ has drop=TRUE when doing rows[1,1], e.g.

── Failure: DBItest: Result: data_logical ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
rows[1L, 2L] (`actual`) not identical to FALSE (`expected`).

`actual` is an S3 object of class <tbl_df/tbl/data.frame>, a list
`expected` is a logical vector (FALSE)
Backtrace:
    ▆
 1. └─DBItest:::spec_result$data_logical(ctx = ctx, con = global_con)
 2.   └─DBItest:::test_select_with_null(...) at rbuild/R/spec-result-roundtrip.R:29:5
 3.     └─DBItest:::test_select(..., .add_null = "below") at rbuild/R/spec-result-roundtrip.R:264:3
 4.       ├─base::eval(bquote(expect_identical(rows[1L, .(i)], .(value_or_testfun)))) at rbuild/R/spec-result-roundtrip.R:333:7
 5.       │ └─base::eval(bquote(expect_identical(rows[1L, .(i)], .(value_or_testfun))))
 6.       └─testthat::expect_identical(rows[1L, 2L], FALSE)

Is it safe to always do drop=TRUE here, or should we just keep skipping this test under "only data.frame returns are supported"?

I lean towards the former, because check_df() has several checks, none of which requires exact [.data.frame syntax:

rows <- check_df(dbGetQuery(con, query))

DBItest/R/utils.R

Lines 78 to 91 in f19fb4d

check_df <- function(df) {
expect_s3_class(df, "data.frame")
if (length(df) >= 1L) {
lengths <- unname(lengths(df))
expect_equal(diff(lengths), rep(0L, length(lengths) - 1L))
expect_equal(nrow(df), lengths[[1]])
}
df_names <- names(df)
expect_true(all(df_names != ""))
expect_false(anyNA(df_names))
df
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant