tests/testthat/test-load_env_csv.R

test_that("load_env_csv works", {
  # reset env
  setup_new_env()

  load_env_csv("./csv/load_env_csv/save/")

  expect_equal(analysr_env$current_hash, 9)

  df_to_load <-
    c("measures",
      "periods",
      "events",
      "stat_units",
      "descriptions")
  df_to_load %>%
    purrr::map(function(x) {
      # check that data frame are not empty
      df <- getElement(analysr_env, x)
      expect_equal(is.data.frame(df) && nrow(df) != 0, TRUE)
      # check that data frame are identical
      file_path <-
        file.path("./csv/load_env_csv/save/", paste0(x, ".csv"))
      expected <- quiet_read_csv(file = file_path,
                                col_types = readr::cols("hash" = "i",
                                "stat_unit" = "c"))$result
      expect_equal(dplyr::all_equal(df, expected), TRUE)
    })

})
RADS-project/analysr-git-test documentation built on Feb. 13, 2022, 8:13 a.m.