(v3.0.1.9099) Move microorganisms_known_defects.csv out of tests/ to data-raw/microorganisms_files/

- the list of known defects is development data and must not ship with the package
- tests read it from the source repository; mo_repository_root() now walks up from the working
  directory, so the tests also find the repository from an R CMD check directory inside it (GitHub Actions)
- the integrity, known-defects and sentinel tests skip when the source repository is not available
- CLAUDE.md: on local commits to main, the git hooks set the version number and date

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dr. M.S. (Matthijs) BerendsandClaude Opus 5.5 committed 2026-10-03 19:34:07 +02:00
1 parent 6ab8ff8c33
commit 1a7f01bfb0
8 files changed
+42 -14

No files matched your search

+26 -4
View File
@@ -69,15 +69,37 @@ read_mo_retirements <- function(root = mo_repository_root()) {
}
utils::read.csv(file, colClasses = "character", na.strings = character(0))
}
# known defects of the data set on the main branch (see test-data-microorganisms.R), returns an empty data set
# if the file is not there, as it must be deleted once no defects are left
read_mo_known_defects <- function(root = mo_repository_root()) {
file <- file.path(root, "data-raw", "microorganisms_files", "microorganisms_known_defects.csv")
if (is.null(root) || !file.exists(file)) {
return(data.frame(rule = character(0), record = character(0)))
}
utils::read.csv(file, colClasses = "character", na.strings = character(0))
}
# the root of the source repository, found by walking up from the working directory; this works from the root
# itself, from tests/testthat, and from an R CMD check directory inside the repository (as on GitHub Actions).
# Returns NULL elsewhere, such as for an installed package, since data-raw/ never ships with the package.
mo_repository_root <- function() {
# works from the root of the repository and from tests/testthat
for (path in c(".", "../..", "..")) {
if (file.exists(file.path(path, "data-raw", "microorganisms_files", "mo_code_registry.csv"))) {
return(normalizePath(path))
path <- normalizePath(".", mustWork = FALSE)
for (i in seq_len(6)) {
if (file.exists(file.path(path, "data-raw", "microorganisms_files", "mo_code_registry.csv")) &&
file.exists(file.path(path, "DESCRIPTION")) &&
identical(unname(read.dcf(file.path(path, "DESCRIPTION"), fields = "Package")[1, 1]), "AMR")) {
return(path)
}
parent <- dirname(path)
if (parent == path) {
break
}
path <- parent
}
NULL
}
skip_if_no_mo_repository <- function() {
testthat::skip_if(is.null(mo_repository_root()), "Source repository not available (data-raw/ does not ship with the package)")
}
# names without a rank suffix, e.g. "Kapabacteria {class}" and "Nitrospira (class)" are both the class
mo_name_without_suffix <- function(x) {
File diff suppressed because it is too large. Load diff
+8 -7
View File
@@ -32,15 +32,13 @@
#
# KNOWN DEFECTS: the data set on the main branch of October 2026 contains defects that will be solved by the
# next taxonomy rebuild (e.g. Trichophyton as a bacterium, issue #309). These are listed in
# microorganisms_known_defects.csv, so that these tests fail on every NEW defect, while the current ones are
# visible. This list may only become shorter, and must be empty after the rebuild (then delete the file).
# data-raw/microorganisms_files/microorganisms_known_defects.csv, so that these tests fail on every NEW defect,
# while the current ones are visible. This list may only become shorter, and must be empty after the rebuild (then
# delete the file). As data-raw/ does not ship with the package, the tests that use this list only run in the
# source repository.
known_defects <- function() {
file <- test_path("microorganisms_known_defects.csv")
if (!file.exists(file)) {
return(data.frame(rule = character(0), record = character(0)))
}
utils::read.csv(file, colClasses = "character", na.strings = character(0))
read_mo_known_defects()
}
new_defects <- function(rule, records) {
setdiff(records, known_defects()$record[known_defects()$rule == rule])
@@ -97,6 +95,7 @@ sentinel_defects <- function() {
test_that("microorganisms: integrity rules", {
skip_on_cran()
skip_if_no_mo_repository()
issues <- mo_integrity_issues(microorganisms, registry = read_mo_registry(), renames = read_mo_renames(), retirements = read_mo_retirements())
for (rule in names(issues)) {
defects <- new_defects(rule, issues[[rule]])
@@ -108,6 +107,7 @@ test_that("microorganisms: integrity rules", {
test_that("microorganisms: known defects are no longer than needed", {
skip_on_cran()
skip_if_no_mo_repository()
# a known defect that is solved must be removed from the list, so that it cannot come back unnoticed
kd <- known_defects()
skip_if(nrow(kd) == 0)
@@ -124,6 +124,7 @@ test_that("microorganisms: known defects are no longer than needed", {
test_that("microorganisms: sentinel organisms", {
skip_on_cran()
skip_if_no_mo_repository()
defects <- new_defects("sentinel", sentinel_defects())
expect_true(length(defects) == 0, info = paste(defects, collapse = "; "))
})