-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for import spectra target factory
inspired by examples in ropensci/jagstargets
- Loading branch information
Showing
3 changed files
with
122 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,65 @@ | ||
# WARNING - Generated by {fusen} from dev/maldipickr-workflow-with-targets.Rmd: do not edit by hand | ||
|
||
# Tests for targets factory borrowed from | ||
# src: https://github.com/ropensci/jagstargets/blob/2bad8b2958d0252a5993d341d38f8d9d02aeb41a/tests/testthat/test-tar_jags_rep_dic.R | ||
test_that("tar_import_and_process_spectra works", { | ||
expect_true(inherits(tar_import_and_process_spectra, "function")) | ||
skip_if_not_installed("targets") | ||
skip_if_not_installed("tarchetypes") | ||
skip_on_cran() | ||
targets::tar_dir({ # tar_dir() runs code from a temporary directory. | ||
targets::tar_script({ | ||
library(maldipickr) | ||
list( | ||
tar_import_and_process_spectra( | ||
name = "anaerobe", | ||
raw_spectra_directories = system.file( | ||
"toy-species-spectra", | ||
package = "maldipickr"), | ||
tolerance = 1 | ||
) | ||
)},ask = FALSE) | ||
# Enough targets are created. | ||
out <- targets::tar_manifest(callr_function = NULL) | ||
expect_equal(nrow(out), 7L) | ||
# Nodes in the graph are connected properly. | ||
out <- targets::tar_network(callr_function = NULL, targets_only = TRUE)$edges | ||
out <- dplyr::arrange(out, from, to) | ||
rownames(out) <- NULL | ||
exp <- tibble::tribble( | ||
~from, ~to, | ||
"anaerobe_checks", "anaerobe_spectra_stats", | ||
"anaerobe_checks", "anaerobe_valid_spectra", | ||
"anaerobe_plates", "anaerobe_spectra_raw", | ||
"anaerobe_plates", "anaerobe_spectra_stats", | ||
"anaerobe_plates_files", "anaerobe_plates", | ||
"anaerobe_spectra_raw", "anaerobe_checks", | ||
"anaerobe_spectra_raw", "anaerobe_valid_spectra", | ||
"anaerobe_valid_spectra", "anaerobe_processed" | ||
) | ||
exp <- dplyr::arrange(exp, from, to) | ||
rownames(exp) <- NULL | ||
expect_equal(out, exp) | ||
# The pipeline produces correctly formatted output. | ||
capture.output(suppressWarnings(targets::tar_make(callr_function = NULL))) | ||
expect_equal( nrow( | ||
targets::tar_read(anaerobe_processed)[[1]][["metadata"]] | ||
), 6L ) | ||
}) | ||
}) | ||
test_that("tar_import_and_process_spectra fails on wrong input", { | ||
skip_if_not_installed("targets") | ||
skip_if_not_installed("tarchetypes") | ||
skip_on_cran() | ||
targets::tar_dir({ # tar_dir() runs code from a temporary directory. | ||
targets::tar_script({ | ||
library(maldipickr) | ||
list( | ||
tar_import_and_process_spectra( | ||
name = "anaerobe", | ||
raw_spectra_directories = "data_directory_that_should_not_exist", | ||
tolerance = 1 | ||
) | ||
)},ask = FALSE) | ||
expect_error(tar_make(), class = "tar_condition_validate") | ||
}) | ||
}) |