File: test-s3.R

package info (click to toggle)
r-cran-memoise 2.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 208 kB
  • sloc: sh: 10; makefile: 5
file content (30 lines) | stat: -rw-r--r-- 620 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
context("s3")

test_that("using a s3 cache works", {
  skip_on_cran()
  skip_on_travis_pr()
  skip_without_aws_credentials()

  aws <- cache_s3("memoise-tests")
  i <- 0
  fn <- function() { i <<- i + 1; i }
  fnm <- memoise(fn, cache = aws)
  on.exit(forget(fnm))

  expect_equal(fn(), 1)
  expect_equal(fn(), 2)
  expect_equal(fnm(), 3)
  expect_equal(fnm(), 3)
  expect_equal(fn(), 4)
  expect_equal(fnm(), 3)

  expect_false(forget(fn))
  expect_true(forget(fnm))
  expect_equal(fnm(), 5)

  expect_true(drop_cache(fnm)())
  expect_equal(fnm(), 6)

  expect_true(is.memoised(fnm))
  expect_false(is.memoised(fn))
})