Skip to content

Commit

Permalink
Modify test cases to prevent collision of directories
Browse files Browse the repository at this point in the history
(without cleaning up)
  • Loading branch information
chainsawriot committed Feb 11, 2023
1 parent 7b23539 commit 5bf4fea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
19 changes: 12 additions & 7 deletions tests/testthat/test_dockerize.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
.gen_temp_dir <- function() {
file.path(tempdir(), paste(sample(c(LETTERS, letters), 20, replace = TRUE), collapse = ""))
}

test_that("defensive programming", {
graph <- readRDS("../testdata/sle_graph.RDS")
expect_error(dockerize(graph, output_dir = tempdir()))
})

test_that("integration of #13 in dockerize()", {
gran_ok <- readRDS("../testdata/gran_ok.RDS")
temp_dir <- file.path(tempdir(), sample(1:10000, size = 1))
temp_dir <- .gen_temp_dir()
dockerize(granlist = gran_ok, output_dir = temp_dir) ## granlist_as_comment = TRUE
x <- readLines(file.path(temp_dir, "gran.R"))
expect_true(any(grepl("^## ## To reconstruct this file", x)))
Expand All @@ -17,7 +21,7 @@ test_that("integration of #13 in dockerize()", {
test_that("integration of #16 in dockerize()", {
## verbose
gran_ok <- readRDS("../testdata/gran_ok.RDS")
temp_dir <- file.path(tempdir(), sample(1:10000, size = 1))
temp_dir <- .gen_temp_dir()
dockerize(granlist = gran_ok, output_dir = temp_dir) ## verbose = TRUE
x <- readLines(file.path(temp_dir, "gran.R"))
expect_true(any(grepl("^verbose <- TRUE", x)))
Expand All @@ -39,7 +43,7 @@ test_that("integration of #16 in dockerize()", {

test_that("integration of #18 in dockerize()", {
gran_ok <- readRDS("../testdata/gran_ok.RDS")
temp_dir <- file.path(tempdir(), sample(1:10000, size = 1))
temp_dir <- .gen_temp_dir()
dockerize(granlist = gran_ok, output_dir = temp_dir) ## cran_mirror = "https://cran.r-project.org/"
x <- readLines(file.path(temp_dir, "gran.R"))
expect_true(any(grepl("^cran_mirror <- \"https://cran\\.r\\-project\\.org/\"", x)))
Expand All @@ -58,7 +62,7 @@ test_that("integration of #18 in dockerize()", {
test_that("integration of #20 to dockerize()", {
gran_ok <- readRDS("../testdata/gran_ok.RDS")
expect_equal(gran_ok$r_version, "4.2.2")
temp_dir <- file.path(tempdir(), sample(1:10000, size = 1))
temp_dir <- .gen_temp_dir()
dockerize(gran_ok, output_dir = temp_dir) ## cran_mirror = "https://cran.r-project.org/"
x <- readLines(file.path(temp_dir, "gran.R"))
expect_true(any(grepl("^cran_mirror <- \"https://cran\\.r\\-project\\.org/\"", x)))
Expand All @@ -78,7 +82,7 @@ test_that("integration of #20 to dockerize()", {
test_that("Dockerize R < 3.1 and >= 2.1", {
gran_rio <- readRDS("../testdata/gran_rio_old.RDS")
expect_equal(gran_rio$r_version, "3.0.1")
temp_dir <- file.path(tempdir(), sample(1:10000, size = 1))
temp_dir <- .gen_temp_dir()
dockerize(gran_rio, output_dir = temp_dir)
expect_true(file.exists(file.path(temp_dir, "compile_r.sh")))
Dockerfile <- readLines(file.path(temp_dir, "Dockerfile"))
Expand All @@ -92,7 +96,7 @@ test_that("Dockerize R < 3.1 and >= 2.1", {
test_that("Docker R < 2.1", {
gran_rio <- readRDS("../testdata/gran_rio_old.RDS")
gran_rio$r_version <- "2.1.0" ## exactly 2.1.0, no error
temp_dir <- file.path(tempdir(), sample(1:10000, size = 1))
temp_dir <- .gen_temp_dir()
expect_error(dockerize(gran_rio, output_dir = temp_dir), NA)
gran_rio <- readRDS("../testdata/gran_rio_old.RDS")
gran_rio$r_version <- "2.0.0"
Expand All @@ -115,6 +119,7 @@ test_that(".consolidate_sysreqs and issue #21", {

test_that("Dockerize warning, issue #21", {
graph <- readRDS("../testdata/issue21.RDS")
temp_dir <- file.path(tempdir(), sample(1:10000, size = 1))
temp_dir <- .gen_temp_dir()
expect_warning(dockerize(graph, output_dir = temp_dir))
})

8 changes: 6 additions & 2 deletions tests/testthat/test_resolve.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.gen_temp_dir <- function() {
file.path(tempdir(), paste(sample(c(LETTERS, letters), 20, replace = TRUE), collapse = ""))
}

test_that("defensive programming", {
expect_error(resolve("LDAvis", os = "windows"))
})
Expand Down Expand Up @@ -48,7 +52,7 @@ test_that("cache #17", {
skip_if_offline()
skip_on_cran()
gran_ok <- readRDS("../testdata/gran_ok.RDS")
temp_dir <- file.path(tempdir(), sample(1:10000, size = 1))
temp_dir <- .gen_temp_dir()
dockerize(gran_ok, output_dir = temp_dir) ## cache = FALSE
x <- readLines(file.path(temp_dir, "Dockerfile"))
expect_false(any(grepl("^COPY cache", x)))
Expand All @@ -71,7 +75,7 @@ test_that("cache for R < 3.1 and R >= 2.1", {
skip_on_cran()
gran_rio <- readRDS("../testdata/gran_rio_old.RDS")
expect_equal(gran_rio$r_version, "3.0.1")
temp_dir <- file.path(tempdir(), sample(1:10000, size = 1))
temp_dir <- .gen_temp_dir()
dockerize(gran_rio, output_dir = temp_dir, cache = TRUE, verbose = FALSE)
x <- readLines(file.path(temp_dir, "Dockerfile"))
expect_true(any(grepl("^COPY cache", x)))
Expand Down

0 comments on commit 5bf4fea

Please sign in to comment.