Skip to content

Commit

Permalink
Fix build tests (#63)
Browse files Browse the repository at this point in the history
* Update variables to pass tests

* Update indiv number of variables

* Change exists tests to read

* Set an environment var to make testthat use multiple CPUs

---------

Co-authored-by: James McMahon <[email protected]>
  • Loading branch information
Jennit07 and Moohan authored Dec 12, 2023
1 parent e29241e commit a69a61c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 35 deletions.
1 change: 1 addition & 0 deletions .Renviron
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TESTTHAT_CPUS = 12
26 changes: 0 additions & 26 deletions tests/testthat/test-files_exist.R

This file was deleted.

28 changes: 28 additions & 0 deletions tests/testthat/test-files_readable.R
Original file line number Diff line number Diff line change
@@ -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"))
})
8 changes: 4 additions & 4 deletions tests/testthat/test-multiple_selections.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-multiple_years.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-partnership_selection.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ 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)

# We shouldn't have the partnership variable
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)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-read_slf_individual.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})

Expand Down

0 comments on commit a69a61c

Please sign in to comment.