Skip to content

Commit ee7d1f4

Browse files
Remove expect_is and expect_that from tests
1 parent a06c2dd commit ee7d1f4

11 files changed

+34
-29
lines changed

R/expectations.R

+20-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
arglist_is_empty <- function() {
2-
function(x) {
3-
expect_true(
4-
is.null(formals(x)),
5-
"has empty argument list"
6-
)
7-
}
1+
expect_arglist_is_empty <- function(object) {
2+
act <- quasi_label(rlang::enquo(object), arg = "object")
3+
act$formals <- formals(act$val)
4+
expect(
5+
is.null(act$formals),
6+
sprintf("%s has an empty argument list.", act$lab)
7+
)
8+
9+
invisible(act$val)
810
}
911

10-
all_args_have_default_values <- function() {
11-
function(x) {
12-
args <- formals(x)
13-
args <- args[names(args) != "..."]
14-
expect_true(
15-
all(vapply(args, function(x) if (is.null(x)) "NULL" else as.character(x), character(1L)) != ""),
16-
"has arguments without default values"
17-
)
18-
}
12+
expect_all_args_have_default_values <- function(object) {
13+
act <- quasi_label(rlang::enquo(object), arg = "object")
14+
act$args <- formals(act$val)
15+
act$args <- act$args[names(act$args) != "..."]
16+
act$char_args <- vapply(act$args, as.character, character(1L))
17+
expect(
18+
all(nzchar(act$char_args, keepNA = FALSE)),
19+
sprintf("%s has arguments without default values", act$lab)
20+
)
21+
22+
invisible(act$val)
1923
}
2024

2125
has_method <- function(method_name) {

R/s4.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ s4_methods <- function(env, pkg_fun = NULL) {
2424
}
2525

2626
s4_real_argument_names <- function(s4_method) {
27-
expect_is(s4_method, c("function", "MethodDefinition", "derivedDefaultMethod"))
27+
expect_s4_class(s4_method, "function")
28+
expect_s4_class(s4_method, "MethodDefinition")
2829
unwrapped <- s4_unwrap(s4_method)
2930
names(formals(unwrapped))
3031
}

R/spec-driver-constructor.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ spec_driver_constructor <- list(
3030
constructor <- get(constructor_name, mode = "function", pkg_env)
3131

3232
#' that is callable without arguments.
33-
expect_that(constructor, all_args_have_default_values())
33+
expect_all_args_have_default_values(constructor)
3434
#' DBI recommends to define a constructor with an empty argument list.
3535
if (!isTRUE(ctx$tweaks$constructor_relax_args)) {
36-
expect_that(constructor, arglist_is_empty())
36+
expect_arglist_is_empty(constructor)
3737
}
3838
},
3939
#

R/spec-driver-data-type.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ test_data_type <- function(ctx, dbObj) {
3434
#' is returned.
3535
expect_equal(length(dbDataType(dbObj, value)), .(ncol(value)))
3636
}
37-
expect_is(dbDataType(dbObj, .(value)), "character")
37+
expect_type(dbDataType(dbObj, .(value)), "character")
3838
expect_visible(dbDataType(dbObj, .(value)))
3939
}))
4040
}

R/spec-meta-column-info.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ spec_meta_column_info <- list(
1919
{
2020
fields <- dbColumnInfo(res)
2121
#' returns a data frame
22-
expect_is(fields, "data.frame")
22+
expect_s3_class(fields, "data.frame")
2323
#' with at least two columns `"name"` and `"type"` (in that order)
2424
expect_equal(names(fields)[1:2], c("name", "type"))
2525
#' (and optional columns that start with a dot).
@@ -30,7 +30,7 @@ spec_meta_column_info <- list(
3030
iris_ret <- dbFetch(res)
3131
expect_identical(fields$name, names(iris_ret))
3232
#' The `"type"` column is of type `character` and only for information.
33-
expect_is(fields$type, "character")
33+
expect_type(fields$type, "character")
3434
#' Do not compute on the `"type"` column, instead use `dbFetch(res, n = 0)`
3535
#' to create a zero-row data frame initialized with the correct data types.
3636
}

R/spec-meta-get-statement.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ spec_meta_get_statement <- list(
1717
dbSendQuery(con, query),
1818
{
1919
s <- dbGetStatement(res)
20-
expect_is(s, "character")
20+
expect_type(s, "character")
2121
expect_identical(s, query)
2222
}
2323
)
@@ -30,7 +30,7 @@ spec_meta_get_statement <- list(
3030
dbSendStatement(con, query),
3131
{
3232
s <- dbGetStatement(res)
33-
expect_is(s, "character")
33+
expect_type(s, "character")
3434
expect_identical(s, query)
3535
}
3636
)

R/spec-sql-list-tables.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ spec_sql_list_tables <- list(
1313
list_tables = function(ctx, con, table_name = "dbit07") {
1414
tables <- dbListTables(con)
1515
#' returns a character vector
16-
expect_is(tables, "character")
16+
expect_type(tables, "character")
1717
#' that enumerates all tables
1818
expect_false(table_name %in% tables)
1919

R/spec-sql-quote-identifier.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ spec_sql_quote_identifier <- list(
1313
#' `dbQuoteIdentifier()` returns an object that can be coerced to [character],
1414
simple_out <- dbQuoteIdentifier(con, "simple")
1515
expect_error(as.character(simple_out), NA)
16-
expect_is(as.character(simple_out), "character")
16+
expect_type(as.character(simple_out), "character")
1717
},
1818
#
1919
quote_identifier_vectorized = function(ctx, con) {

R/spec-sql-quote-string.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spec_sql_quote_string <- list(
1414
simple <- "simple"
1515
simple_out <- dbQuoteString(con, simple)
1616
expect_error(as.character(simple_out), NA)
17-
expect_is(as.character(simple_out), "character")
17+
expect_type(as.character(simple_out), "character")
1818
expect_equal(length(simple_out), 1L)
1919
},
2020
#

R/spec-sql-write-table.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ spec_sql_write_table <- list(
441441
test_table_roundtrip(
442442
con, tbl_in,
443443
transform = function(tbl_out) {
444-
expect_is(unclass(tbl_out$a), "numeric")
444+
expect_type(unclass(tbl_out$a), "double")
445445
tbl_out
446446
}
447447
)

R/utils.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
get_pkg_path <- function(ctx) {
44
pkg_name <- package_name(ctx)
5-
expect_is(pkg_name, "character")
5+
expect_type(pkg_name, "character")
66

77
pkg_path <- find.package(pkg_name)
88
pkg_path

0 commit comments

Comments
 (0)