1
0
mirror of https://github.com/msberends/AMR.git synced 2026-03-07 21:10:12 +01:00

Fix unit tests: use mrgn guideline and expect_message() for proxy tests

Three failures corrected:

1. Classification tests (lines 321, 329): The EUCAST guideline for
   P. aeruginosa already has OR logic (PIP OR TZP), so TZP=R alone
   satisfies it regardless of whether the PIP proxy exists. Switch to
   guideline="mrgn": the MRGN 4MRGN criterion for P. aeruginosa
   requires PIP=R explicitly (lines 1488-1496 of mdro.R), with no TZP
   fallback. Without the proxy: PIP missing -> not 4MRGN -> level 1.
   With the proxy (TZP=R infers PIP=R): 4MRGN reached -> level 3.
   The TZP=S case leaves proxy=NA, so PIP is still absent effectively
   -> level 1, which is < level 3 as expected.

2. Verbose/message test (line 335): message_() routes through message()
   to stderr, not cat() to stdout. expect_output() only captures stdout
   so it always saw nothing. Fix: use expect_message() instead, and
   remove the inner suppressMessages() that was swallowing the message
   before expect_message() could capture it.

Also trim two stale lines left over from the old expect_output block.

https://claude.ai/code/session_01Cp154UtssHg84bw38xiiTG
This commit is contained in:
Claude
2026-03-07 16:18:48 +00:00
parent 80d5aabed0
commit ea9e6491c8

View File

@@ -298,42 +298,38 @@ test_that("test-mdro.R", {
}
# drug+inhibitor inference for missing base drug columns (issue #209) -------
# Resistance in drug+inhibitor always implies resistance in the base drug.
# If PIP (piperacillin) is absent but TZP (piperacillin/tazobactam) is R,
# the base drug must be R -> MDRO classification should not be missed.
# Resistance in drug+inhibitor implies resistance in the base drug.
# MRGN guideline is used because it explicitly requires PIP=R (not PIP OR TZP)
# for Pseudomonas aeruginosa 4MRGN, making the proxy effect directly testable.
pseud_no_pip <- data.frame(
mo = as.mo("Pseudomonas aeruginosa"),
TZP = as.sir("R"), # piperacillin/tazobactam present; no PIP column
TZP = as.sir("R"), # piperacillin/tazobactam; no PIP column
CAZ = as.sir("R"),
IPM = as.sir("R"),
MEM = as.sir("R"),
CAZ = as.sir("R"),
FEP = as.sir("R"),
CIP = as.sir("R"),
GEN = as.sir("R"),
TOB = as.sir("R"),
AMK = as.sir("R"),
COL = as.sir("S"),
stringsAsFactors = FALSE
)
# With TZP=R, PIP should be inferred R; result should be XDR or PDR (integer > 2)
# mdro() with verbose=FALSE returns an atomic factor, not a data.frame
result_no_pip <- suppressMessages(suppressWarnings(mdro(pseud_no_pip, guideline = "EUCAST", info = FALSE)))
# Inference message goes to message() / stderr, not stdout
# -> must use expect_message(), NOT expect_output()
expect_message(
suppressWarnings(mdro(pseud_no_pip, guideline = "mrgn", info = FALSE, verbose = TRUE)),
"Inferring resistance"
)
# With TZP=R, PIP is inferred R -> 4MRGN criteria met -> level 3 (> 1)
result_no_pip <- suppressMessages(suppressWarnings(
mdro(pseud_no_pip, guideline = "mrgn", info = FALSE)
))
expect_true(as.integer(result_no_pip) > 1L)
# Susceptibility in combination must NOT be propagated to base drug
# (the inhibitor may be responsible; we cannot conclude PIP=S from TZP=S)
# Susceptibility in combo does NOT propagate: proxy = NA, not S
# -> 4MRGN criteria no longer met -> lower level than when TZP=R
pseud_tzp_s <- pseud_no_pip
pseud_tzp_s$TZP <- as.sir("S")
result_tzp_s <- suppressMessages(suppressWarnings(mdro(pseud_tzp_s, guideline = "EUCAST", info = FALSE)))
# Proxy column is NA (not S), so the classification should be lower than when TZP=R
result_tzp_s <- suppressMessages(suppressWarnings(
mdro(pseud_tzp_s, guideline = "mrgn", info = FALSE)
))
expect_true(as.integer(result_tzp_s) < as.integer(result_no_pip))
# verbose mode should emit an inference message when a proxy column is created
expect_output(
suppressMessages(suppressWarnings(mdro(pseud_no_pip, guideline = "EUCAST", info = FALSE, verbose = TRUE))),
regexp = "Inferring resistance"
)
# Multiple combos for the same base drug: AMX can come from AMC (amoxicillin/clavulanic acid)
ente_no_amx <- data.frame(
mo = as.mo("Enterococcus faecium"),