Skip to content

Commit

Permalink
Second batch of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eddelbuettel committed Jan 5, 2024
1 parent f074238 commit aa1b124
Show file tree
Hide file tree
Showing 21 changed files with 167 additions and 126 deletions.
15 changes: 9 additions & 6 deletions inst/tinytest/test_dim.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
library(tinytest)
library(tiledb)

isOldWindows <- Sys.info()[["sysname"]] == "Windows" && grepl('Windows Server 2008', osVersion)
if (isOldWindows) exit_file("skip this file on old Windows releases")

ctx <- tiledb_ctx(limitTileDBCores())

isRESTCI <- Sys.getenv("TILEDB_CLOUD_REST_BIN", "") != ""
if (isRESTCI) {
## we can rely on the normal tempfile semantics but override the tmpdir
## argument to be our REST CI base url in the unit test namespace
tempfile <- function() { base::tempfile(tmpdir="tiledb://unit") }
}

#test_that("tiledb_dim default constructor", {
dim <- tiledb_dim("foo", c(1, 100))
expect_true(is(dim, "tiledb_dim"))
Expand Down Expand Up @@ -92,7 +96,6 @@ suppressMessages({
})
atttype <- "INT32"
intmax <- .Machine$integer.max # shorthand
uri <- tempfile()
dimtypes <- c("ASCII", # Variable length string
"INT8", # 8-bit integer
"UINT8", # 8-bit unsigned integer
Expand All @@ -119,7 +122,7 @@ dimtypes <- c("ASCII", # Variable length string
"DATETIME_AS" # attosecond
)
for (dtype in dimtypes) {
if (dir.exists(uri)) unlink(uri, recursive=TRUE)
uri <- tempfile()
dom <- switch(dtype,
"ASCII" = NULL,
"INT8" =,
Expand Down Expand Up @@ -287,7 +290,7 @@ dimtypes <- c("ASCII", # Variable length string
"DATETIME_AS" # attosecond
)
for (dtype in dimtypes) {
if (dir.exists(uri)) unlink(uri, recursive=TRUE)
uri <- tempfile()
dom <- switch(dtype,
"ASCII" = NULL,
"INT8" =,
Expand Down
12 changes: 8 additions & 4 deletions inst/tinytest/test_dimsubset.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ library(tinytest)
library(tiledb)
library(RcppSpdlog) # use logging for some informal profiling

isOldWindows <- Sys.info()[["sysname"]] == "Windows" && grepl('Windows Server 2008', osVersion)
if (isOldWindows) exit_file("skip this file on old Windows releases")

if (!requireNamespace("nycflights13", quietly=TRUE)) exit_file("Needed 'nycflights13' package missing")

isRESTCI <- Sys.getenv("TILEDB_CLOUD_REST_BIN", "") != ""
if (isRESTCI) {
## we can rely on the normal tempfile semantics but override the tmpdir
## argument to be our REST CI base url in the unit test namespace
tempfile <- function() { base::tempfile(tmpdir="tiledb://unit") }
}

log_setup("test_dimsubset", "warn") # but set the default level to 'warn' -> silent, activate via 'info'
ctx <- tiledb_ctx(limitTileDBCores())
log_info("ctx created")

op <- options()
options(stringsAsFactors=FALSE) # accomodate R 3.*
dir.create(tmp <- tempfile())
tmp <- tempfile()

library(nycflights13)

Expand Down
10 changes: 7 additions & 3 deletions inst/tinytest/test_domain.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
library(tinytest)
library(tiledb)

isOldWindows <- Sys.info()[["sysname"]] == "Windows" && grepl('Windows Server 2008', osVersion)
if (isOldWindows) exit_file("skip this file on old Windows releases")

ctx <- tiledb_ctx(limitTileDBCores())

isRESTCI <- Sys.getenv("TILEDB_CLOUD_REST_BIN", "") != ""
if (isRESTCI) {
## we can rely on the normal tempfile semantics but override the tmpdir
## argument to be our REST CI base url in the unit test namespace
tempfile <- function() { base::tempfile(tmpdir="tiledb://unit") }
}

#test_that("tiledb_domain basic constructor", {
d1 <- tiledb_dim("d1", c(1L, 100L))
dom <- tiledb_domain(list(d1))
Expand Down
6 changes: 3 additions & 3 deletions inst/tinytest/test_filestore.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
library(tinytest)
library(tiledb)

isOldWindows <- Sys.info()[["sysname"]] == "Windows" && grepl('Windows Server 2008', osVersion)
if (isOldWindows) exit_file("skip this file on old Windows releases")

isWindows <- Sys.info()[["sysname"]] == "Windows"

ctx <- tiledb_ctx(limitTileDBCores())

isRESTCI <- Sys.getenv("TILEDB_CLOUD_REST_BIN", "") != ""
if (isRESTCI) exit_file("Skipping during REST CI")

if (tiledb_version(TRUE) < "2.9.0") exit_file("Needs TileDB 2.9.* or later")

text_file <- tempfile()
Expand Down
6 changes: 3 additions & 3 deletions inst/tinytest/test_filter.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
library(tinytest)
library(tiledb)

isOldWindows <- Sys.info()[["sysname"]] == "Windows" && grepl('Windows Server 2008', osVersion)
if (isOldWindows) exit_file("skip this file on old Windows releases")

ctx <- tiledb_ctx(limitTileDBCores())

isRESTCI <- Sys.getenv("TILEDB_CLOUD_REST_BIN", "") != ""
if (isRESTCI) exit_file("Skipping during REST CI")

#test_that("tiledb_filter default constructor", {
flt <- tiledb_filter()
expect_true(is(flt, "tiledb_filter"))
Expand Down
3 changes: 0 additions & 3 deletions inst/tinytest/test_filterlist.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
library(tinytest)
library(tiledb)

isOldWindows <- Sys.info()[["sysname"]] == "Windows" && grepl('Windows Server 2008', osVersion)
if (isOldWindows) exit_file("skip this file on old Windows releases")

ctx <- tiledb_ctx(limitTileDBCores())

#test_that("tiledb_filter_list default constructor", {
Expand Down
12 changes: 9 additions & 3 deletions inst/tinytest/test_fragmentinfo.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
library(tinytest)
library(tiledb)

isOldWindows <- Sys.info()[["sysname"]] == "Windows" && grepl('Windows Server 2008', osVersion)
if (isOldWindows) exit_file("skip this file on old Windows releases")
isMacOS <- (Sys.info()['sysname'] == "Darwin")

ctx <- tiledb_ctx(limitTileDBCores())

isRESTCI <- Sys.getenv("TILEDB_CLOUD_REST_BIN", "") != ""
if (isRESTCI) {
## we can rely on the normal tempfile semantics but override the tmpdir
## argument to be our REST CI base url in the unit test namespace
tempfile <- function() { base::tempfile(tmpdir="tiledb://unit") }
}

uri <- tempfile()
if (dir.exists(uri)) unlink(uri, TRUE)

## create simple array
set.seed(123)
Expand Down Expand Up @@ -61,6 +65,8 @@ D2 <- data.frame(keys = 11:20,
arr <- tiledb_array(uri, "WRITE")
arr[] <- D2

if (isRESTCI) exit_file("Skip consolidation during REST CI")

array_consolidate(uri) # written twice so consolidate

rm(fraginf)
Expand Down
15 changes: 11 additions & 4 deletions inst/tinytest/test_group.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
library(tinytest)
library(tiledb)

isOldWindows <- Sys.info()[["sysname"]] == "Windows" && grepl('Windows Server 2008', osVersion)
if (isOldWindows) exit_file("skip this file on old Windows releases")
isWindows <- Sys.info()[["sysname"]] == "Windows"
isMacOS <- (Sys.info()['sysname'] == "Darwin")

ctx <- tiledb_ctx(limitTileDBCores())

isRESTCI <- Sys.getenv("TILEDB_CLOUD_REST_BIN", "") != ""
if (isRESTCI) {
## we can rely on the normal tempfile semantics but override the tmpdir
## argument to be our REST CI base url in the unit test namespace
tempfile <- function() { base::tempfile(tmpdir="tiledb://unit") }
}

if (tiledb_version(TRUE) < "2.8.0") exit_file("TileDB Group requires TileDB 2.8.* or later")

uri <- tempfile()

chk <- tiledb_group_create(uri)
expect_equal(chk, uri) # returns uri
expect_true(dir.exists(chk))
if (!isRESTCI) expect_true(dir.exists(chk))

## instantiate and check properties
grp <- tiledb_group(uri)
Expand Down Expand Up @@ -86,11 +91,13 @@ grp <- tiledb_group_close(grp)
#expect_equal(tiledb_group_metadata_num(grp2), 2)
#expect_false(tiledb_group_has_metadata(grp2, "otherkey"))

if (isRESTCI) exit_file("skip remainder") # TODO should this work? Getting 'unrecognised array'
## create some temp arrays to adds as groups
uri1 <- file.path(uri, "anny")
uri2 <- file.path(uri, "bob")
uri3 <- file.path(uri, "chloe")
uri4 <- file.path(uri, "dave")

df1 <- data.frame(val=seq(100, 200, by=10))
df2 <- data.frame(letters=letters)
df3 <- data.frame(nine=rep(9L, 9))
Expand All @@ -100,7 +107,7 @@ tiledb::fromDataFrame(df2, uri2)
tiledb::fromDataFrame(df3, uri3)
tiledb::fromDataFrame(df4, uri4)

## add member
## add member (unless REST CI)
grp <- tiledb_group_open(grp, "WRITE")
grp <- tiledb_group_add_member(grp, uri1, FALSE) # use absolute URL
grp <- tiledb_group_close(grp)
Expand Down
53 changes: 26 additions & 27 deletions inst/tinytest/test_libtiledb.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
library(tinytest)
library(tiledb)

isOldWindows <- Sys.info()[["sysname"]] == "Windows" && grepl('Windows Server 2008', osVersion)
if (isOldWindows) exit_file("skip this file on old Windows releases")

tiledb_ctx(limitTileDBCores())

isRESTCI <- Sys.getenv("TILEDB_CLOUD_REST_BIN", "") != ""
if (isRESTCI) {
## we can rely on the normal tempfile semantics but override the tmpdir
## argument to be our REST CI base url in the unit test namespace
tempfile <- function() { base::tempfile(tmpdir="tiledb://unit") }
}

#test_that("version is valid", {
ver <- tiledb_version()
expect_equal(length(ver), 3)
Expand Down Expand Up @@ -33,13 +37,11 @@ expect_equal(unname(tiledb:::libtiledb_config_get(config, "don't exist")), NA_ch
#})

#test_that("construct libtiledb_config with an empty vector of paramters", {
params = c()
params <- c()
default_config <- tiledb:::libtiledb_config()
params_config <- tiledb:::libtiledb_config(params)
expect_equal(
tiledb:::libtiledb_config_get(default_config, "sm.tile_cache_size"),
tiledb:::libtiledb_config_get(params_config, "sm.tile_cache_size")
)
expect_equal(tiledb:::libtiledb_config_get(default_config, "sm.tile_cache_size"),
tiledb:::libtiledb_config_get(params_config, "sm.tile_cache_size"))
#})

#test_that("tiledb_config can be converted to an R vector", {
Expand Down Expand Up @@ -92,7 +94,7 @@ dim <- tiledb:::libtiledb_dim(ctx, "d1", "FLOAT64", c(1.0, 100.0), 10.0)
expect_true(is(dim, "externalptr"))
#})


# n=161
#test_that("basic libtiledb_domain constructor works", {
##ctx <- tiledb:::libtiledb_ctx()
ctx <- tiledb_get_context()@ptr
Expand Down Expand Up @@ -120,6 +122,7 @@ attr <- tiledb:::libtiledb_attribute(ctx, "a1", "INT32", filter_list, 1, FALSE)
expect_true(is(attr, "externalptr"))
#})

## n=164
#test_that("basic float64 libtiledb_attr constructor works", {
##ctx <- tiledb:::libtiledb_ctx()
ctx <- tiledb_get_context()@ptr
Expand All @@ -143,7 +146,7 @@ expect_true(is(sch, "externalptr"))
#})

#test_that("basic dense vector libtiledb_array creation works", {
dir.create(tmp <- tempfile())
tmp <- tempfile()
##ctx <- tiledb:::libtiledb_ctx()
ctx <- tiledb_get_context()@ptr
dim <- tiledb:::libtiledb_dim(ctx, "d1", "INT32", c(1L, 3L), 3L)
Expand All @@ -152,14 +155,13 @@ filter <- tiledb:::libtiledb_filter(ctx, "NONE")
filter_list <- tiledb:::libtiledb_filter_list(ctx, c(filter))
att <- tiledb:::libtiledb_attribute(ctx, "a1", "FLOAT64", filter_list, 1, FALSE)
sch <- tiledb:::libtiledb_array_schema(ctx, dom, c(att), cell_order = "COL_MAJOR", tile_order = "COL_MAJOR", sparse = FALSE)
pth <- paste(tmp, "test_array", sep = "/")
uri <- tiledb:::libtiledb_array_create(pth, sch)
expect_true(dir.exists(pth))
uri <- tiledb:::libtiledb_array_create(tmp, sch)
if (!isRESTCI) expect_true(dir.exists(tmp))
unlink(tmp, recursive = TRUE)
#})

#test_that("basic dense vector writes / reads works", {
dir.create(tmp <- tempfile())
tmp <- tempfile()
##ctx <- tiledb:::libtiledb_ctx()
ctx <- tiledb_get_context()@ptr
dim <- tiledb:::libtiledb_dim(ctx, "d1", "INT32", c(1L, 3L), 3L)
Expand All @@ -168,8 +170,7 @@ filter <- tiledb:::libtiledb_filter(ctx, "NONE")
filter_list <- tiledb:::libtiledb_filter_list(ctx, c(filter))
att <- tiledb:::libtiledb_attribute(ctx, "a1", "FLOAT64", filter_list, 1, FALSE)
sch <- tiledb:::libtiledb_array_schema(ctx, dom, c(att), cell_order = "COL_MAJOR", tile_order = "COL_MAJOR", sparse = FALSE)
pth <- paste(tmp, "test_dense_read_write", sep = "/")
uri <- tiledb:::libtiledb_array_create(pth, sch)
uri <- tiledb:::libtiledb_array_create(tmp, sch)

dat <- c(3, 2, 1)
arr <- tiledb:::libtiledb_array_open(ctx, uri, "WRITE")
Expand All @@ -190,7 +191,7 @@ unlink(tmp, recursive = TRUE)
#})

#test_that("basic dense vector read subarray works", {
dir.create(tmp <- tempfile())
tmp <- tempfile()
##ctx <- tiledb:::libtiledb_ctx()
ctx <- tiledb_get_context()@ptr
dim <- tiledb:::libtiledb_dim(ctx, "d1", "INT32", c(1L, 3L), 3L)
Expand All @@ -199,8 +200,7 @@ filter <- tiledb:::libtiledb_filter(ctx, "NONE")
filter_list <- tiledb:::libtiledb_filter_list(ctx, c(filter))
att <- tiledb:::libtiledb_attribute(ctx, "a1", "FLOAT64", filter_list, 1, FALSE)
sch <- tiledb:::libtiledb_array_schema(ctx, dom, c(att), cell_order = "COL_MAJOR", tile_order = "COL_MAJOR", sparse = FALSE)
pth <- paste(tmp, "test_dense_read_write", sep = "/")
uri <- tiledb:::libtiledb_array_create(pth, sch)
uri <- tiledb:::libtiledb_array_create(tmp, sch)

dat <- c(3, 2, 1)
arr <- tiledb:::libtiledb_array_open(ctx, uri, "WRITE")
Expand All @@ -222,6 +222,9 @@ expect_equal(res, dat[sub])
unlink(tmp, recursive = TRUE)
#})

if (isRESTCI) exit_file("skip VFS tests")

## n=170
#test_that("basic tiledb vfs constructor works", {
##ctx <- tiledb:::libtiledb_ctx()
ctx <- tiledb_get_context()@ptr
Expand All @@ -234,25 +237,21 @@ expect_true(is(vfs, "externalptr"))
#})

#test_that("basic vfs is_dir, is_file functionality works", {
dir.create(tmp <- tempfile())
tmp <- tempfile()

##ctx <- tiledb:::libtiledb_ctx()
ctx <- tiledb_get_context()@ptr
vfs <- tiledb:::libtiledb_vfs(ctx)

## test dir
expect_true(tiledb:::libtiledb_vfs_is_dir(vfs, tmp))
expect_false(tiledb:::libtiledb_vfs_is_dir(vfs, tmp))
expect_false(tiledb:::libtiledb_vfs_is_dir(vfs, "i don't exist"))

test_file_path <- paste("file:/", tmp, "test_file", sep = "/")
test_file <- file(test_file_path, "wb")
test_file <- file(tmp, "wb")
writeChar(c("foo", "bar", "baz"), test_file)
close(test_file)

## test file
if(.Platform$OS.type != "windows") {
expect_true(tiledb:::libtiledb_vfs_is_file(vfs, test_file_path))
}
expect_false(tiledb:::libtiledb_vfs_is_file(vfs, tmp))
expect_true(tiledb:::libtiledb_vfs_is_file(vfs, tmp))
unlink(tmp, recursive = TRUE)
#})
10 changes: 7 additions & 3 deletions inst/tinytest/test_matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
library(tinytest)
library(tiledb)

isOldWindows <- Sys.info()[["sysname"]] == "Windows" && grepl('Windows Server 2008', osVersion)
if (isOldWindows) exit_file("skip this file on old Windows releases")

ctx <- tiledb_ctx(limitTileDBCores())

isRESTCI <- Sys.getenv("TILEDB_CLOUD_REST_BIN", "") != ""
if (isRESTCI) {
## we can rely on the normal tempfile semantics but override the tmpdir
## argument to be our REST CI base url in the unit test namespace
tempfile <- function() { base::tempfile(tmpdir="tiledb://unit") }
}

uri <- tempfile()
M <- matrix(1:16, 4, 4, dimnames=list(LETTERS[1:4], letters[1:4]))
fromMatrix(M, uri)
Expand Down
Loading

0 comments on commit aa1b124

Please sign in to comment.