Skip to content

Commit

Permalink
Fix cmd checks and revise test
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonysena committed Aug 16, 2023
1 parent 415f3b0 commit 28c36f9
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 80 deletions.
4 changes: 1 addition & 3 deletions R/Execution.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ generateTargetsScript <- function(analysisSpecifications, executionSettings, dep
)
}
}
}

targetList
targetList
}, script = fileName)

#Store settings objects in the temp folder so they are available in targets
Expand Down
6 changes: 4 additions & 2 deletions R/ModuleEnv.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@
#'
#' @param code code block to execute
#' @param moduleFolder Instantiated Strategus module folder
#' @param injectVars list of var names list(name=value) to replace (e.g. replace list(foo = "some string") will
#' @param injectVars list of var names list(name=value) to replace (e.g. replace list(foo = "some string") will
#' find the pattern foo and replace it with the string some string - be careful!
#' @param tempScriptFile tempFile to write script to (ret
#' @param tempScriptFile tempFile to write script to
#' @param useLocalStrategusLibrary Use the locally installed Strategus library? TRUE will use the Strategus
#' installation from the calling R process.
#' @param job run as rstudio job
#' @param processName String name for process
#' @returns NULL invisibly
Expand Down
1 change: 1 addition & 0 deletions R/Settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ addModuleSpecifications <- function(analysisSpecifications, moduleSpecifications
#' @param cohortTableNames An object identifying the various cohort table names that will be created in the
#' `workDatabaseSchema`. This object can be created using the
#' [CohortGenerator::getCohortTableNames()] function.
#' @param tempEmulationSchema Some database platforms like Oracle and Impala do not truly support temp tables. To emulate temp tables, provide a schema with write privileges where temp tables can be created.
#' @param workFolder A folder in the local file system where intermediate results can be written.
#' @param resultsFolder A folder in the local file system where the module output will be written.
#' @param minCellCount The minimum number of subjects contributing to a count before it can be included
Expand Down
2 changes: 2 additions & 0 deletions man/createCdmExecutionSettings.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/createResultDataModels.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/withModuleRenv.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

146 changes: 73 additions & 73 deletions tests/testthat/test-Strategus.R
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
# test_that("Run Eunomia study", {
# # NOTE: Need to set this in each test otherwise it goes out of scope
# renv:::renv_scope_envvars(RENV_PATHS_CACHE = renvCachePath)
#
# # Setup keyring for the test
# Sys.setenv("STRATEGUS_KEYRING_PASSWORD" = keyringPassword)
# createKeyringForUnitTest(selectedKeyring = keyringName, selectedKeyringPassword = keyringPassword)
# on.exit(deleteKeyringForUnitTest())
#
# # Using a named and secured keyring
# Strategus::storeConnectionDetails(
# connectionDetails = connectionDetails,
# connectionDetailsReference = dbms,
# keyringName = keyringName
# )
#
# analysisSpecifications <- ParallelLogger::loadSettingsFromJson(
# fileName = system.file("testdata/analysisSpecification.json",
# package = "Strategus"
# )
# )
#
# # Create a unique set of cohort tables for this test run and
# # ensure they are removed when complete
# cohortTableNames <- CohortGenerator::getCohortTableNames(cohortTable = paste0("s", tableSuffix))
#
# # Use this line to limit to only running the CohortGeneratorModule
# # for testing purposes.
# analysisSpecifications$moduleSpecifications <- analysisSpecifications$moduleSpecifications[-c(2:length(analysisSpecifications$moduleSpecifications))]
# executionSettings <- createCdmExecutionSettings(
# connectionDetailsReference = dbms,
# workDatabaseSchema = workDatabaseSchema,
# cdmDatabaseSchema = cdmDatabaseSchema,
# cohortTableNames = cohortTableNames,
# workFolder = file.path(tempDir, "EunomiaTestStudy/work_folder"),
# resultsFolder = file.path(tempDir, "EunomiaTestStudy/results_folder"),
# minCellCount = 5
# )
#
# if (!dir.exists(file.path(tempDir, "EunomiaTestStudy"))) {
# dir.create(file.path(tempDir, "EunomiaTestStudy"), recursive = TRUE)
# }
# ParallelLogger::saveSettingsToJson(
# object = executionSettings,
# file.path(tempDir, "EunomiaTestStudy/eunomiaExecutionSettings.json")
# )
#
# executionSettings <- ParallelLogger::loadSettingsFromJson(
# fileName = file.path(tempDir, "EunomiaTestStudy/eunomiaExecutionSettings.json")
# )
#
# Strategus::execute(
# analysisSpecifications = analysisSpecifications,
# executionSettings = executionSettings,
# executionScriptFolder = file.path(tempDir, "EunomiaTestStudy/script_folder"),
# keyringName = keyringName
# )
#
# expect_true(file.exists(file.path(tempDir, "EunomiaTestStudy/results_folder/CohortGeneratorModule_1/done")))
#
# withr::defer(
# {
# CohortGenerator::dropCohortStatsTables(
# connectionDetails = connectionDetails,
# cohortDatabaseSchema = workDatabaseSchema,
# cohortTableNames = cohortTableNames,
# dropCohortTable = TRUE
# )
# unlink(file.path(tempDir, "EunomiaTestStudy"), recursive = TRUE, force = TRUE)
# },
# testthat::teardown_env()
# )
# })
test_that("Run Eunomia study", {
# NOTE: Need to set this in each test otherwise it goes out of scope
renv:::renv_scope_envvars(RENV_PATHS_CACHE = renvCachePath)

# Setup keyring for the test
Sys.setenv("STRATEGUS_KEYRING_PASSWORD" = keyringPassword)
createKeyringForUnitTest(selectedKeyring = keyringName, selectedKeyringPassword = keyringPassword)
on.exit(deleteKeyringForUnitTest())

# Using a named and secured keyring
Strategus::storeConnectionDetails(
connectionDetails = connectionDetails,
connectionDetailsReference = dbms,
keyringName = keyringName
)

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

# Create a unique set of cohort tables for this test run and
# ensure they are removed when complete
cohortTableNames <- CohortGenerator::getCohortTableNames(cohortTable = paste0("s", tableSuffix))

# Use this line to limit to only running the CohortGeneratorModule
# for testing purposes.
analysisSpecifications$moduleSpecifications <- analysisSpecifications$moduleSpecifications[-c(2:length(analysisSpecifications$moduleSpecifications))]
executionSettings <- createCdmExecutionSettings(
connectionDetailsReference = dbms,
workDatabaseSchema = workDatabaseSchema,
cdmDatabaseSchema = cdmDatabaseSchema,
cohortTableNames = cohortTableNames,
workFolder = file.path(tempDir, "EunomiaTestStudy/work_folder"),
resultsFolder = file.path(tempDir, "EunomiaTestStudy/results_folder"),
minCellCount = 5
)

if (!dir.exists(file.path(tempDir, "EunomiaTestStudy"))) {
dir.create(file.path(tempDir, "EunomiaTestStudy"), recursive = TRUE)
}
ParallelLogger::saveSettingsToJson(
object = executionSettings,
file.path(tempDir, "EunomiaTestStudy/eunomiaExecutionSettings.json")
)

executionSettings <- ParallelLogger::loadSettingsFromJson(
fileName = file.path(tempDir, "EunomiaTestStudy/eunomiaExecutionSettings.json")
)

Strategus::execute(
analysisSpecifications = analysisSpecifications,
executionSettings = executionSettings,
executionScriptFolder = file.path(tempDir, "EunomiaTestStudy/script_folder"),
keyringName = keyringName
)

expect_true(file.exists(file.path(tempDir, "EunomiaTestStudy/results_folder/CohortGeneratorModule_1/done")))

withr::defer(
{
CohortGenerator::dropCohortStatsTables(
connectionDetails = connectionDetails,
cohortDatabaseSchema = workDatabaseSchema,
cohortTableNames = cohortTableNames,
dropCohortTable = TRUE
)
unlink(file.path(tempDir, "EunomiaTestStudy"), recursive = TRUE, force = TRUE)
},
testthat::teardown_env()
)
})

0 comments on commit 28c36f9

Please sign in to comment.