Skip to content

Commit e6a4906

Browse files
committed
closed_con and invalid_con
1 parent cf4a862 commit e6a4906

16 files changed

+35
-35
lines changed

R/spec-connection-disconnect.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ spec_connection_disconnect <- list(
2323
#' A warning is issued immediately when calling `dbDisconnect()` on an
2424
#' already disconnected
2525
disconnect_closed_connection = function(ctx) with_closed_connection({
26-
expect_warning(dbDisconnect(con))
26+
expect_warning(dbDisconnect(closed_con))
2727
}), # with_closed_connection
2828

2929
#' or invalid connection.
3030
disconnect_invalid_connection = function(ctx) with_invalid_connection({
31-
expect_warning(dbDisconnect(con))
31+
expect_warning(dbDisconnect(invalid_con))
3232
}), # with_invalid_connection
3333
#
3434
NULL

R/spec-meta-is-valid.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ spec_meta_is_valid <- list(
2424
is_valid_stale_connection = function(ctx) with_invalid_connection({
2525
#' For an invalid connection object (e.g., for some drivers if the object
2626
#' is saved to a file and then restored), the method also returns `FALSE`.
27-
expect_false(expect_visible(dbIsValid(con)))
27+
expect_false(expect_visible(dbIsValid(invalid_con)))
2828
}), # with_invalid_connection
2929
#
3030
is_valid_result_query = function(ctx, con) {

R/spec-result-execute.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ spec_result_execute <- list(
2626

2727
#' An error is raised when issuing a statement over a closed
2828
execute_closed_connection = function(ctx) with_closed_connection({
29-
expect_error(dbExecute(con, trivial_statement()))
29+
expect_error(dbExecute(closed_con, trivial_statement()))
3030
}), # with_closed_connection
3131

3232
#' or invalid connection,
3333
execute_invalid_connection = function(ctx) with_invalid_connection({
34-
expect_error(dbExecute(con, trivial_statement()))
34+
expect_error(dbExecute(invalid_con, trivial_statement()))
3535
}), # with_invalid_connection
3636

3737
#' if the syntax of the statement is invalid,

R/spec-result-get-query.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ spec_result_get_query <- list(
4343

4444
#' An error is raised when issuing a query over a closed
4545
get_query_closed_connection = function(ctx) with_closed_connection({
46-
expect_error(dbGetQuery(con, trivial_query()))
46+
expect_error(dbGetQuery(closed_con, trivial_query()))
4747
}), # with_closed_connection
4848

4949
#' or invalid connection,
5050
get_query_invalid_connection = function(ctx) with_invalid_connection({
51-
expect_error(dbGetQuery(con, trivial_query()))
51+
expect_error(dbGetQuery(invalid_con, trivial_query()))
5252
}), # with_invalid_connection
5353

5454
#' if the syntax of the query is invalid,

R/spec-result-send-query.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ spec_result_send_query <- list(
2323

2424
#' An error is raised when issuing a query over a closed
2525
send_query_closed_connection = function(ctx) with_closed_connection({
26-
expect_error(dbSendQuery(con, trivial_query()))
26+
expect_error(dbSendQuery(closed_con, trivial_query()))
2727
}), # with_closed_connection
2828

2929
#' or invalid connection,
3030
send_query_invalid_connection = function(ctx) with_invalid_connection({
31-
expect_error(dbSendQuery(con, trivial_query()))
31+
expect_error(dbSendQuery(invalid_con, trivial_query()))
3232
}), # with_invalid_connection
3333

3434
#' or if the query is not a non-`NA` string.

R/spec-result-send-statement.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ spec_result_send_statement <- list(
2626

2727
#' An error is raised when issuing a statement over a closed
2828
send_statement_closed_connection = function(ctx) with_closed_connection({
29-
expect_error(dbSendStatement(con, trivial_statement()))
29+
expect_error(dbSendStatement(closed_con, trivial_statement()))
3030
}), # with_closed_connection
3131

3232
#' or invalid connection,
3333
send_statement_invalid_connection = function(ctx) with_invalid_connection({
34-
expect_error(dbSendStatement(con, trivial_statement()))
34+
expect_error(dbSendStatement(invalid_con, trivial_statement()))
3535
}), # with_invalid_connection
3636

3737
#' or if the statement is not a non-`NA` string.

R/spec-sql-append-table.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ spec_sql_append_table <- list(
5050
#'
5151
#' An error is raised when calling this method for a closed
5252
append_table_closed_connection = function(ctx) with_closed_connection({
53-
expect_error(dbAppendTable(con, "test", data.frame(a = 1)))
53+
expect_error(dbAppendTable(closed_con, "test", data.frame(a = 1)))
5454
}), # with_closed_connection
5555

5656
#' or invalid connection.
5757
append_table_invalid_connection = function(ctx) with_invalid_connection({
58-
expect_error(dbAppendTable(con, "test", data.frame(a = 1)))
58+
expect_error(dbAppendTable(invalid_con, "test", data.frame(a = 1)))
5959
}), # with_invalid_connection
6060

6161
#' An error is also raised

R/spec-sql-create-table.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ spec_sql_create_table <- list(
3333
#'
3434
#' An error is raised when calling this method for a closed
3535
create_table_closed_connection = function(ctx) with_closed_connection({
36-
expect_error(dbCreateTable(con, "test", data.frame(a = 1)))
36+
expect_error(dbCreateTable(closed_con, "test", data.frame(a = 1)))
3737
}), # with_closed_connection
3838

3939
#' or invalid connection.
4040
create_table_invalid_connection = function(ctx) with_invalid_connection({
41-
expect_error(dbCreateTable(con, "test", data.frame(a = 1)))
41+
expect_error(dbCreateTable(invalid_con, "test", data.frame(a = 1)))
4242
}), # with_invalid_connection
4343

4444
#' An error is also raised

R/spec-sql-exists-table.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ spec_sql_exists_table <- list(
3434
#'
3535
#' An error is raised when calling this method for a closed
3636
exists_table_closed_connection = function(ctx) with_closed_connection({
37-
expect_error(dbExistsTable(con, "test"))
37+
expect_error(dbExistsTable(closed_con, "test"))
3838
}), # with_closed_connection
3939

4040
#' or invalid connection.
4141
exists_table_invalid_connection = function(ctx) with_invalid_connection({
42-
expect_error(dbExistsTable(con, "test"))
42+
expect_error(dbExistsTable(invalid_con, "test"))
4343
}), # with_invalid_connection
4444

4545
#' An error is also raised

R/spec-sql-list-fields.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ spec_sql_list_fields <- list(
5656

5757
#' An error is also raised when calling this method for a closed
5858
list_fields_closed_connection = function(ctx) with_closed_connection({
59-
expect_error(dbListFields(con, "test"))
59+
expect_error(dbListFields(closed_con, "test"))
6060
}), # with_closed_connection
6161

6262
#' or invalid connection.
6363
list_fields_invalid_connection = function(ctx) with_invalid_connection({
64-
expect_error(dbListFields(con, "test"))
64+
expect_error(dbListFields(invalid_con, "test"))
6565
}), # with_invalid_connection
6666

6767
#' @section Specification:

R/spec-sql-list-objects.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ spec_sql_list_objects <- list(
8484

8585
#' An error is raised when calling this method for a closed
8686
list_objects_closed_connection = function(ctx) with_closed_connection({
87-
expect_error(dbListObjects(con))
87+
expect_error(dbListObjects(closed_con))
8888
}), # with_closed_connection
8989

9090
#' or invalid connection.
9191
list_objects_invalid_connection = function(ctx) with_invalid_connection({
92-
expect_error(dbListObjects(con))
92+
expect_error(dbListObjects(invalid_con))
9393
}), # with_invalid_connection
9494

9595
#' @section Specification:

R/spec-sql-list-tables.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ spec_sql_list_tables <- list(
6565

6666
#' An error is raised when calling this method for a closed
6767
list_tables_closed_connection = function(ctx) with_closed_connection({
68-
expect_error(dbListTables(con))
68+
expect_error(dbListTables(closed_con))
6969
}), # with_closed_connection
7070

7171
#' or invalid connection.
7272
list_tables_invalid_connection = function(ctx) with_invalid_connection({
73-
expect_error(dbListTables(con))
73+
expect_error(dbListTables(invalid_con))
7474
}), # with_invalid_connection
7575
#
7676
NULL

R/spec-sql-write-table.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ spec_sql_write_table <- list(
4646
#'
4747
#' An error is raised when calling this method for a closed
4848
write_table_closed_connection = function(ctx) with_closed_connection({
49-
expect_error(dbWriteTable(con, "test", data.frame(a = 1)))
49+
expect_error(dbWriteTable(closed_con, "test", data.frame(a = 1)))
5050
}), # with_closed_connection
5151

5252
#' or invalid connection.
5353
write_table_invalid_connection = function(ctx) with_invalid_connection({
54-
expect_error(dbWriteTable(con, "test", data.frame(a = 1)))
54+
expect_error(dbWriteTable(invalid_con, "test", data.frame(a = 1)))
5555
}), # with_invalid_connection
5656

5757
#' An error is also raised

R/spec-transaction-begin-commit-rollback.R

+6-6
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ spec_transaction_begin_commit_rollback <- list(
3636
#' but this is not tested.
3737
begin_commit_closed = function(ctx) with_closed_connection({
3838
#' In any way, all generics throw an error with a closed
39-
expect_error(dbBegin(con))
40-
expect_error(dbCommit(con))
41-
expect_error(dbRollback(con))
39+
expect_error(dbBegin(closed_con))
40+
expect_error(dbCommit(closed_con))
41+
expect_error(dbRollback(closed_con))
4242
}), # with_closed_connection
4343
#
4444
begin_commit_invalid = function(ctx) with_invalid_connection({
4545
#' or invalid connection.
46-
expect_error(dbBegin(con))
47-
expect_error(dbCommit(con))
48-
expect_error(dbRollback(con))
46+
expect_error(dbBegin(invalid_con))
47+
expect_error(dbCommit(invalid_con))
48+
expect_error(dbRollback(invalid_con))
4949
}), # with_invalid_connection
5050
#
5151
commit_without_begin = function(ctx, con) {

R/spec-transaction-with-transaction.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ spec_transaction_with_transaction <- list(
1818
#' Failure to initiate the transaction
1919
#' (e.g., if the connection is closed
2020
with_transaction_error_closed = function(ctx) with_closed_connection({
21-
expect_error(dbWithTransaction(con, NULL))
21+
expect_error(dbWithTransaction(closed_con, NULL))
2222
}), # with_closed_connection
2323

2424
#' or invalid
2525
with_transaction_error_invalid = function(ctx) with_invalid_connection({
26-
expect_error(dbWithTransaction(con, NULL))
26+
expect_error(dbWithTransaction(invalid_con, NULL))
2727
}), # with_invalid_connection
2828

2929
#' of if [dbBegin()] has been called already)

R/utils.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ with_connection <- function(code, con = "con", env = parent.frame()) {
3535
# evaluates the code inside local() after defining a variable "con"
3636
# (can be overridden by specifying con argument)
3737
# that points to a newly opened and then closed connection. Disconnects on exit.
38-
with_closed_connection <- function(code, con = "con", env = parent.frame()) {
38+
with_closed_connection <- function(code, con = "closed_con", env = parent.frame()) {
3939
code_sub <- substitute(code)
4040

4141
con <- as.name(con)
@@ -54,7 +54,7 @@ with_closed_connection <- function(code, con = "con", env = parent.frame()) {
5454
# evaluates the code inside local() after defining a variable "con"
5555
# (can be overridden by specifying con argument)
5656
# that points to a newly opened but invalidated connection. Disconnects on exit.
57-
with_invalid_connection <- function(code, con = "con", env = parent.frame()) {
57+
with_invalid_connection <- function(code, con = "invalid_con", env = parent.frame()) {
5858
code_sub <- substitute(code)
5959

6060
stopifnot(con != "..con")

0 commit comments

Comments
 (0)