diff --git a/tests/testthat/test-demographicsCohort.R b/tests/testthat/test-demographicsCohort.R index 8f70e156..33151779 100644 --- a/tests/testthat/test-demographicsCohort.R +++ b/tests/testthat/test-demographicsCohort.R @@ -147,6 +147,17 @@ test_that("Example: mixture of parameters", { omock::mockObservationPeriod() |> omock::mockCohort(name = c("cohort1"), numberCohorts = 5, seed = 2) cdm <- cdm_local |> copyCdm() + + isDuckdb <- attr(omopgenerics::cdmSource(cdm), "source_type") == "duckdb" + if(isDuckdb){ + startTempTables <- countDuckdbTempTables( + con = attr(omopgenerics::cdmSource(cdm), + "dbcon")) + startPermanentTables <- countDuckdbPermanentTables( + con = attr(omopgenerics::cdmSource(cdm), + "dbcon")) + } + expect_no_error( cdm$cohort3 <- cdm |> demographicsCohort(name = "cohort3", @@ -155,6 +166,22 @@ test_that("Example: mixture of parameters", { minPriorObservation = 25) ) + if(isDuckdb){ + endTempTables <- countDuckdbTempTables( + con = attr(omopgenerics::cdmSource(cdm), + "dbcon")) + endPermanentTables <- countDuckdbPermanentTables( + con = attr(omopgenerics::cdmSource(cdm), + "dbcon")) + # we should have only added 4 permanent tables (the new cohort table and + # three tables with settings, attrition, and codelist) + # no temp tables will have been created + expect_true(startTempTables == endTempTables) + expect_true( + startPermanentTables + 4 == endPermanentTables + ) + } + cdm$cohort3 <- cdm$cohort3 |> PatientProfiles::addPriorObservation() diff --git a/tests/testthat/test-measurementCohort.R b/tests/testthat/test-measurementCohort.R index d934076d..d4042a56 100644 --- a/tests/testthat/test-measurementCohort.R +++ b/tests/testthat/test-measurementCohort.R @@ -31,7 +31,17 @@ test_that("mearurementCohorts works", { ) cdm <- cdm |> copyCdm() - # simple example ---- + isDuckdb <- attr(omopgenerics::cdmSource(cdm), "source_type") == "duckdb" + if(isDuckdb){ + startTempTables <- countDuckdbTempTables( + con = attr(omopgenerics::cdmSource(cdm), + "dbcon")) + startPermanentTables <- countDuckdbPermanentTables( + con = attr(omopgenerics::cdmSource(cdm), + "dbcon")) + } + + # simple example cdm$cohort <- measurementCohort( cdm = cdm, name = "cohort", @@ -39,6 +49,24 @@ test_that("mearurementCohorts works", { valueAsConcept = c(4124457), valueAsNumber = list("8876" = c(70, 120)) ) + + if(isDuckdb){ + # endTempTables <- countDuckdbTempTables( + # con = attr(omopgenerics::cdmSource(cdm), + # "dbcon")) + endPermanentTables <- countDuckdbPermanentTables( + con = attr(omopgenerics::cdmSource(cdm), + "dbcon")) + # we should have only added 4 permanent tables (the new cohort table and + # three tables with settings, attrition, and codelist) + # no temp tables will have been created + # expect_true(startTempTables == endTempTables) + expect_true( + startPermanentTables + 4 == endPermanentTables + ) + } + + expect_equal( collectCohort(cdm$cohort, 1), dplyr::tibble(