Skip to content

Commit

Permalink
Merge pull request #463 from katy-sadowski/katy__test_cleanup
Browse files Browse the repository at this point in the history
Reorganize test files
  • Loading branch information
katy-sadowski authored Jul 4, 2023
2 parents 12c2ffb + f3c1c65 commit b89d4e8
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 115 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ This release includes:

- The `outputFolder` parameter for the `executeDqChecks` function is now REQUIRED and no longer has a default value. **This may be a breaking change for users who have not specified this parameter in their script to run DQD.**

### Removal of measurement plausibility checks

- Most plausibleValueLow and plausibleValueHigh measurement values were removed from the concept check threshold files, due to feedback from the community that many of these ranges included plausible values and as such were causing unexpected check failures. An initiative is planned to reinterrogate these ranges and add them back once the team has higher confidence that they will only flag legitimately implausible values

### Integrated testing was also added and the package was refactored on the backend

DataQualityDashboard 1.4.1
Expand Down
43 changes: 0 additions & 43 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,3 @@ remove_sql_comments <- function(sql) {
sql4 <- gsub("@@@@ .+? @@@@", " ", sql3, ) # remove multi-line comments
sql5 <- gsub("\\s+", " ", sql4) # remove multiple spaces
}

# dbms <- getOption("dbms", default = "sqlite")
# if (dbms == "sqlite") {
# connectionDetails <- Eunomia::getEunomiaConnectionDetails()
# cdmDatabaseSchema <- "main"
# resultsDatabaseSchema <- "main"
# cdmVersion <- 5
# }
# if (dbms == "postgresql") {
# DatabaseConnector::downloadJdbcDrivers("postgresql", pathToDriver = jdbcDriverFolder)
# connectionDetails <- createConnectionDetails(dbms = "postgresql",
# user = Sys.getenv("CDM5_POSTGRESQL_USER"),
# password = URLdecode(Sys.getenv("CDM5_POSTGRESQL_PASSWORD")),
# server = Sys.getenv("CDM5_POSTGRESQL_SERVER"),
# pathToDriver = jdbcDriverFolder)
#
# cdmDatabaseSchema <- Sys.getenv("CDM5_POSTGRESQL_CDM_SCHEMA")
# cdmVersion <- 5
# }
# if (dbms == "sql server") {
# DatabaseConnector::downloadJdbcDrivers("sql server", pathToDriver = jdbcDriverFolder)
# connectionDetails <- createConnectionDetails(dbms = "sql server",
# user = Sys.getenv("CDM5_SQL_SERVER_USER"),
# password = URLdecode(Sys.getenv("CDM5_SQL_SERVER_PASSWORD")),
# server = Sys.getenv("CDM5_SQL_SERVER_SERVER"),
# pathToDriver = jdbcDriverFolder)
# cdmDatabaseSchema <- Sys.getenv("CDM5_SQL_SERVER_CDM_SCHEMA")
# cdmVersion <- 5
# }
# if (dbms == "oracle") {
# DatabaseConnector::downloadJdbcDrivers("oracle", pathToDriver = jdbcDriverFolder)
# connectionDetails <- createConnectionDetails(dbms = "oracle",
# user = Sys.getenv("CDM5_ORACLE_USER"),
# password = URLdecode(Sys.getenv("CDM5_ORACLE_PASSWORD")),
# server = Sys.getenv("CDM5_ORACLE_SERVER"),
# pathToDriver = jdbcDriverFolder)
# cdmDatabaseSchema <- Sys.getenv("CDM5_ORACLE_CDM_SCHEMA")
#
# # Restore temp schema setting after tests complete
# oldTempSchema <- getOption("sqlRenderTempEmulationSchema")
# options("sqlRenderTempEmulationSchema" = Sys.getenv("CDM5_ORACLE_OHDSI_SCHEMA"))
# cdmVersion <- 5
# }
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
library(testthat)

test_that("listDqChecks works", {
checks <- listDqChecks()
expect_equal(length(checks), 4)
expect_true(all(sapply(checks, is.data.frame)))
})

