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