File: spec-meta-has-completed.R

package info (click to toggle)
r-cran-dbitest 1.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,216 kB
  • sloc: sh: 10; makefile: 2
file content (65 lines) | stat: -rw-r--r-- 2,483 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#' spec_meta_has_completed
#' @family meta specifications
#' @usage NULL
#' @format NULL
#' @keywords NULL
spec_meta_has_completed <- list(
  has_completed_formals = function() {
    # <establish formals of described functions>
    expect_equal(names(formals(dbHasCompleted)), c("res", "..."))
  },

  has_completed_query = function(con) {
    #' @return
    #' `dbHasCompleted()` returns a logical scalar.
    #' For a query initiated by [dbSendQuery()] with non-empty result set,
    res <- local_result(dbSendQuery(con, trivial_query()))
    #' `dbHasCompleted()` returns `FALSE` initially
    expect_false(expect_visible(dbHasCompleted(res)))
    #' and `TRUE` after calling [dbFetch()] without limit.
    check_df(dbFetch(res))
    expect_true(expect_visible(dbHasCompleted(res)))
  },
  #
  has_completed_statement = function(con, table_name) {
    #' For a query initiated by [dbSendStatement()],
    res <- local_result(dbSendStatement(con, paste0("CREATE TABLE ", table_name, " (a integer)")))
    #' `dbHasCompleted()` always returns `TRUE`.
    expect_true(expect_visible(dbHasCompleted(res)))
  },
  #'
  has_completed_error = function(con) {
    #' @section Failure modes:
    res <- dbSendQuery(con, trivial_query())
    dbClearResult(res)
    #' Attempting to query completion status for a result set cleared with
    #' [dbClearResult()] gives an error.
    expect_error(dbHasCompleted(res))
  },

  has_completed_query_spec = function(con) {
    #' @section Specification:
    #' The completion status for a query is only guaranteed to be set to
    #' `FALSE` after attempting to fetch past the end of the entire result.
    #' Therefore, for a query with an empty result set,
    res <- local_result(dbSendQuery(con, "SELECT * FROM (SELECT 1 as a) AS x WHERE (1 = 0)"))
    #' the initial return value is unspecified,
    #' but the result value is `TRUE` after trying to fetch only one row.
    check_df(dbFetch(res, 1))
    expect_true(expect_visible(dbHasCompleted(res)))
  },

  has_completed_query_spec_partial = function(con) {
    #' @section Specification:
    #' Similarly, for a query with a result set of length n,
    res <- local_result(dbSendQuery(con, trivial_query()))
    #' the return value is unspecified after fetching n rows,
    check_df(dbFetch(res, 1))
    #' but the result value is `TRUE` after trying to fetch only one more
    #' row.
    check_df(dbFetch(res, 1))
    expect_true(expect_visible(dbHasCompleted(res)))
  },
  #
  NULL
)