forked from TileDB-Inc/TileDB-R
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_config.R
More file actions
88 lines (67 loc) · 2.54 KB
/
Copy pathtest_config.R
File metadata and controls
88 lines (67 loc) · 2.54 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
library(tinytest)
library(tiledb)
ctx <- tiledb_ctx(limitTileDBCores())
#test_that("tiledb_config default constructor", {
cfg <- tiledb_config()
expect_true(is(cfg, "tiledb_config"))
#test_that("tiledb_config named vector constructor", {
cfg <- tiledb_config(config = c(foo = "bar"))
expect_true(is(cfg, "tiledb_config"))
#})
#test_that("tiledb_config errors upon invalid vector argument", {
expect_error(tiledb_config("foo"))
## all values must have a non-empty name
expect_error(tiledb_config(foo = "foo", "bar"))
expect_error(tiledb_config(1))
expect_error(tiledb_config(c(foo = 1)))
#})
## handle cases with NAs
expect_silent(cfg <- tiledb_config(c(a = "1")))
expect_equal(cfg["a"], c(a = "1"))
expect_silent(cfg <- tiledb_config(c(a = "1", b = "2")))
expect_equal(cfg["b"], c(b = "2"))
expect_equal(head(names(as.vector(cfg)), 2L), c("a", "b"))
expect_silent(cfg <- tiledb_config(c(a = "1", c = NA_character_, b = "2")))
expect_equal(head(names(as.vector(cfg)), 2L), c("a", "b"))
#test_that("tiledb_config indexing works", {
cfg <- tiledb_config()
cfg["foo"] <- "bar"
expect_equal(cfg["foo"], c("foo" = "bar"))
# can stringify basic types
cfg["int"] <- 1L
expect_equal(cfg["int"], c(int = "1"))
cfg["bool"] <- FALSE
expect_equal(cfg["bool"], c(bool = "false"))
cfg["float"] <- 2.3
expect_equal(cfg["float"], c(float = "2.3"))
res <- cfg[c("int", "bool", "float")]
expect_equal(res, c(int = "1", bool = "false", float = 2.3))
# can only stringify basic types int / float / bools
expect_error(cfg["error"] <- c(1, 2, 3))
#})
#test_that("tiledb_config can convert to R named vector", {
cfg <- tiledb_config()
v <- as.vector(cfg)
expect_true(is(v, "character"))
keys <- names(v)
values <- unname(v)
#})
#test_that("tiledb_config set, get and unset", {
cfg <- tiledb_config()
param <- "vfs.s3.region"
origval <- cfg[param][[1]]
newval <- "not.kansas"
tiledb:::libtiledb_config_set(cfg@ptr, param, newval)
expect_equal(tiledb:::libtiledb_config_get(cfg@ptr, param)[[1]], newval)
tiledb:::libtiledb_config_unset(cfg@ptr, param) # resets, not unsets
expect_equal(tiledb:::libtiledb_config_get(cfg@ptr, param)[[1]], origval)
# test 'tiledb_config_unset()'
origval <- cfg["sm.group.timestamp_end"]
# new value
cfg["sm.group.timestamp_end"] <- 1000
cfg <- tiledb_config_unset(cfg, "sm.group.timestamp_end")
expect_equal(is(cfg), "tiledb_config")
expect_equal(cfg["sm.group.timestamp_end"], origval)
#})
if (tiledb_version(TRUE) < "2.17.0") exit_file("Remainder needs 2.17.* or later")
expect_true(nzchar(tiledb_config_as_built_json())) # only test for non-zero instead of parsing