mirror of
https://github.com/msberends/AMR.git
synced 2026-11-16 00:10:57 +01:00
(v3.0.1.9135) Fix get_mo_source() removing the mo_source file at the default location, returning the wrong mo_source, and throwing an error after the original file was moved, and run the unit tests in CI also in a real interactive session and with a user setup, a Dutch locale, and CLSI as default guideline, with tests that no longer assume an English locale or EUCAST
This commit is contained in:
1 parent
4be7352843
commit
8b01bcb23c
16 files changed
+360
-38
No files matched your search
@@ -0,0 +1,50 @@
|
||||
# ==================================================================== #
|
||||
# TITLE: #
|
||||
# AMR: An R Package for Working with Antimicrobial Resistance Data #
|
||||
# #
|
||||
# SOURCE CODE: #
|
||||
# https://github.com/msberends/AMR #
|
||||
# #
|
||||
# PLEASE CITE THIS SOFTWARE AS: #
|
||||
# Berends MS, Luz CF, Friedrich AW, et al. (2022). #
|
||||
# AMR: An R Package for Working with Antimicrobial Resistance Data. #
|
||||
# Journal of Statistical Software, 104(3), 1-31. #
|
||||
# https://doi.org/10.18637/jss.v104.i03 #
|
||||
# #
|
||||
# Developed at the University of Groningen and the University Medical #
|
||||
# Center Groningen in the Netherlands, in collaboration with many #
|
||||
# colleagues from around the world, see our website. #
|
||||
# #
|
||||
# This R package is free software; you can freely use and distribute #
|
||||
# it for both personal and commercial purposes under the terms of the #
|
||||
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
|
||||
# the Free Software Foundation. #
|
||||
# We created this package for both routine data analysis and academic #
|
||||
# research and it was publicly released in the hope that it will be #
|
||||
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
|
||||
# #
|
||||
# Visit our website for the full manual and a complete tutorial about #
|
||||
# how to conduct AMR data analysis: https://amr-for-r.org #
|
||||
# ==================================================================== #
|
||||
|
||||
# Runs all unit tests from source, see run_tests.sh. Quits with status 1 on any failure or error, and with status 2 if the tests could not be run at all.
|
||||
# Every top-level error must end in quit(), since an interactive session would otherwise continue reading "1" from stdin.
|
||||
|
||||
status <- tryCatch(
|
||||
{
|
||||
if (identical(Sys.getenv("AMR_TEST_INTERACTIVE"), "true") && !interactive()) {
|
||||
stop("AMR_TEST_INTERACTIVE is set, but this R session is not interactive")
|
||||
}
|
||||
cat("Interactive:", interactive(), "| LANG:", Sys.getenv("LANG"), "| AMR options:", paste(names(options())[grepl("^AMR_", names(options()))], collapse = ", "), "\n")
|
||||
# report all failures, not only the first 10
|
||||
options(warn = 1, testthat.summary.max_reports = Inf, testthat.progress.max_fails = Inf)
|
||||
res <- as.data.frame(testthat::test_local(Sys.getenv("AMR_TEST_PKG_DIR", "."), reporter = "summary", stop_on_failure = FALSE))
|
||||
cat("\nFiles:", length(unique(res$file)), "| failed:", sum(res$failed), "| errors:", sum(res$error), "| skipped:", sum(res$skipped), "| passed:", sum(res$passed), "\n")
|
||||
as.integer(sum(res$failed) > 0 || any(res$error))
|
||||
},
|
||||
error = function(e) {
|
||||
cat("Tests could not be run:", conditionMessage(e), "\n")
|
||||
2L
|
||||
}
|
||||
)
|
||||
quit(save = "no", status = status)
|
||||
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
# ==================================================================== #
|
||||
# TITLE: #
|
||||
# AMR: An R Package for Working with Antimicrobial Resistance Data #
|
||||
# #
|
||||
# SOURCE CODE: #
|
||||
# https://github.com/msberends/AMR #
|
||||
# #
|
||||
# PLEASE CITE THIS SOFTWARE AS: #
|
||||
# Berends MS, Luz CF, Friedrich AW, et al. (2022). #
|
||||
# AMR: An R Package for Working with Antimicrobial Resistance Data. #
|
||||
# Journal of Statistical Software, 104(3), 1-31. #
|
||||
# https://doi.org/10.18637/jss.v104.i03 #
|
||||
# #
|
||||
# Developed at the University of Groningen and the University Medical #
|
||||
# Center Groningen in the Netherlands, in collaboration with many #
|
||||
# colleagues from around the world, see our website. #
|
||||
# #
|
||||
# This R package is free software; you can freely use and distribute #
|
||||
# it for both personal and commercial purposes under the terms of the #
|
||||
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
|
||||
# the Free Software Foundation. #
|
||||
# We created this package for both routine data analysis and academic #
|
||||
# research and it was publicly released in the hope that it will be #
|
||||
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
|
||||
# #
|
||||
# Visit our website for the full manual and a complete tutorial about #
|
||||
# how to conduct AMR data analysis: https://amr-for-r.org #
|
||||
# ==================================================================== #
|
||||
|
||||
# Runs an R script, in a real interactive R session if AMR_TEST_INTERACTIVE is "true", and exits with its status.
|
||||
# Usage: run_tests.sh <script.R>
|
||||
# R CMD check and Rscript are never interactive, so code behind interactive() is otherwise never run in CI.
|
||||
# In an interactive session, R reads both its commands and the answers to prompts from stdin, and it ignores -f. Therefore stdin holds one source() line, followed by an endless stream of "1", which means 'proceed' in every utils::menu() prompt of this package.
|
||||
# A timeout prevents an unanswerable prompt from hanging the job.
|
||||
|
||||
set +e +o pipefail
|
||||
script="$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
|
||||
|
||||
if [ "$AMR_TEST_INTERACTIVE" = "true" ]; then
|
||||
{ echo "source('$script')"; yes 1; } | timeout 3600 R --interactive --no-save --quiet
|
||||
status=${PIPESTATUS[1]}
|
||||
else
|
||||
timeout 3600 Rscript "$script"
|
||||
status=$?
|
||||
fi
|
||||
|
||||
if [ "$status" = "124" ]; then
|
||||
echo "Timed out, possibly on a prompt that could not be answered"
|
||||
fi
|
||||
exit $status
|
||||
@@ -0,0 +1,67 @@
|
||||
# ==================================================================== #
|
||||
# TITLE: #
|
||||
# AMR: An R Package for Working with Antimicrobial Resistance Data #
|
||||
# #
|
||||
# SOURCE CODE: #
|
||||
# https://github.com/msberends/AMR #
|
||||
# #
|
||||
# PLEASE CITE THIS SOFTWARE AS: #
|
||||
# Berends MS, Luz CF, Friedrich AW, et al. (2022). #
|
||||
# AMR: An R Package for Working with Antimicrobial Resistance Data. #
|
||||
# Journal of Statistical Software, 104(3), 1-31. #
|
||||
# https://doi.org/10.18637/jss.v104.i03 #
|
||||
# #
|
||||
# Developed at the University of Groningen and the University Medical #
|
||||
# Center Groningen in the Netherlands, in collaboration with many #
|
||||
# colleagues from around the world, see our website. #
|
||||
# #
|
||||
# This R package is free software; you can freely use and distribute #
|
||||
# it for both personal and commercial purposes under the terms of the #
|
||||
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
|
||||
# the Free Software Foundation. #
|
||||
# We created this package for both routine data analysis and academic #
|
||||
# research and it was publicly released in the hope that it will be #
|
||||
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
|
||||
# #
|
||||
# Visit our website for the full manual and a complete tutorial about #
|
||||
# how to conduct AMR data analysis: https://amr-for-r.org #
|
||||
# ==================================================================== #
|
||||
|
||||
# Sets up the user environment of a test scenario in the home directory, before run_tests.sh runs the tests. Run it through run_tests.sh with AMR_TEST_INTERACTIVE=true, since set_mo_source() only works in interactive sessions.
|
||||
# AMR_TEST_SCENARIO can contain one or more of these words, separated by a comma:
|
||||
# - "user": an existing ~/mo_source.rds, and the options AMR_custom_ab and AMR_custom_mo set to RDS files
|
||||
# - "clsi": the option AMR_guideline set to "CLSI"
|
||||
# The options are written to ~/.Rprofile, so that they are set at start-up as with users.
|
||||
|
||||
status <- tryCatch(
|
||||
{
|
||||
stopifnot(interactive())
|
||||
scenarios <- trimws(strsplit(Sys.getenv("AMR_TEST_SCENARIO"), ",")[[1]])
|
||||
stopifnot(length(scenarios) > 0, all(scenarios %in% c("user", "clsi")))
|
||||
pkgload::load_all(Sys.getenv("AMR_TEST_PKG_DIR", "."), quiet = TRUE)
|
||||
opts <- character(0)
|
||||
if ("user" %in% scenarios) {
|
||||
dir.create("~/amr_fixtures", showWarnings = FALSE)
|
||||
write.csv(data.frame(lab_code = c("AMRTEST_ECOLI", "AMRTEST_SAUR"), mo = c("B_ESCHR_COLI", "B_STPHY_AURS")), "~/amr_fixtures/mo_source.csv", row.names = FALSE)
|
||||
set_mo_source("~/amr_fixtures/mo_source.csv")
|
||||
stopifnot(file.exists("~/mo_source.rds"))
|
||||
saveRDS(data.frame(ab = "AMRTST", name = "Amrtestacillin", group = "Test antimicrobials"), "~/amr_fixtures/custom_ab.rds")
|
||||
saveRDS(data.frame(genus = "Amrtestbacterium", species = "scenarii"), "~/amr_fixtures/custom_mo.rds")
|
||||
opts <- c(opts, paste0("AMR_custom_ab = '", path.expand("~/amr_fixtures/custom_ab.rds"), "'"), paste0("AMR_custom_mo = '", path.expand("~/amr_fixtures/custom_mo.rds"), "'"))
|
||||
}
|
||||
if ("clsi" %in% scenarios) {
|
||||
opts <- c(opts, "AMR_guideline = 'CLSI'")
|
||||
}
|
||||
if (length(opts) > 0) {
|
||||
write(paste0("options(", paste(opts, collapse = ", "), ")"), "~/.Rprofile", append = TRUE)
|
||||
}
|
||||
cat("Scenario set up:", paste(scenarios, collapse = ", "), "\n")
|
||||
if (file.exists("~/.Rprofile")) cat(readLines("~/.Rprofile"), sep = "\n")
|
||||
0L
|
||||
},
|
||||
error = function(e) {
|
||||
cat("Scenario could not be set up:", conditionMessage(e), "\n")
|
||||
2L
|
||||
}
|
||||
)
|
||||
quit(save = "no", status = status)
|
||||
Reference in new issue
Block a user