Skip to content

Commit

Permalink
add withr package
Browse files Browse the repository at this point in the history
  • Loading branch information
RayStick committed Dec 16, 2024
1 parent 9906266 commit 639a2b9
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 12 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Suggests:
knitr,
mockery,
rmarkdown,
testthat (>= 3.0.0)
testthat (>= 3.0.0),
withr
VignetteBuilder:
knitr
Config/testthat/edition: 3
Expand Down
1 change: 1 addition & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ library(utils)
library(tidyr)
library(gridExtra)
library(dplyr)
library(withr)

test_check("browseMetadata")
4 changes: 2 additions & 2 deletions tests/testthat/test-browse_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

test_that("browse_metadata function outputs files correctly", {
# Setup
temp_dir <- withr::local_tempdir()
temp_dir <- local_tempdir()
example_json_file <- system.file("inputs/national_community_child_health_database_(ncchd)_20240405T130125.json", package = "browseMetadata")

# Execution
Expand All @@ -26,4 +26,4 @@ test_that("browse_metadata function outputs files correctly", {
expect_equal(nrow(bar_csv), 26)
expect_equal(ncol(bar_csv),3)
expect_equal(sum(bar_csv$N_Variables),318)
})
})
4 changes: 2 additions & 2 deletions tests/testthat/test-copy_previous.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# libraries: testthat, mockery, utils
# libraries: testthat, mockery, utils, withr

test_that("copy_previous works correctly when there are files to copy from", {
# Create a temporary directory
temp_dir <- withr::local_tempdir()
temp_dir <- local_tempdir()

# Create test CSV files
# Criteria for test files: one must have 'AUTO CATEGORISED' as Note, overlap in DataElements across files, different timestamps across files)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-map_metadata.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# libraries: testthat, mockery
# libraries: testthat, mockery, withr

test_that("map_metadata function works correctly with user input", {
# Setup
temp_dir <- withr::local_tempdir()
temp_dir <- local_tempdir()

demo_log_output <- system.file("outputs/LOG_NationalCommunityChildHealthDatabase(NCCHD)_CHILD_2024-11-27-14-19-55.csv", package = "browseMetadata")
demo_output <- system.file("outputs/OUTPUT_NationalCommunityChildHealthDatabase(NCCHD)_CHILD_2024-11-27-14-19-55.csv", package = "browseMetadata")
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-map_metadata_compare.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# libraries: testthat, mockery
# libraries: testthat, mockery, withr

test_that("map_metadata function works correctly with user input", {
# Setup
temp_dir <- withr::local_tempdir()
temp_dir <- local_tempdir()

demo_session_dir <- system.file("outputs", package = "browseMetadata")
demo_session1_base <- "NationalCommunityChildHealthDatabase(NCCHD)_CHILD_2024-11-27-14-19-55"
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-map_metadata_convert.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# libraries: testthat
# libraries: testthat, withr

test_that("map_metadata_convert function outputs files correctly", {
# Setup
temp_dir <- withr::local_tempdir()
temp_dir <- local_tempdir()
file_in <- system.file("outputs/OUTPUT_NationalCommunityChildHealthDatabase(NCCHD)_CHILD_2024-11-27-14-19-55.csv", package = "browseMetadata")
file_out <- system.file("outputs/L-OUTPUT_NationalCommunityChildHealthDatabase(NCCHD)_CHILD_2024-11-27-14-19-55.csv", package = "browseMetadata")

Expand All @@ -18,4 +18,4 @@ test_that("map_metadata_convert function outputs files correctly", {

# Test that the outputs are the same
expect_equal(actual_output, expected_output)
})
})

0 comments on commit 639a2b9

Please sign in to comment.