test_that("Execute a single DQ check on Synthea/Eunomia", {
outputFolder <- tempfile("dqd_")
on.exit(unlink(outputFolder, recursive = TRUE))
Expand Down Expand Up @@ -43,7 +37,6 @@ test_that("Execute all TABLE checks on Synthea/Eunomia", {
expect_true(nrow(results$CheckResults) > 0)
})


test_that("Execute FIELD checks on Synthea/Eunomia", {
outputFolder <- tempfile("dqd_")
on.exit(unlink(outputFolder, recursive = TRUE))
Expand Down Expand Up @@ -185,44 +178,6 @@ test_that("Check invalid cdm version", {
)
})

test_that("Write JSON results", {
outputFolder <- tempfile("dqd_")
on.exit(unlink(outputFolder, recursive = TRUE))

expect_warning(
results <- executeDqChecks(
connectionDetails = connectionDetailsEunomia,
cdmDatabaseSchema = cdmDatabaseSchemaEunomia,
resultsDatabaseSchema = resultsDatabaseSchemaEunomia,
cdmSourceName = "Eunomia",
checkNames = "measurePersonCompleteness",
outputFolder = outputFolder,
writeToTable = FALSE
),
regexp = "^Missing check names.*"
)

jsonPath <- list.files(outputFolder, ".json", full.names = TRUE)
csvPath <- file.path(outputFolder, "results.csv")
writeJsonResultsToCsv(
jsonPath = jsonPath,
csvPath = csvPath
)
expect_true(file.exists(csvPath))

DataQualityDashboard::writeJsonResultsToTable(
connectionDetails = connectionDetailsEunomia,
resultsDatabaseSchema = resultsDatabaseSchemaEunomia,
jsonFilePath = jsonPath,
writeTableName = "dqd_results"
)
connection <- DatabaseConnector::connect(connectionDetailsEunomia)
on.exit(DatabaseConnector::disconnect(connection), add = TRUE)
tableNames <- DatabaseConnector::getTableNames(connection = connection, databaseSchema = resultsDatabaseSchemaEunomia)
expect_true("dqd_results" %in% tolower(tableNames))
DatabaseConnector::renderTranslateExecuteSql(connection, "DROP TABLE @database_schema.dqd_results;", database_schema = resultsDatabaseSchemaEunomia)
})

test_that("Execute DQ checks and write to table", {
outputFolder <- tempfile("dqd_")
on.exit(unlink(outputFolder, recursive = TRUE))
Expand All @@ -247,33 +202,6 @@ test_that("Execute DQ checks and write to table", {
DatabaseConnector::renderTranslateExecuteSql(connection, "DROP TABLE @database_schema.dqd_results;", database_schema = resultsDatabaseSchemaEunomia)
})

test_that("Execute reEvaluateThresholds on Synthea/Eunomia", {
outputFolder <- tempfile("dqd_")
on.exit(unlink(outputFolder, recursive = TRUE))

expect_warning(
results <- executeDqChecks(
connectionDetails = connectionDetailsEunomia,
cdmDatabaseSchema = cdmDatabaseSchemaEunomia,
resultsDatabaseSchema = resultsDatabaseSchemaEunomia,
cdmSourceName = "Eunomia",
checkNames = "measurePersonCompleteness",
outputFolder = outputFolder,
writeToTable = F
),
regexp = "^Missing check names.*"
)

jsonPath <- list.files(outputFolder, ".json", full.names = TRUE)

results2 <- reEvaluateThresholds(
jsonFilePath = jsonPath,
outputFolder = outputFolder,
outputFile = "reEvaluated.txt"
)
expect_is(results2, "list")
})

test_that("Execute DQ checks using sqlOnly=TRUE and sqlOnlyUnionCount=4 and sqlOnlyIncrementalInsert=TRUE", {
outputFolder <- tempfile("dqd_")
on.exit(unlink(outputFolder, recursive = TRUE))
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-listChecks.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
library(testthat)

test_that("listDqChecks works", {
checks <- listDqChecks()
expect_equal(length(checks), 4)
expect_true(all(sapply(checks, is.data.frame)))
})
28 changes: 28 additions & 0 deletions tests/testthat/test-reEvaluateThresholds.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
library(testthat)

test_that("Execute reEvaluateThresholds on Synthea/Eunomia", {
outputFolder <- tempfile("dqd_")
on.exit(unlink(outputFolder, recursive = TRUE))

expect_warning(
results <- executeDqChecks(
connectionDetails = connectionDetailsEunomia,
cdmDatabaseSchema = cdmDatabaseSchemaEunomia,
resultsDatabaseSchema = resultsDatabaseSchemaEunomia,
cdmSourceName = "Eunomia",
checkNames = "measurePersonCompleteness",
outputFolder = outputFolder,
writeToTable = F
),
regexp = "^Missing check names.*"
)

jsonPath <- list.files(outputFolder, ".json", full.names = TRUE)

results2 <- reEvaluateThresholds(
jsonFilePath = jsonPath,
outputFolder = outputFolder,
outputFile = "reEvaluated.txt"
)
expect_is(results2, "list")
})
39 changes: 39 additions & 0 deletions tests/testthat/test-writeJsonResultsTo.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
library(testthat)

test_that("Write JSON results", {
outputFolder <- tempfile("dqd_")
on.exit(unlink(outputFolder, recursive = TRUE))

expect_warning(
results <- executeDqChecks(
connectionDetails = connectionDetailsEunomia,
cdmDatabaseSchema = cdmDatabaseSchemaEunomia,
resultsDatabaseSchema = resultsDatabaseSchemaEunomia,
cdmSourceName = "Eunomia",
checkNames = "measurePersonCompleteness",
outputFolder = outputFolder,
writeToTable = FALSE
),
regexp = "^Missing check names.*"
)

jsonPath <- list.files(outputFolder, ".json", full.names = TRUE)
csvPath <- file.path(outputFolder, "results.csv")
writeJsonResultsToCsv(
jsonPath = jsonPath,
csvPath = csvPath
)
expect_true(file.exists(csvPath))

DataQualityDashboard::writeJsonResultsToTable(
connectionDetails = connectionDetailsEunomia,
resultsDatabaseSchema = resultsDatabaseSchemaEunomia,
jsonFilePath = jsonPath,
writeTableName = "dqd_results"
)
connection <- DatabaseConnector::connect(connectionDetailsEunomia)
on.exit(DatabaseConnector::disconnect(connection), add = TRUE)
tableNames <- DatabaseConnector::getTableNames(connection = connection, databaseSchema = resultsDatabaseSchemaEunomia)
expect_true("dqd_results" %in% tolower(tableNames))
DatabaseConnector::renderTranslateExecuteSql(connection, "DROP TABLE @database_schema.dqd_results;", database_schema = resultsDatabaseSchemaEunomia)
})

0 comments on commit b89d4e8

Please sign in to comment.