Skip to content

Commit

Permalink
Abort when no results files are found (#1155)
Browse files Browse the repository at this point in the history
* Abort when no results files are found

* Error message

* Actually test expect the error we created

* Cleaned up invalid test
  • Loading branch information
azimov authored Feb 28, 2025
1 parent 9fa5ecc commit 206c152
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 24 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ Imports:
tidyr (>= 1.2.0),
CohortGenerator (>= 0.10.0),
remotes,
scales
scales,
cli
Suggests:
Eunomia,
RSQLite (>= 2.2.1),
Expand Down
4 changes: 4 additions & 0 deletions R/Shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ createMergedResultsFile <-
recursive = TRUE
)

if (length(listOfZipFilesToUpload) == 0) {
cli::cli_abort("No result files found in folder", dataFolder)
}

for (zipFileName in listOfZipFilesToUpload) {
uploadResults(
connectionDetails = connectionDetails,
Expand Down
27 changes: 4 additions & 23 deletions tests/testthat/test-1-ResultsDataModel.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ VALUES ('Synthea','Synthea','OHDSI Community','SyntheaTM is a Synthetic Patient

test_that("Sqlite results data model", {
dbFile <- tempfile(fileext = ".sqlite")
createMergedResultsFile(dataFolder = file.path(folder, "export"), sqliteDbPath = dbFile, overwrite = TRUE, tablePrefix = "cd_")
expect_error(createMergedResultsFile(dataFolder = file.path("non_existant_export_folder"),
sqliteDbPath = dbFile,
overwrite = TRUE,
tablePrefix = "cd_"))
connectionDetailsSqlite <- DatabaseConnector::createConnectionDetails(dbms = "sqlite", server = dbFile)
connectionSqlite <- DatabaseConnector::connect(connectionDetails = connectionDetailsSqlite)
with_dbc_connection(connectionSqlite, {
Expand All @@ -189,27 +192,5 @@ test_that("Sqlite results data model", {
connectionDetails = connectionDetailsSqlite,
databaseSchema = "non_existant_schema"
))

specifications <- getResultsDataModelSpecifications()
for (tableName in unique(specifications$tableName)) {
primaryKey <- specifications %>%
dplyr::filter(tableName == !!tableName &
primaryKey == "Yes") %>%
dplyr::select("columnName") %>%
dplyr::pull()

if ("database_id" %in% primaryKey) {
sql <-
"SELECT COUNT(*) FROM @schema.@table_name WHERE database_id = '@database_id';"
sql <- SqlRender::render(
sql = sql,
schema = "main",
table_name = paste0("cd_", tableName),
database_id = "cdmv5"
)
databaseIdCount <- DatabaseConnector::querySql(connectionSqlite, sql)[, 1]
expect_true(databaseIdCount >= 0)
}
}
})
})

0 comments on commit 206c152

Please sign in to comment.