-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathtest-smk-utils.R
More file actions
69 lines (59 loc) · 2.25 KB
/
test-smk-utils.R
File metadata and controls
69 lines (59 loc) · 2.25 KB
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
66
67
68
69
#-------------------------------------------------------------------------------
# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved.
#
# This program and the accompanying materials
# are made available under the terms of the GNU Public License v3.0.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#-------------------------------------------------------------------------------
#
# Set up
#
## When .loadServersideObject is called, the actual data exists two levels below the function,
## i.e. data in global env --> ds function --> .loadServersideObject. We recreate this in
## the test environment with a wrapper function.
.dsFunctionWrapper <- function(x) {
.loadServersideObject(x)
}
# context("utils::smk::setup")
test_that(".loadServersideObject() returns existing object", {
test_df <- data.frame(a = 1:3)
result <- .dsFunctionWrapper("test_df")
expect_identical(result, test_df)
})
test_that(".loadServersideObject() throws error for missing object", {
expect_error(
.dsFunctionWrapper("test_df"),
regexp = "does not exist"
)
})
test_that(".checkClass() passes for correct class", {
df <- data.frame(a = 1)
expect_invisible(
.checkClass(df, "df", c("data.frame", "matrix"))
)
})
test_that(".checkClass() throws informative error for wrong class with one target class", {
x <- list(a = 1)
expect_error(
.checkClass(x, "x", "data.frame"),
regexp = "The server-side object must be of type data.frame. 'x' is type list."
)
})
test_that(".checkClass() throws informative error for wrong class with three target classes", {
x <- list(a = 1)
expect_error(
.checkClass(x, "x", c("data.frame", "matrix", "unicorn")),
regexp = "The server-side object must be of type data.frame, matrix or unicorn. 'x' is type list."
)
})
test_that(".checkClass() throws informative error for three target classes and three actual classes", {
x <- tibble(a = 1)
expect_error(
.checkClass(x, "x", c("Boolean", "unicorn", "donkey")),
regexp = "The server-side object must be of type Boolean, unicorn or donkey. 'x' is type tbl_df, tbl and data.frame."
)
})
# context("utils::smk::shutdown")
# context("utils::smk::done")