Skip to content

Commit

Permalink
TEMPORARY: suppress warnings in cache tests (#5)
Browse files Browse the repository at this point in the history
@eliotmcintire we can revert this once the issue is dealt with in `archivist`
  • Loading branch information
achubaty committed Jun 22, 2017
1 parent 565f572 commit af0cf0f
Showing 1 changed file with 38 additions and 39 deletions.
77 changes: 38 additions & 39 deletions tests/testthat/test-cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ test_that("test file-backed raster caching", {
# confirm that the raster has the given tmp filename
expect_identical(strsplit(tmpRasterfile, split = "[\\/]"),
strsplit(a@file@name, split = "[\\/]"))
aa <- Cache(randomPolyToDisk, tmpdir, tmpRasterfile, cacheRepo = tmpdir, userTags = "something2")
aa <- suppressWarnings(Cache(randomPolyToDisk, tmpdir, tmpRasterfile, cacheRepo = tmpdir, userTags = "something2"))

# Test clearCache by tags
expect_equal(NROW(showCache(tmpdir)), 9)
clearCache(tmpdir, userTags = "something$")
suppressWarnings(clearCache(tmpdir, userTags = "something$"))
expect_equal(NROW(showCache(tmpdir)), 9)
clearCache(tmpdir, userTags = "something2")
suppressWarnings(clearCache(tmpdir, userTags = "something2"))
expect_equal(NROW(showCache(tmpdir)), 0)

aa <- Cache(randomPolyToDisk, tmpdir, tmpRasterfile, cacheRepo = tmpdir, userTags = "something2")
aa <- suppressWarnings(Cache(randomPolyToDisk, tmpdir, tmpRasterfile, cacheRepo = tmpdir, userTags = "something2"))
expect_equal(NROW(showCache(tmpdir)), 9)
clearCache(tmpdir, userTags = c("something$", "testing$"))
suppressWarnings(clearCache(tmpdir, userTags = c("something$", "testing$")))
expect_equal(NROW(showCache(tmpdir)), 9)
clearCache(tmpdir, userTags = c("something2$", "testing$"))
suppressWarnings(clearCache(tmpdir, userTags = c("something2$", "testing$")))
expect_equal(NROW(showCache(tmpdir)), 9)
clearCache(tmpdir, userTags = c("something2$", "randomPolyToDisk$"))
suppressWarnings(clearCache(tmpdir, userTags = c("something2$", "randomPolyToDisk$")))
expect_equal(NROW(showCache(tmpdir)), 0)

aa <- Cache(randomPolyToDisk, tmpdir, tmpRasterfile, cacheRepo = tmpdir, userTags = "something2")
aa <- suppressWarnings(Cache(randomPolyToDisk, tmpdir, tmpRasterfile, cacheRepo = tmpdir, userTags = "something2"))

# confirm that the raster has the new filename in the cachePath
expect_false(identical(strsplit(tmpRasterfile, split = "[\\/]"),
Expand All @@ -56,7 +56,7 @@ test_that("test file-backed raster caching", {
nOT <- Sys.time()
for (i in 1:2) {
assign(paste0("b", i), system.time(
assign(paste0("a", i), Cache(rasterTobinary, aa, cacheRepo = tmpdir, notOlderThan = nOT))
assign(paste0("a", i), suppressWarnings(Cache(rasterTobinary, aa, cacheRepo = tmpdir, notOlderThan = nOT)))
))
nOT <- Sys.time() - 100
}
Expand All @@ -67,7 +67,7 @@ test_that("test file-backed raster caching", {
# confirm that the second one was obtained through reading from Cache... much faster than writing
expect_true(b1[1] > b2[1])

clearCache(tmpdir)
suppressWarnings(clearCache(tmpdir))

# Check that Caching of rasters saves them to tif file instead of rdata
randomPolyToMemory <- function(tmpdir) {
Expand All @@ -77,11 +77,11 @@ test_that("test file-backed raster caching", {
r
}

bb <- Cache(randomPolyToMemory, tmpdir, cacheRepo = tmpdir)
bb <- suppressWarnings(Cache(randomPolyToMemory, tmpdir, cacheRepo = tmpdir))
expect_true(filename(bb) == "")
expect_true(inMemory(bb))

bb <- Cache(randomPolyToMemory, tmpdir, cacheRepo = tmpdir)
bb <- suppressWarnings(Cache(randomPolyToMemory, tmpdir, cacheRepo = tmpdir))
expect_true(NROW(showCache(tmpdir)) == 9)

# Test that factors are saved correctly
Expand All @@ -92,7 +92,7 @@ test_that("test file-backed raster caching", {
dataType(r) <- "INT1U"
r
}
bb <- Cache(randomPolyToFactorInMemory, tmpdir, cacheRepo = tmpdir)
bb <- suppressWarnings(Cache(randomPolyToFactorInMemory, tmpdir, cacheRepo = tmpdir))
expect_true(dataType(bb) == "INT1U")
expect_true(raster::is.factor(bb))
expect_true(is(raster::levels(bb)[[1]], "data.frame"))
Expand All @@ -114,7 +114,7 @@ test_that("test file-backed raster caching", {
# bb1 has original tmp filename
bb1 <- randomPolyToFactorOnDisk(tmpdir, tf)
# bb has new one, inside of cache repository, with same basename
bb <- Cache(randomPolyToFactorOnDisk, tmpdir, tmpFile = tf, cacheRepo = tmpdir)
bb <- suppressWarnings(Cache(randomPolyToFactorOnDisk, tmpdir, tmpFile = tf, cacheRepo = tmpdir))
expect_true(dirname(filename(bb)) == file.path(tmpdir, "rasters"))
expect_true(basename(filename(bb)) == basename(tf))
expect_false(filename(bb) == tf)
Expand All @@ -126,7 +126,7 @@ test_that("test file-backed raster caching", {
expect_true(NCOL(raster::levels(bb)[[1]]) == 3)
expect_true(NROW(raster::levels(bb)[[1]]) == 30)

clearCache(tmpdir)
suppressWarnings(clearCache(tmpdir))
})

test_that("test date-based cache removal", {
Expand All @@ -139,16 +139,15 @@ test_that("test date-based cache removal", {
tmpfile <- normPath(tmpfile)
try(clearCache(tmpdir), silent = TRUE)

a <- Cache(runif, 1, cacheRepo = tmpdir)
a <- suppressWarnings(Cache(runif, 1, cacheRepo = tmpdir))
a1 <- showCache(tmpdir)
expect_true(NROW(a1) > 0)
b <- clearCache(tmpdir, before = Sys.Date() - 1)
expect_true(NROW(b) == 0)
expect_identical(a1, showCache(tmpdir))

b <- clearCache(tmpdir, before = Sys.Date() + 1)
b <- suppressWarnings(clearCache(tmpdir, before = Sys.Date() + 1))
expect_identical(b, a1)

})

test_that("test keepCache", {
Expand All @@ -159,31 +158,31 @@ test_that("test keepCache", {
on.exit(unlink(tmpdir, recursive = TRUE), add = TRUE)

try(clearCache(tmpdir), silent = TRUE)
Cache(rnorm, 10, cacheRepo = tmpdir)
Cache(runif, 10, cacheRepo = tmpdir)
Cache(round, runif(4), cacheRepo = tmpdir)
suppressWarnings(Cache(rnorm, 10, cacheRepo = tmpdir))
suppressWarnings(Cache(runif, 10, cacheRepo = tmpdir))
suppressWarnings(Cache(round, runif(4), cacheRepo = tmpdir))
expect_true(NROW(showCache(tmpdir)) == 24)
expect_true(NROW(showCache(tmpdir, c("rnorm","runif"))) == 0) # and search
expect_true(NROW(keepCache(tmpdir, "rnorm")) == 8)
expect_true(NROW(suppressWarnings(keepCache(tmpdir, "rnorm"))) == 8)
# do it twice to make sure it can deal with repeats
expect_true(NROW(keepCache(tmpdir, "rnorm")) == 8)
Sys.sleep(1)
st <- Sys.time()
Sys.sleep(1)
Cache(sample, 10, cacheRepo = tmpdir)
Cache(length, 10, cacheRepo = tmpdir)
Cache(sum, runif(4), cacheRepo = tmpdir)
suppressWarnings(Cache(sample, 10, cacheRepo = tmpdir))
suppressWarnings(Cache(length, 10, cacheRepo = tmpdir))
suppressWarnings(Cache(sum, runif(4), cacheRepo = tmpdir))
showCache(tmpdir, after = st)
expect_true(NROW(showCache(tmpdir, before = st)) == 8)
expect_true(NROW(keepCache(tmpdir, before = st)) == 8)
expect_true(NROW(suppressWarnings(keepCache(tmpdir, before = st))) == 8)
expect_true(NROW(showCache(tmpdir)) == 8)

ranNums <- Cache(runif, 4, cacheRepo = tmpdir, userTags = "objectName:a")
ranNums <- Cache(rnorm, 4, cacheRepo = tmpdir, userTags = "objectName:a")
ranNums <- suppressWarnings(Cache(runif, 4, cacheRepo = tmpdir, userTags = "objectName:a"))
ranNums <- suppressWarnings(Cache(rnorm, 4, cacheRepo = tmpdir, userTags = "objectName:a"))
showCache(tmpdir) # shows spades, runif and rnorm objects
expect_true(NROW(showCache(tmpdir, userTags = c("spades","rnorm"))) == 0) # shows nothing because object has both spades and rnorm
expect_true(length(unique(showCache(tmpdir, userTags = "spades|rnorm")$artifact)) == 2) # "or" search
expect_true(length(unique(keepCache(tmpdir, userTags = "spades|rnorm")$artifact)) == 2) # keep all with spades or rnorm
expect_true(length(unique(suppressWarnings(keepCache(tmpdir, userTags = "spades|rnorm")$artifact))) == 2) # keep all with spades or rnorm
expect_true(length(unique(showCache(tmpdir)$artifact)) == 2) # shows spades, runif and rnorm objects
})

Expand Down Expand Up @@ -213,9 +212,9 @@ test_that("test environments", {

# Upper level -- all are same, because values are same, even though all are enviros
shortFn <- function(a) sample(a$a)
out <- Cache(shortFn, a = a, cacheRepo = tmpdir)
out2 <- Cache(shortFn, a = b, cacheRepo = tmpdir)
out3 <- Cache(shortFn, a = g, cacheRepo = tmpdir)
out <- suppressWarnings(Cache(shortFn, a = a, cacheRepo = tmpdir))
out2 <- suppressWarnings(Cache(shortFn, a = b, cacheRepo = tmpdir))
out3 <- suppressWarnings(Cache(shortFn, a = g, cacheRepo = tmpdir))
expect_true(identical(attributes(out), attributes(out2)))
expect_true(identical(attributes(out), attributes(out3)))

Expand All @@ -228,19 +227,19 @@ test_that("test environments", {
i2 <- i
i2$d <- as.list(i2$d)

out <- Cache(shortFn, a = a, cacheRepo = tmpdir)
out2 <- Cache(shortFn, a = b, cacheRepo = tmpdir)
out3 <- Cache(shortFn, a = g, cacheRepo = tmpdir)
out4 <- Cache(shortFn, a = i, cacheRepo = tmpdir)
out5 <- Cache(shortFn, a = i2, cacheRepo = tmpdir)
out <- suppressWarnings(Cache(shortFn, a = a, cacheRepo = tmpdir))
out2 <- suppressWarnings(Cache(shortFn, a = b, cacheRepo = tmpdir))
out3 <- suppressWarnings(Cache(shortFn, a = g, cacheRepo = tmpdir))
out4 <- suppressWarnings(Cache(shortFn, a = i, cacheRepo = tmpdir))
out5 <- suppressWarnings(Cache(shortFn, a = i2, cacheRepo = tmpdir))

expect_false(identical(attributes(out), attributes(out2))) # test different values are different
expect_true(identical(attributes(out), attributes(out3))) # test same values but different enviros are same
expect_true(identical(attributes(out), attributes(out4))) # test environment is same as a list
expect_true(identical(attributes(out), attributes(out5))) # test environment is same as recursive list

df <- data.frame(a = a$a, b = LETTERS[1:10])
out6 <- Cache(shortFn, a = df, cacheRepo = tmpdir)
out7 <- Cache(shortFn, a = df, cacheRepo = tmpdir)
out6 <- suppressWarnings(Cache(shortFn, a = df, cacheRepo = tmpdir))
out7 <- suppressWarnings(Cache(shortFn, a = df, cacheRepo = tmpdir))
expect_true(identical(attributes(out6), attributes(out7))) # test data.frame
})

0 comments on commit af0cf0f

Please sign in to comment.