Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrie committed Mar 23, 2024
1 parent 9e6718e commit 1cdbd6d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 32 deletions.
5 changes: 4 additions & 1 deletion R/pkgDep.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ pkgDep <- function(pkg, availPkgs, repos = getOption("repos"), type = "source",
quiet = quiet, ...)
}

assert_that(nrow(availPkgs) > 0, msg = "Unable to retrieve available packages from CRAN")
assert_that(
nrow(availPkgs) > 0,
msg = sprintf("Unable to retrieve %s package %s from %s", type, pkg, repos)
)


pkgInAvail <- pkg %in% availPkgs[, "Package"]
Expand Down
21 changes: 4 additions & 17 deletions tests/testthat/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ mock_write_packages <- function(dir, type = "source", r_version) {
if (missing(pkgs)) pkgs <- c("chron", "curl")
if (missing(types)) types <- set_test_types()

pdb_source <- pkgAvail(repos = MRAN, type = "source", Rversion = Rversion)
pdb_win <- pkgAvail(repos = MRAN, type = "win.binary", Rversion = Rversion)
# pdb_source <- pkgAvail(repos = MRAN, type = "source", Rversion = Rversion)
# pdb_win <- pkgAvail(repos = MRAN, type = "win.binary", Rversion = Rversion)
# pdb_mac <- pkgAvail(repos = MRAN, type = "mac.binary", Rversion = Rversion)

mockr::with_mock(
Expand All @@ -111,28 +111,15 @@ mock_write_packages <- function(dir, type = "source", r_version) {
{

for (type in types) {
pkgList_source <- pkgDep(pkgs, availPkgs = pdb_source, repos = MRAN,
pdb <- pkgAvail(repos = MRAN, type = type, Rversion = Rversion)
pkgList_source <- pkgDep(pkgs, availPkgs = pdb, repos = MRAN,
type = type, suggests = FALSE, Rversion = Rversion)

makeRepo(pkgList_source, path = path, repos = MRAN,
type = type,
quiet = TRUE, Rversion = Rversion)

}

# pkgList_win <- pkgDep(pkgs, availPkgs = pdb_win, repos = MRAN,
# type = "win.binary",
# suggests = FALSE, Rversion = Rversion)
# makeRepo(pkgList_win, path = path, repos = MRAN,
# type = "win.binary",
# quiet = TRUE, Rversion = Rversion)

# pkgList_mac <- pkgDep(pkgs, availPkgs = pdb_mac, repos = MRAN,
# type = "mac.binary",
# suggests = FALSE, Rversion = Rversion)
# makeRepo(pkgList_mac, path = path, repos = MRAN,
# type = "mac.binary",
# quiet = TRUE, Rversion = Rversion)
}
)
}
Expand Down
16 changes: 10 additions & 6 deletions tests/testthat/test-3-makeRepo.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@


{
revolution <- MRAN("2023-08-04")
revolution <- MRAN("2023-08-31")
if (!is.online(revolution, tryHttp = FALSE)) {
# Use http:// for older versions of R
revolution <- sub("^https://", "http://", revolution)
}
rvers <- "4.0"
rvers <- "4.3"
pkgs <- c("Rcpp")
repo_root <- file.path(tempdir(), "miniCRAN", Sys.Date())
if (file.exists(repo_root)) unlink(repo_root, recursive = TRUE)
Expand All @@ -19,6 +19,7 @@

# types are defined in env var `minicran_test_scope`
types <- set_test_types()
pkg_type <- types[1]

test_for_type <- function(pkg_type) {
# skip_if_not_installed("mockr")
Expand All @@ -29,19 +30,20 @@ test_for_type <- function(pkg_type) {
skip_if_offline()
skip_if_not_installed("mockr")

# pdb <- pkgAvail(repos = revolution, type = pkg_type, quiet = TRUE)
pdb <- pkgAvail(repos = revolution, type = pkg_type, Rversion = rvers, quiet = TRUE)
pkgList <- pkgDep(pkgs, availPkgs = pdb, repos = revolution, type = pkg_type,
suggests = FALSE, Rversion = rvers, quiet = FALSE)
prefix <- repoPrefix(pkg_type, Rversion = rvers)
dir.create(repo_root, recursive = TRUE, showWarnings = FALSE)

mockr::with_mock(
ret <- mockr::with_mock(
download_packages = mock_download_packages,
write_packages = mock_write_packages,
.env = "miniCRAN",
{
ret <- makeRepo(pkgList, path = repo_root, repos = revolution,
type = pkg_type, quiet = TRUE, Rversion = rvers)
makeRepo(pkgList, path = repo_root, repos = revolution,
type = pkg_type, quiet = TRUE, Rversion = rvers)
}
)

Expand All @@ -64,6 +66,8 @@ test_for_type <- function(pkg_type) {
})
}

for (pkg_type in (types)) {test_for_type(pkg_type = pkg_type)}
# types are defined in env var `minicran_test_scope`
types <- set_test_types()
for (pkg_type in types) {test_for_type(pkg_type = pkg_type)}

unlink(repo_root, recursive = TRUE)
16 changes: 8 additions & 8 deletions tests/testthat/test-5-updateRepo.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
# Use http:// for older versions of R
revolution <- sub("^https://", "http://", revolution)
}
rvers <- "4.0"
pkgs <- c("chron", "XML")
rvers <- "4.2"
pkgs <- c("chron", "data.table")

types <- intersect(
set_test_types(),
# c("source", "win.binary", "mac.binary")
c("source", "win.binary")
# c("source", "win.binary")
c("source", "win.binary", "mac.binary")
)

names(types) <- types
Expand All @@ -38,19 +38,19 @@ test_that("sample repo is setup correctly", {
})
expect_type(pkgList, "list")

z <- .createSampleRepo(path = repo_root, MRAN = revolution, Rversion = rvers,
.createSampleRepo(path = repo_root, MRAN = revolution, Rversion = rvers,
pkgs = pkgs, types = names(types))
# expect_type(z, "character")
pkg_names <- unname(pkgAvail(repo_root, quiet = TRUE)[, "Package"])
pkg_names <- unname(pkgAvail(repo_root, quiet = TRUE, type = type, Rversion = rvers)[, "Package"])
expect_true(all(pkgs %in% pkg_names))
})


# Add packages to repo ----------------------------------------------------

pkgsAdd <- c("Rcpp")

pkg_type <- names(types)[1]

for (pkg_type in names(types)) {

skip_if_not_installed("mockr")
Expand Down Expand Up @@ -198,7 +198,7 @@ for (pkg_type in names(types)) {
# In the following allow for differences between mac.binary and other types
expect_gte(nrow(old), 1)
expect_equal(ncol(old), 4)
expect_true( "XML" %in% rownames(old))
expect_true( "data.table" %in% rownames(old))

mockr::with_mock(
download_packages = mock_download_packages,
Expand Down

0 comments on commit 1cdbd6d

Please sign in to comment.