attic/testthat2/test_base_downloadOMLObject.R

context("downloadOMLObject")

test_that("downloadOMLObject", {
  # initial cleanup
  clearOMLCache()
  
  grid = expand.grid(id = 2:3, object = c("data", "task", "flow", "run"), stringsAsFactors = FALSE)
  for (i in 1:nrow(grid)) {
    # check if there is error when file is not in cache but cache.only option is active
    expect_error(downloadOMLObject(id = grid[i, "id"], object = grid[i, "object"], cache.only = TRUE), "not found in cache")
    # check if all files have been downloaded and exist in cache dir now
    down = downloadOMLObject(id = grid[i, "id"], object = grid[i, "object"])
    for (j in 1:length(down$files)) {
      expect_true(identical(file.exists(down$files[[j]]$path), down$files[[j]]$found))
    }
  }
  
  clearOMLCache()
  # change apikey temporairly
  apikey = getOMLConfig()$apikey
  setOMLConfig(apikey = collapse(rep("a", 32), ""))
  for (i in 1:nrow(grid)) {
    # check if error is print when xml contains an error node
    expect_error(downloadOMLObject(id = grid[i, "id"], object = grid[i, "object"]), "Authentication failed")
  }
  setOMLConfig(apikey = apikey)
  
  # cleanup
  clearOMLCache()
})
openml/openml-r documentation built on Oct. 21, 2022, 2:16 a.m.