Skip to content

Commit e09fd7f

Browse files
committed
test: clean up epix_fill_through_version
1 parent d479882 commit e09fd7f

File tree

1 file changed

+7
-26
lines changed

1 file changed

+7
-26
lines changed

tests/testthat/test-epix_fill_through_version.R

+7-26
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,7 @@ test_that("epix_fill_through_version mirrors input when it is sufficiently up to
77
ea_trivial_fill_na1 <- epix_fill_through_version(ea_orig, some_earlier_observed_version, "na")
88
ea_trivial_fill_na2 <- epix_fill_through_version(ea_orig, ea_orig$versions_end, "na")
99
ea_trivial_fill_locf <- epix_fill_through_version(ea_orig, some_earlier_observed_version, "locf")
10-
# Below, we want R6 objects to be compared based on contents rather than
11-
# addresses. We appear to get this with `expect_identical` in `testthat`
12-
# edition 3, which is based on `waldo::compare` rather than `base::identical`;
13-
# `waldo::compare` in waldo >=0.3.1 appears (as of 0.4.0) to compare R6
14-
# objects by contents rather than address (in a way that is tested but maybe
15-
# not guaranteed via user docs). Use `testthat::local_edition` to ensure we
16-
# use testthat edition 3 here (use `testthat::` to prevent ambiguity with
17-
# `readr`).
18-
testthat::local_edition(3)
10+
1911
expect_identical(ea_orig, ea_trivial_fill_na1)
2012
expect_identical(ea_orig, ea_trivial_fill_na2)
2113
expect_identical(ea_orig, ea_trivial_fill_locf)
@@ -33,9 +25,6 @@ test_that("epix_fill_through_version can extend observed versions, gives expecte
3325
ea_fill_na <- epix_fill_through_version(ea_orig, later_unobserved_version, "na")
3426
ea_fill_locf <- epix_fill_through_version(ea_orig, later_unobserved_version, "locf")
3527

36-
# We use testthat edition 3 features here, passing `ignore_attr` to
37-
# `waldo::compare`. Ensure we are using edition 3:
38-
testthat::local_edition(3)
3928
withCallingHandlers(
4029
{
4130
expect_identical(ea_fill_na$versions_end, later_unobserved_version)
@@ -69,23 +58,16 @@ test_that("epix_fill_through_version does not mutate x", {
6958
# doesn't seem sufficient to trigger)
7059
as_epi_archive(tibble::tibble(geo_value = 1L, time_value = 1L, version = 1L, value = 10L))
7160
)) {
72-
# We want to perform a strict comparison of the contents of `ea_orig` before
73-
# and `ea_orig` after. `copy` + `expect_identical` based on waldo would
74-
# sort of work, but we might want something stricter. `as.list` +
75-
# `identical` plus a check of the DT seems to do the trick.
76-
ea_orig_before_as_list <- as.list(ea_orig)
61+
ea_orig_before <- clone(ea_orig)
7762
ea_orig_dt_before_copy <- data.table::copy(ea_orig$DT)
7863
some_unobserved_version <- 8L
79-
#
64+
8065
ea_fill_na <- epix_fill_through_version(ea_orig, some_unobserved_version, "na")
81-
ea_orig_after_as_list <- as.list(ea_orig)
82-
# use identical, not expect_identical, for the R6-as-list test; latter isn't as strict
83-
expect_true(identical(ea_orig_before_as_list, ea_orig_after_as_list))
66+
expect_identical(ea_orig_before, ea_orig)
8467
expect_identical(ea_orig_dt_before_copy, ea_orig$DT)
85-
#
68+
8669
ea_fill_locf <- epix_fill_through_version(ea_orig, some_unobserved_version, "locf")
87-
ea_orig_after_as_list <- as.list(ea_orig)
88-
expect_true(identical(ea_orig_before_as_list, ea_orig_after_as_list))
70+
expect_identical(ea_orig_before, ea_orig)
8971
expect_identical(ea_orig_dt_before_copy, ea_orig$DT)
9072
}
9173
})
@@ -101,8 +83,7 @@ test_that("epix_fill_through_version return with expected visibility", {
10183

10284
test_that("epix_fill_through_version returns same key & doesn't mutate old DT or its key", {
10385
ea <- as_epi_archive(tibble::tibble(geo_value = 1L, time_value = 1L, version = 1L, value = 10L))
104-
old_dt <- ea$DT
105-
old_dt_copy <- data.table::copy(old_dt)
86+
old_dt_copy <- data.table::copy(ea$DT)
10687
old_key <- data.table::key(ea$DT)
10788
expect_identical(data.table::key(epix_fill_through_version(ea, 5L, "na")$DT), old_key)
10889
expect_identical(data.table::key(epix_fill_through_version(ea, 5L, "locf")$DT), old_key)

0 commit comments

Comments
 (0)