Skip to content

Commit

Permalink
add snapshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gravesti committed Jul 18, 2024
1 parent b6089e2 commit b284e71
Show file tree
Hide file tree
Showing 6 changed files with 3,864 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ repos:
.*\.rds|
.*\.Rds|
.*\.sh|
.*\.RData
.*\.RData|
.*\.svg
)$
- id: lintr
- id: readme-rmd-rendered
Expand Down
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Suggests:
sandwich,
survminer,
flexsurv,
tibble
tibble,
vdiffr
VignetteBuilder:
knitr
biocViews:
Expand Down
1,772 changes: 1,772 additions & 0 deletions tests/testthat/_snaps/plot_km/kmplot2-all.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
991 changes: 991 additions & 0 deletions tests/testthat/_snaps/plot_km/kmplot2-by-am.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
991 changes: 991 additions & 0 deletions tests/testthat/_snaps/plot_km/kmplot2-by-trial.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 106 additions & 0 deletions tests/testthat/test-plot_km.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,109 @@ test_that("ph_diagplot_schoenfeld works without error", {
)
expect_equal(original_par, par())
})

test_that("ph_diagplot_lch works without error", {
original_par <- par()
load(system.file("extdata", "combined_data_tte.rda", package = "maicplus", mustWork = TRUE))
kmobj <- survfit(Surv(TIME, EVENT) ~ ARM, combined_data_tte, conf.type = "log-log")
ph_diagplot_lch(kmobj,
time_scale = "month", log_time = TRUE,

Check warning on line 31 in tests/testthat/test-plot_km.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=tests/testthat/test-plot_km.R,line=31,col=18,[indentation_linter] Indentation should be 4 spaces but is 18 spaces.
endpoint_name = "OS", subtitle = "(Before Matching)"
)

expect_equal(original_par, par())
})

test_that("ph_diagplot_schoenfeld works without error", {
original_par <- par()
load(system.file("extdata", "combined_data_tte.rda", package = "maicplus", mustWork = TRUE))
unweighted_cox <- coxph(Surv(TIME, EVENT == 1) ~ ARM, data = combined_data_tte)
expect_no_error(
ph_diagplot_schoenfeld(unweighted_cox,
time_scale = "month", log_time = TRUE,

Check warning on line 44 in tests/testthat/test-plot_km.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=tests/testthat/test-plot_km.R,line=44,col=27,[indentation_linter] Indentation should be 6 spaces but is 27 spaces.
endpoint_name = "OS", subtitle = "(Before Matching)"
)
)
expect_equal(original_par, par())
})

test_that("kmplot2 works", {
skip_if_not_installed("vdiffr")

data(weighted_twt)
data(adtte_twt)
data(pseudo_ipd_twt)

# plot by trial
expect_warning(
vdiffr::expect_doppelganger(
title = "kmplot2_by_trial",
fig = function() {
kmplot2(
weights_object = weighted_twt,
tte_ipd = adtte_twt,
tte_pseudo_ipd = pseudo_ipd_twt,
trt_ipd = "A",
trt_agd = "B",
trt_common = "C",
trt_var_ipd = "ARM",
trt_var_agd = "ARM",
endpoint_name = "Overall Survival",
km_conf_type = "log-log",
km_layout = "by_trial",
time_scale = "month",
break_x_by = 2
)
}
),
"select_"
)



# plot by arm
vdiffr::expect_doppelganger(
title = "kmplot2_by_am",
fig = function() {
kmplot2(
weights_object = weighted_twt,
tte_ipd = adtte_twt,
tte_pseudo_ipd = pseudo_ipd_twt,
trt_ipd = "A",
trt_agd = "B",
trt_common = "C",
trt_var_ipd = "ARM",
trt_var_agd = "ARM",
endpoint_name = "Overall Survival",
km_conf_type = "log-log",
km_layout = "by_arm",
time_scale = "month",
break_x_by = 2
)
}
)

# plot all
vdiffr::expect_doppelganger(
title = "kmplot2_all",
fig = function() {
kmplot2(
weights_object = weighted_twt,
tte_ipd = adtte_twt,
tte_pseudo_ipd = pseudo_ipd_twt,
trt_ipd = "A",
trt_agd = "B",
trt_common = "C",
trt_var_ipd = "ARM",
trt_var_agd = "ARM",
endpoint_name = "Overall Survival",
km_conf_type = "log-log",
km_layout = "all",
time_scale = "month",
break_x_by = 2,
xlim = c(0, 20),
show_risk_set = FALSE
)
}
)
})

0 comments on commit b284e71

Please sign in to comment.