tests/testthat/test-data_dir.R

context("Get/Set STATS19_DOWNLOAD_DIRECTORY envvar")

test_that("Set STATS19_DOWNLOAD_DIRECTORY ", {
  expect_error(set_data_directory())

  test_path = file.path(tempdir(), "stats19")
  dir.create(test_path)
  # hold value
  c = get_data_directory()
  Sys.setenv(STATS19_DOWNLOAD_DIRECTORY = "")
  set_data_directory(test_path)
  expect_true(identical(get_data_directory(), test_path))
  # reset test user's prefs
  if(!identical(c, tempdir())) {
    set_data_directory(c)
  }
})

test_that("Get STATS19_DOWNLOAD_DIRECTORY ", {
  # TODO: we can do this abit more sophisticated
  c = Sys.getenv("STATS19_DOWNLOAD_DIRECTORY")
  if(c == "") c = tempdir()
  expect_true(identical(get_data_directory(), c))
})

Try the stats19 package in your browser

Any scripts or data that you put into this service are public.

stats19 documentation built on Nov. 5, 2023, 1:09 a.m.