Skip to content

Commit

Permalink
Create .zip with test module for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonysena committed Aug 21, 2023
1 parent 3384cee commit 4fdc96a
Show file tree
Hide file tree
Showing 21 changed files with 52 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/R_CMD_check_Hades.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
fail-fast: false
matrix:
config:
- {os: windows-latest, r: '4.2.3', rtools: '42', rspm: "https://cloud.r-project.org"}
- {os: macOS-latest, r: '4.2.3', rtools: '42', rspm: "https://cloud.r-project.org"}
#- {os: windows-latest, r: '4.2.3', rtools: '42', rspm: "https://cloud.r-project.org"}
#- {os: macOS-latest, r: '4.2.3', rtools: '42', rspm: "https://cloud.r-project.org"}
- {os: ubuntu-20.04, r: '4.2.3', rtools: '42', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
#- {os: windows-latest, r: 'release', rtools: '', rspm: "https://cloud.r-project.org"}
#- {os: macOS-latest, r: 'release', rtools: '', rspm: "https://cloud.r-project.org"}
Expand Down
53 changes: 21 additions & 32 deletions R/ModuleInstantiation.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,44 +144,33 @@ instantiateModule <- function(module, version, remoteRepo, remoteUsername, modul
dir.create(moduleFolder)
success <- FALSE
on.exit(if (!success) unlink(moduleFolder, recursive = TRUE))
moduleFile <- file.path(moduleFolder, sprintf("%s_%s.zip", module, version))
if (module == "TestModule1") {
# For test purposes only: get module from extras folder
files <- list.files(
system.file(
"testdata/TestModules/TestModule1",
package = "Strategus"
# For unit testing purposes only: get module from inst/testdata folder
file.copy(
from = system.file(
file.path("testdata", basename(moduleFile)),
package = utils::packageName()
),
full.names = TRUE,
include.dirs = TRUE,
all.files = TRUE
to = moduleFolder
)
files <- c(files, list.files("extras/TestModules/TestModule1/renv", full.names = TRUE, include.dirs = FALSE, all.files = TRUE))
print(paste0("DEBUG 1: ", files))
#files <- files[!grepl("extras/TestModules/TestModule1/renv/library", files)]
files <- files[!grepl("\\.$", files)]
files <- files[!grepl(".Rhistory$", files)]
print(paste0("DEBUG 2: ", files))
file.copy(files, moduleFolder, recursive = TRUE)
#dir.create(file.path(moduleFolder, "renv"))
#file.copy("extras/TestModules/TestModule1/renv/activate.R", file.path(moduleFolder, "renv"), recursive = TRUE)
} else {
moduleFile <- file.path(moduleFolder, sprintf("%s_%s.zip", module, version))
moduleUrl <- sprintf("https://%s/%s/%s/archive/refs/tags/v%s.zip", remoteRepo, remoteUsername, module, version)
utils::download.file(url = moduleUrl, destfile = moduleFile)
utils::unzip(zipfile = moduleFile, exdir = moduleFolder)
unlink(moduleFile)
# At this point, the unzipped folders will likely exist in a sub folder.
# Move all files from that sub folder to the main module folder
subFolders <- list.dirs(path = moduleFolder, recursive = FALSE)
if (length(subFolders) > 0) {
for (i in 1:length(subFolders)) {
R.utils::copyDirectory(
from = subFolders[i],
to = moduleFolder,
recursive = TRUE
)
unlink(subFolders[i], recursive = TRUE)
}
}
utils::unzip(zipfile = moduleFile, exdir = moduleFolder)
unlink(moduleFile)
# At this point, the unzipped folders will likely exist in a sub folder.
# Move all files from that sub folder to the main module folder
subFolders <- list.dirs(path = moduleFolder, recursive = FALSE)
if (length(subFolders) > 0) {
for (i in 1:length(subFolders)) {
R.utils::copyDirectory(
from = subFolders[i],
to = moduleFolder,
recursive = TRUE
)
unlink(subFolders[i], recursive = TRUE)
}
}

Expand Down
30 changes: 28 additions & 2 deletions extras/PackageMaintenance.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,32 @@ unlink("inst/doc/IntroductionToStrategus.tex")
pkgdown::build_site()
OhdsiRTools::fixHadesLogo()

# Repackage the test module for unit testing
# NOTE: This is only necessary when the TestModule
# has been updated
testModuleRootFolder <- "extras/TestModule1-0.0.1"
targetModuleZipFile <- "TestModule1_0.0.1.zip"
testModuleFilesToRemove <- c(
file.path(testModuleRootFolder, ".RData"),
file.path(testModuleRootFolder, ".Rhistory")
)
testModuleDirToRemove <- c(
file.path(testModuleRootFolder, ".Rproj.user"),
file.path(testModuleRootFolder, "renv/library")
)
unlink(testModuleFilesToRemove)
unlink(testModuleDirToRemove, recursive = TRUE)



oldwd <- getwd()
setwd("extras")
zip::zip(
zipfile = targetModuleZipFile,
files = list.files("TestModule1-0.0.1", all.files = TRUE, recursive = TRUE, include.dirs = TRUE, full.names = TRUE)
)
file.copy(
from = targetModuleZipFile,
to = file.path("../inst/testdata", targetModuleZipFile),
overwrite = TRUE
)
file.remove(targetModuleZipFile)
setwd(oldwd)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added inst/testdata/TestModule1_0.0.1.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/testthat/test-Strategus.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test_that("Run Eunomia study", {
)

analysisSpecifications <- ParallelLogger::loadSettingsFromJson(
fileName = system.file("testdata/testModuleAnalysisSpecification.json",
fileName = system.file("testdata/unitTestAnalysisSpecification.json",
package = "Strategus"
)
)
Expand Down

0 comments on commit 4fdc96a

Please sign in to comment.