Skip to content

Commit 4d9ab80

Browse files
committed
[annotation] Integration test of base+delta generation.
1 parent a8d7ec1 commit 4d9ab80

2 files changed

Lines changed: 61 additions & 3 deletions

File tree

R/review_structures.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,10 @@ RS_append <- function(path, contents){
502502
close(f)
503503
}
504504

505-
# NOTE: The contents of the following conditional are a WIP of the annotation feature.
506-
# They are parked until user requirements and technical blockers are clarified.
507-
# TODO? Repurpose as test/performance test/"live documentation"
505+
# NOTE: The contents of the following conditional are a WIP of the review feature.
506+
# They may be useful for performance testing, but maybe a higher-level approach,
507+
# such as that on `tests/testthat/test-review.R`, is enough and we don't need
508+
# to call the `RS_*` functions directly.
508509
if(FALSE){
509510
describe_and_time <- function(description, expr){
510511
t0 <- Sys.time()

tests/testthat/test-review.R

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
local({
2+
folder_contents <- NULL
3+
fs_callbacks <- list(
4+
attach = function(arg) NULL, list = function(arg) NULL, read = function(arg) NULL, write = function(arg) NULL,
5+
append = function(arg) NULL, execute_IO_plan = function(arg) NULL,
6+
read_folder = function(arg) folder_contents <<- arg
7+
)
8+
9+
store_path <- file.path(tempdir(), "data_checks")
10+
dir.create(store_path)
11+
on.exit(unlink(store_path, recursive = TRUE), add = TRUE, after = FALSE)
12+
13+
fs_client <- fs_init(callbacks = fs_callbacks, store_path)
14+
fs_client[["read_folder"]](subfolder_candidates = "dataset_list")
15+
16+
# Review folder contents is initialized here
17+
review = list(
18+
datasets = list(
19+
ae = list(
20+
id_vars = c("USUBJID", "AESEQ"),
21+
tracked_vars = c(
22+
"AESEV", "AETERM", "AEHLGT", "AEHLT", "AELLT",
23+
"AEDECOD", "AESOC", "AESTDTC", "AEENDTC", "AESTDY","AEOUT", "AEACN", "AEREL"
24+
)
25+
)
26+
),
27+
choices = c("choiceA", "choiceB"),
28+
roles = c("roleA", "roleB")
29+
)
30+
31+
dataset_lists <- list(
32+
dataset_list = list(
33+
ae = safetyData::sdtm_ae[1:2,]
34+
)
35+
)
36+
37+
info <- REV_load_annotation_info(folder_contents, review, dataset_lists)
38+
expect_length(info[["error"]], 0)
39+
fs_client[["execute_IO_plan"]](IO_plan = info[["folder_IO_plan"]], is_init = TRUE)
40+
fs_client[["read_folder"]](subfolder_candidates = "dataset_list")
41+
42+
test_that("Detect modification of previously known row and output new delta file", {
43+
dataset_lists2 <- dataset_lists
44+
dataset_lists2[["dataset_list"]][["ae"]][["AESEV"]][[1]] <- "SEVERE"
45+
46+
info <- REV_load_annotation_info(folder_contents, review, dataset_lists2)
47+
expect_length(info[["error"]], 0)
48+
expect_length(info[["folder_IO_plan"]], 1)
49+
folder_op <- info[["folder_IO_plan"]][[1]]
50+
expect_equal(folder_op[["type"]], "write_file")
51+
expect_equal(folder_op[["fname"]], "ae_001.delta")
52+
53+
delta <- RS_parse_delta(info[["folder_IO_plan"]][[1]][["contents"]], 13)
54+
55+
expect_equal(delta[["modified_row_indices"]], c(1L))
56+
})
57+
})

0 commit comments

Comments
 (0)