From bff37019a371179cb2c5b780f0fc61ef26675e86 Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Tue, 25 Jul 2023 15:18:48 +0100 Subject: [PATCH 1/4] Update variables to pass tests --- tests/testthat/test-multiple_selections.R | 8 ++++---- tests/testthat/test-multiple_years.R | 4 ++-- tests/testthat/test-partnership_selection.R | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/testthat/test-multiple_selections.R b/tests/testthat/test-multiple_selections.R index d4952d4..746a9b2 100644 --- a/tests/testthat/test-multiple_selections.R +++ b/tests/testthat/test-multiple_selections.R @@ -5,27 +5,27 @@ test_that("select years and recid", { set.seed(50) acute_only <- read_slf_episode(c("1718", "1819"), - col_select = c("year", "anon_chi", "recid", "keydate1_dateformat"), + col_select = c("year", "anon_chi", "recid", "record_keydate1"), recids = "01B" ) %>% dplyr::slice_sample(n = 200000) expect_equal( names(acute_only), - c("year", "anon_chi", "recid", "keydate1_dateformat") + c("year", "anon_chi", "recid", "record_keydate1") ) expect_equal(unique(acute_only$year), c("1718", "1819")) expect_equal(unique(acute_only$recid), "01B") hosp_only <- read_slf_episode(c("1718", "1819"), - col_select = c("year", "anon_chi", "recid", "keydate1_dateformat"), + col_select = c("year", "anon_chi", "recid", "record_keydate1"), recids = c("01B", "02B", "04B", "GLS") ) %>% dplyr::slice_sample(n = 200000) expect_equal( names(hosp_only), - c("year", "anon_chi", "recid", "keydate1_dateformat") + c("year", "anon_chi", "recid", "record_keydate1") ) expect_equal(unique(hosp_only$year), c("1718", "1819")) expect_equal(sort(unique(hosp_only$recid)), c("01B", "02B", "04B", "GLS")) diff --git a/tests/testthat/test-multiple_years.R b/tests/testthat/test-multiple_years.R index f2aaece..03806b2 100644 --- a/tests/testthat/test-multiple_years.R +++ b/tests/testthat/test-multiple_years.R @@ -8,7 +8,7 @@ test_that("read multiple years works for individual file", { indiv <- read_slf_individual(c("1718", "1819"), col_select = c("year", "anon_chi") ) %>% - dplyr::slice_sample(n = 50) + dplyr::slice_sample(n = 100) # Test for anything odd expect_s3_class(indiv, "tbl_df") @@ -34,7 +34,7 @@ test_that("read multiple years works for episode file", { ep <- read_slf_episode(c("1718", "1819"), col_select = c("year", "anon_chi") ) %>% - dplyr::slice_sample(n = 50) + dplyr::slice_sample(n = 100) # Test for anything odd expect_s3_class(ep, "tbl_df") diff --git a/tests/testthat/test-partnership_selection.R b/tests/testthat/test-partnership_selection.R index 27ff274..9a24372 100644 --- a/tests/testthat/test-partnership_selection.R +++ b/tests/testthat/test-partnership_selection.R @@ -45,7 +45,7 @@ test_that("Can still do filtering if variable is not selected", { # Don't choose to read the partnership variable indiv_1718_edinburgh <- read_slf_individual("1718", partnerships = "S37000012", - col_select = c("hri_scot") + col_select = c("anon_chi") ) %>% dplyr::slice_sample(n = 1000) @@ -53,7 +53,7 @@ test_that("Can still do filtering if variable is not selected", { expect_false("hscp2018" %in% names(indiv_1718_edinburgh)) # Should still have the variables we picked - expect_true("hri_scot" %in% names(indiv_1718_edinburgh)) + expect_true("anon_chi" %in% names(indiv_1718_edinburgh)) # Should have at least 100 records (checks we're not getting an empty file) expect_gte(nrow(indiv_1718_edinburgh), 100) From 2609f12c97762c81754355b4ce080590fb51ca90 Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Tue, 25 Jul 2023 15:56:11 +0100 Subject: [PATCH 2/4] Update indiv number of variables --- tests/testthat/test-read_slf_individual.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-read_slf_individual.R b/tests/testthat/test-read_slf_individual.R index eb6305f..38546f9 100644 --- a/tests/testthat/test-read_slf_individual.R +++ b/tests/testthat/test-read_slf_individual.R @@ -16,7 +16,7 @@ test_that("Reads individual file correctly", { expect_equal(nrow(indiv_file), 100) # Test for correct number of variables (will need updating) - expect_length(indiv_file, 184) + expect_length(indiv_file, 180) } }) From 43acbfb79129f91c3fe95388e3e1269d1f86ccb5 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Wed, 26 Jul 2023 12:01:48 +0100 Subject: [PATCH 3/4] Change exists tests to read --- tests/testthat/test-files_exist.R | 26 -------------------------- tests/testthat/test-files_readable.R | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 26 deletions(-) delete mode 100644 tests/testthat/test-files_exist.R create mode 100644 tests/testthat/test-files_readable.R diff --git a/tests/testthat/test-files_exist.R b/tests/testthat/test-files_exist.R deleted file mode 100644 index 53515a7..0000000 --- a/tests/testthat/test-files_exist.R +++ /dev/null @@ -1,26 +0,0 @@ -skip_on_ci() - - -test_that("Episode files exist", { - # Episode files - expect_true(fs::file_exists(gen_file_path("1415", "episode", ext = "parquet"))) - expect_true(fs::file_exists(gen_file_path("1516", "episode", ext = "parquet"))) - expect_true(fs::file_exists(gen_file_path("1617", "episode", ext = "parquet"))) - expect_true(fs::file_exists(gen_file_path("1718", "episode", ext = "parquet"))) - expect_true(fs::file_exists(gen_file_path("1819", "episode", ext = "parquet"))) - expect_true(fs::file_exists(gen_file_path("1920", "episode", ext = "parquet"))) - expect_true(fs::file_exists(gen_file_path("2021", "episode", ext = "parquet"))) - expect_true(fs::file_exists(gen_file_path("2122", "episode", ext = "parquet"))) -}) - - -test_that("Individual files exist", { - expect_true(fs::file_exists(gen_file_path("1415", "individual", ext = "parquet"))) - expect_true(fs::file_exists(gen_file_path("1516", "individual", ext = "parquet"))) - expect_true(fs::file_exists(gen_file_path("1617", "individual", ext = "parquet"))) - expect_true(fs::file_exists(gen_file_path("1718", "individual", ext = "parquet"))) - expect_true(fs::file_exists(gen_file_path("1819", "individual", ext = "parquet"))) - expect_true(fs::file_exists(gen_file_path("1920", "individual", ext = "parquet"))) - expect_true(fs::file_exists(gen_file_path("2021", "individual", ext = "parquet"))) - expect_true(fs::file_exists(gen_file_path("2122", "individual", ext = "parquet"))) -}) diff --git a/tests/testthat/test-files_readable.R b/tests/testthat/test-files_readable.R new file mode 100644 index 0000000..8b4dc13 --- /dev/null +++ b/tests/testthat/test-files_readable.R @@ -0,0 +1,28 @@ +skip_on_ci() + + +test_that("Episode files are readable", { + # Episode files + expect_true(fs::file_access(gen_file_path("1415", "episode"), mode = "read")) + expect_true(fs::file_access(gen_file_path("1516", "episode"), mode = "read")) + expect_true(fs::file_access(gen_file_path("1617", "episode"), mode = "read")) + expect_true(fs::file_access(gen_file_path("1718", "episode"), mode = "read")) + expect_true(fs::file_access(gen_file_path("1819", "episode"), mode = "read")) + expect_true(fs::file_access(gen_file_path("1920", "episode"), mode = "read")) + expect_true(fs::file_access(gen_file_path("2021", "episode"), mode = "read")) + expect_true(fs::file_access(gen_file_path("2122", "episode"), mode = "read")) + expect_true(fs::file_access(gen_file_path("2223", "episode"), mode = "read")) +}) + + +test_that("Individual files are readable", { + expect_true(fs::file_access(gen_file_path("1415", "individual"), mode = "read")) + expect_true(fs::file_access(gen_file_path("1516", "individual"), mode = "read")) + expect_true(fs::file_access(gen_file_path("1617", "individual"), mode = "read")) + expect_true(fs::file_access(gen_file_path("1718", "individual"), mode = "read")) + expect_true(fs::file_access(gen_file_path("1819", "individual"), mode = "read")) + expect_true(fs::file_access(gen_file_path("1920", "individual"), mode = "read")) + expect_true(fs::file_access(gen_file_path("2021", "individual"), mode = "read")) + expect_true(fs::file_access(gen_file_path("2122", "individual"), mode = "read")) + expect_true(fs::file_access(gen_file_path("2223", "individual"), mode = "read")) +}) From 90ca40571a8206f9a1b982e8da87465eb89c185f Mon Sep 17 00:00:00 2001 From: James McMahon Date: Thu, 27 Jul 2023 14:40:50 +0100 Subject: [PATCH 4/4] Set an environment var to make testthat use multiple CPUs --- .Renviron | 1 + 1 file changed, 1 insertion(+) create mode 100644 .Renviron diff --git a/.Renviron b/.Renviron new file mode 100644 index 0000000..a3a718d --- /dev/null +++ b/.Renviron @@ -0,0 +1 @@ +TESTTHAT_CPUS = 12