From e6a50e58980654d8d5f8c93cc9af43c23502197f Mon Sep 17 00:00:00 2001 From: Cyril Achard Date: Thu, 26 Nov 2026 14:13:53 +0100 Subject: [PATCH 1/3] Copy project findings, errors and policy --- dlccore/project/errors.py | 41 ++ dlccore/project/policy.py | 67 ++++ dlccore/project/schemas/base/finding_codes.py | 363 ++++++++++++++++++ dlccore/project/schemas/base/findings.py | 109 ++++++ tests/project/schemas/test_finding_codes.py | 234 +++++++++++ tests/project/schemas/test_layout_instance.py | 64 +++ 6 files changed, 878 insertions(+) create mode 100644 dlccore/project/errors.py create mode 100644 dlccore/project/policy.py create mode 100644 dlccore/project/schemas/base/finding_codes.py create mode 100644 dlccore/project/schemas/base/findings.py create mode 100644 tests/project/schemas/test_finding_codes.py create mode 100644 tests/project/schemas/test_layout_instance.py diff --git a/dlccore/project/errors.py b/dlccore/project/errors.py new file mode 100644 index 0000000..47c898c --- /dev/null +++ b/dlccore/project/errors.py @@ -0,0 +1,41 @@ +"""Data validation-specific errors.""" + +from __future__ import annotations + +from typing import TYPE_CHECKING + +from dlc_octopus.schemas.base.findings import Severity + +if TYPE_CHECKING: + from dlc_octopus.schemas.base.findings import Finding + from dlc_octopus.schemas.snapshots import ProjectSnapshot + + +class ConfigUnavailableError(RuntimeError): + """Raised when canonical project config data is unavailable.""" + + +BLOCKING_SEVERITIES = frozenset({Severity.ERROR}) + + +class ProjectValidationError(RuntimeError): + """Raised when an inspected project contains blocking findings.""" + + def __init__( + self, + snapshot: ProjectSnapshot, + ) -> None: + self.snapshot = snapshot + self.findings = _blocking_findings(snapshot) + + codes = ", ".join(finding.code for finding in self.findings) + + super().__init__(f"Project validation failed with {len(self.findings)} blocking finding(s): {codes}.") + + +def _blocking_findings( + snapshot: ProjectSnapshot, +) -> tuple[Finding, ...]: + """Return the snapshot's findings whose severity is in ``BLOCKING_SEVERITIES``.""" + + return tuple(finding for finding in snapshot.findings if finding.severity in BLOCKING_SEVERITIES) diff --git a/dlccore/project/policy.py b/dlccore/project/policy.py new file mode 100644 index 0000000..8d95067 --- /dev/null +++ b/dlccore/project/policy.py @@ -0,0 +1,67 @@ +"""A consumer's policy over findings: Octopus's severity default, adjusted by the consumer's own finding codes. + +The codes are the consumer's decision; these helpers only apply them. +""" + +from __future__ import annotations + +from collections.abc import Collection, Iterable + +from dlc_octopus.errors import BLOCKING_SEVERITIES +from dlc_octopus.schemas.base.finding_codes import FindingCode +from dlc_octopus.schemas.base.findings import Finding + + +def get_blocking_findings( + findings: Iterable[Finding], + *, + block: Collection[FindingCode] = (), + allow: Collection[FindingCode] = (), +) -> tuple[Finding, ...]: + """Return the findings that block, in order: blocking severity by default, plus ``block``, minus ``allow``. + + Args: + findings: The findings to filter, e.g. from ``findings_in_scope``. + block: Codes that block whatever their severity. + allow: Codes that never block, even at blocking severity. + + Raises: + TypeError: If a code is not a ``FindingCode`` member, so that a renamed code fails where it is named. + ValueError: If a code is both blocked and allowed. + """ + + _members(block) + _members(allow) + + both = set(block) & set(allow) + if both: + raise ValueError(f"Codes both blocked and allowed: {sorted(both)}.") + + return tuple( + finding + for finding in findings + if finding.code not in allow and (finding.severity in BLOCKING_SEVERITIES or finding.code in block) + ) + + +def unhandled(findings: Iterable[Finding], handled: Collection[FindingCode]) -> tuple[Finding, ...]: + """Return the findings whose code is not in ``handled``, in order. + + Args: + findings: The findings to check. + handled: The codes the consumer maps; a mapping from each code to how it is handled also works, and only its + keys are read. + + Raises: + TypeError: If a code is not a ``FindingCode`` member, so that a renamed code fails where it is named. + """ + + _members(handled) + + return tuple(finding for finding in findings if finding.code not in handled) + + +def _members(codes: Collection[FindingCode]) -> None: + strays = [code for code in codes if not isinstance(code, FindingCode)] + if strays: + raise TypeError(f"Name finding codes by their FindingCode members, not {strays!r}.") diff --git a/dlccore/project/schemas/base/finding_codes.py b/dlccore/project/schemas/base/finding_codes.py new file mode 100644 index 0000000..0c125cf --- /dev/null +++ b/dlccore/project/schemas/base/finding_codes.py @@ -0,0 +1,363 @@ +# schemas/base/finding_codes.py +"""Finding vocabulary: severities, and the stable codes to emit. + +Validation-check, baseline-check and validator-suite identifiers share the +same naming style but are separate namespaces. + +Codes are grouped by subject rather than by emitting module, following the +``_`` convention. +""" + +from __future__ import annotations + +from enum import Enum +from itertools import chain + + +class Severity(str, Enum): + NOTE = "note" + WARNING = "warning" + ERROR = "error" + + +class FindingCode(str, Enum): + """Base for every ``Finding.code`` namespace; declares no codes itself.""" + + # Render as the bare code, as ``enum.StrEnum`` would; it is 3.11+. + __str__ = str.__str__ + + description: str + severity: Severity + evidence_keys: tuple[str, ...] + + def __new__( + cls, + code: str, + description: str, + severity: Severity, + evidence_keys: tuple[str, ...], + ) -> FindingCode: + member = str.__new__(cls, code) + member._value_ = code + member.description = description + member.severity = severity + member.evidence_keys = tuple(evidence_keys) + + return member + + +class StructureFindingCode(FindingCode): + """Findings about the project's schema-defined layout.""" + + PROJECT_REQUIRED_NODE_MISSING = ( + "PROJECT_REQUIRED_NODE_MISSING", + "A required project-layout node is missing.", + Severity.ERROR, + ("resource_kind",), + ) + PROJECT_SYMLINK_TARGET_MISSING = ( + "PROJECT_SYMLINK_TARGET_MISSING", + "A project resource is a symlink whose target does not exist.", + Severity.ERROR, + ("resource_kind", "raw_target", "absolute_target"), + ) + PROJECT_SYMLINK_TARGET_WRONG_TYPE = ( + "PROJECT_SYMLINK_TARGET_WRONG_TYPE", + "The symbolic-link target has an unexpected filesystem type.", + Severity.ERROR, + ("resource_kind", "raw_target", "absolute_target", "target_kind"), + ) + PROJECT_NODE_WRONG_TYPE = ( + "PROJECT_NODE_WRONG_TYPE", + "A project resource exists at the expected location but has the wrong filesystem type.", + Severity.ERROR, + ("resource_kind", "expected_type"), + ) + PROJECT_NODE_UNREADABLE = ( + "PROJECT_NODE_UNREADABLE", + "A project-layout node could not be read.", + Severity.ERROR, + ("resource_kind", "error_type", "error_message"), + ) + PROJECT_RESOURCE_PATH_COLLISION = ( + "PROJECT_RESOURCE_PATH_COLLISION", + "This project resource resolves to the same filesystem path as another; each one is reported.", + Severity.ERROR, + ("resource_kind", "collision_path", "collision_group"), + ) + + +class ConfigFindingCode(FindingCode): + """Findings about reading, parsing and interpreting ``config.yaml``.""" + + CONFIG_READ_FAILED = ( + "CONFIG_READ_FAILED", + "The config file could not be read.", + Severity.ERROR, + ("error_type", "error_message"), + ) + CONFIG_PARSE_FAILED = ( + "CONFIG_PARSE_FAILED", + "The config file could not be parsed.", + Severity.ERROR, + ("error_type", "error_message"), + ) + CONFIG_VALIDATION_ERROR = ( + "CONFIG_VALIDATION_ERROR", + "The config file failed canonical schema validation.", + Severity.ERROR, + ("error_type", "error_message"), + ) + CONFIG_LOAD_FAILED = ( + "CONFIG_LOAD_FAILED", + "The config file could not be loaded through the canonical schema, for a reason other than a field " + "failing validation, such as a config version with no migration path.", + Severity.ERROR, + ("error_type", "error_message"), + ) + CONFIG_VERSION_UPGRADED = ( + "CONFIG_VERSION_UPGRADED", + "The config declares an older config version; DeepLabCut migrated it in memory to the current one.", + Severity.NOTE, + ("declared_version", "loaded_version"), + ) + CONFIG_VERSION_DOWNGRADED = ( + "CONFIG_VERSION_DOWNGRADED", + "The config declares a newer config version than this code reads; DeepLabCut migrated it down in memory, " + "which can drop fields.", + Severity.WARNING, + ("declared_version", "loaded_version"), + ) + CONFIG_NO_KEYPOINTS = ( + "CONFIG_NO_KEYPOINTS", + "The config loads but declares no keypoints.", + Severity.WARNING, + ("multianimal_project", "declared"), + ) + CONFIG_NULL_KEY_DEFAULTED = ( + "CONFIG_NULL_KEY_DEFAULTED", + "A config key is written with no value, so the DeepLabCut field default was used.", + Severity.NOTE, + ("default",), + ) + CONFIG_PROJECT_PATH_MISMATCH = ( + "CONFIG_PROJECT_PATH_MISMATCH", + "The project path declared in config.yaml does not match the project root observed. A declared path " + "probed as missing may also be an unreachable network location or a path from another platform.", + Severity.NOTE, + ("declared_project_path", "observed_project_root", "declared_path_probe", "error_type", "error_message"), + ) + CONFIG_PROJECT_PATH_NOT_ABSOLUTE = ( + "CONFIG_PROJECT_PATH_NOT_ABSOLUTE", + "The project path in config.yaml is missing, empty or relative, and cannot be compared with the project root.", + Severity.NOTE, + ("declared_project_path",), + ) + + +class ConfiguredVideoFindingCode(FindingCode): + """Findings about video paths declared in ``config.yaml``.""" + + CONFIGURED_VIDEO_PATH_MISSING = ( + "CONFIGURED_VIDEO_PATH_MISSING", + "The configured video path does not exist.", + Severity.ERROR, + (), + ) + CONFIGURED_VIDEO_PATH_SYMLINK_TARGET_MISSING = ( + "CONFIGURED_VIDEO_PATH_SYMLINK_TARGET_MISSING", + "The configured video path is a symlink whose target does not exist.", + Severity.ERROR, + ("raw_target", "absolute_target"), + ) + CONFIGURED_VIDEO_PATH_UNREADABLE = ( + "CONFIGURED_VIDEO_PATH_UNREADABLE", + "The configured video path could not be read.", + Severity.ERROR, + ("error_type", "error_message"), + ) + CONFIGURED_VIDEO_PATH_NOT_FILE = ( + "CONFIGURED_VIDEO_PATH_NOT_FILE", + "The configured video path exists but is not a file.", + Severity.ERROR, + (), + ) + CONFIGURED_VIDEOS_UNDER_MISSING_ROOT = ( + "CONFIGURED_VIDEOS_UNDER_MISSING_ROOT", + "Configured video paths end in videos/, the video exists in this project, but the paths " + "themselves do not exist. Was the project moved or copied?", + Severity.WARNING, + ("declared_paths", "matched_paths"), + ) + CONFIGURED_VIDEO_IN_OTHER_COPY = ( + "CONFIGURED_VIDEO_IN_OTHER_COPY", + "The configured video path ends in videos/ and exists, but is a different file from this " + "project's video with the same name. DeepLabCut will read the configured one.", + Severity.WARNING, + ("matched_path",), + ) + CONFIGURED_VIDEO_OUTSIDE_PROJECT = ( + "CONFIGURED_VIDEO_OUTSIDE_PROJECT", + "The configured video path exists but is not in the project's videos directory.", + Severity.ERROR, + (), + ) + VIDEO_NOT_IN_VIDEO_SETS = ( + "VIDEO_NOT_IN_VIDEO_SETS", + "A video in the project's videos directory has no corresponding path in the configuration.", + Severity.NOTE, + ("resource_kind",), + ) + + +class FingerprintFindingCode(FindingCode): + """Findings about file and frame fingerprints of requested project resources.""" + + FILE_FINGERPRINT_FAILED = ( + "FILE_FINGERPRINT_FAILED", + "A requested resource could not be file-fingerprinted.", + Severity.ERROR, + ("resource_kind", "error_type", "error_message"), + ) + FILE_FINGERPRINT_CHANGED = ( + "FILE_FINGERPRINT_CHANGED", + "A resource's file fingerprint differs from the one recorded for it, or it was not fingerprinted.", + Severity.WARNING, + ("recorded_sha256", "observed_sha256"), + ) + + +class LabeledDataFindingCode(FindingCode): + """Findings about the content of labeled-data files.""" + + LABELED_DATA_UNREADABLE = ( + "LABELED_DATA_UNREADABLE", + "A labeled-data file could not be read.", + Severity.ERROR, + ("resource_kind", "error_type", "error_message"), + ) + LABELED_DATA_H5_MULTI_KEY = ( + "LABELED_DATA_H5_MULTI_KEY", + "An H5 labels file holds several tables; one was read by declared precedence and the others were not.", + Severity.ERROR, + ("keys_found", "selected_key"), + ) + LABELED_DATA_H5_LEGACY_KEY = ( + "LABELED_DATA_H5_LEGACY_KEY", + "An H5 labels file stores its table under a key older DeepLabCut releases wrote.", + Severity.WARNING, + ("key",), + ) + LABELED_DATA_H5_UNKNOWN_KEY = ( + "LABELED_DATA_H5_UNKNOWN_KEY", + "An H5 labels file stores its table under a key no DeepLabCut release is known to write.", + Severity.WARNING, + ("key",), + ) + LABELED_DATA_HEADER_UNRECOGNISED = ( + "LABELED_DATA_HEADER_UNRECOGNISED", + "A labels file's column levels are neither of the headers DeepLabCut writes, so no labels can be read from it.", + Severity.ERROR, + ("level_names",), + ) + LABELED_DATA_COORDS_UNRECOGNISED = ( + "LABELED_DATA_COORDS_UNRECOGNISED", + "Keypoints whose coordinates are not exactly x, y and optionally likelihood, so no labels can be read from " + "the file.", + Severity.ERROR, + ("keypoints",), + ) + LABELED_DATA_LIKELIHOOD_PARTIAL = ( + "LABELED_DATA_LIKELIHOOD_PARTIAL", + "Some keypoints store a likelihood and these do not, so no labels can be read from the file.", + Severity.ERROR, + ("keypoints",), + ) + LABELED_DATA_VALUES_NOT_NUMERIC = ( + "LABELED_DATA_VALUES_NOT_NUMERIC", + "Value columns hold something other than real numbers, so no labels can be read from the file.", + Severity.ERROR, + ("columns",), + ) + LABELED_DATA_NO_FRAMES = ( + "LABELED_DATA_NO_FRAMES", + "A labels file has a header and no frames, so it holds no labels.", + Severity.WARNING, + (), + ) + LABELED_DATA_ROW_INDEX_UNRECOGNISED = ( + "LABELED_DATA_ROW_INDEX_UNRECOGNISED", + "A labels file's row index is neither frame path parts nor path strings, so no labels can be read from it.", + Severity.ERROR, + ("first_entry",), + ) + LABELED_DATA_FRAME_DEPTH = ( + "LABELED_DATA_FRAME_DEPTH", + "Frames whose path has other than three parts, so no labels can be read from the file.", + Severity.ERROR, + ("row_count", "first_frame"), + ) + LABELED_DATA_FRAME_PART_UNNAMED = ( + "LABELED_DATA_FRAME_PART_UNNAMED", + "Frames with a path part that is neither text nor an integer, so no labels can be read from the file.", + Severity.ERROR, + ("row_count", "first_frame"), + ) + LABELED_DATA_CSV_FRAME_ABSORBED = ( + "LABELED_DATA_CSV_FRAME_ABSORBED", + "A CSV labels file's first frame has no values, so a CSV read takes it as the row index's names and the " + "file reads back without that frame.", + Severity.WARNING, + ("frame",), + ) + LABELED_DATA_WRITER_STAMP_MALFORMED = ( + "LABELED_DATA_WRITER_STAMP_MALFORMED", + "A labels file carries a writer stamp that could not be read.", + Severity.NOTE, + ("error_message",), + ) + LABELED_DATA_HUMAN_LIKELIHOOD = ( + "LABELED_DATA_HUMAN_LIKELIHOOD", + "Human labels store a likelihood, which ground truth never carries.", + Severity.WARNING, + (), + ) + LABELED_DATA_KEYPOINT_MISSING = ( + "LABELED_DATA_KEYPOINT_MISSING", + "Individuals lack a bodypart another individual of the same scorer has.", + Severity.WARNING, + ("missing",), + ) + LABELED_DATA_INDIVIDUAL_EMPTY = ( + "LABELED_DATA_INDIVIDUAL_EMPTY", + "Keypoints whose individual is named with an empty string, which names no individual.", + Severity.ERROR, + ("keypoints",), + ) + + +def iter_finding_codes() -> tuple[FindingCode, ...]: + """Return every declared finding code, namespace by namespace.""" + + return tuple(chain.from_iterable(FindingCode.__subclasses__())) + + +def finding_code(value: str | FindingCode) -> FindingCode: + """Return the declared code for one value, as read from serialized output. + + Raises: + ValueError: If no namespace declares the value. + """ + + if isinstance(value, FindingCode): + return value + + for namespace in FindingCode.__subclasses__(): + try: + return namespace(value) + except ValueError: + continue + + declared = ", ".join(code.value for code in iter_finding_codes()) + + raise ValueError(f"Unknown finding code {value!r}. Declared codes are: {declared or ''}.") diff --git a/dlccore/project/schemas/base/findings.py b/dlccore/project/schemas/base/findings.py new file mode 100644 index 0000000..cf651aa --- /dev/null +++ b/dlccore/project/schemas/base/findings.py @@ -0,0 +1,109 @@ +# schemas/base/findings.py +"""Simple diagnostic facts generated from walking through the project structure. + +These are the main enablers for downstream reporting, consumption by GUI/CLI/LLM agents, +and offering actions based on the findings (e.g., "PROJECT_REQUIRED_NODE_MISSING" could trigger a prompt to +locate or create the missing file). +""" + +from __future__ import annotations + +from enum import Enum +from pathlib import Path +from typing import TYPE_CHECKING + +from pydantic import Field, JsonValue, model_validator +from typing_extensions import Self + +from dlc_octopus.schemas.base.core import FrozenModel, LayoutInstance, SchemaId +from dlc_octopus.schemas.base.finding_codes import FindingCode, Severity, finding_code + +if TYPE_CHECKING: + from IPython.lib.pretty import RepresentationPrinter + + +class Reach(str, Enum): + """Which instances of its layout node a finding is about.""" + + ONE_PER_PROJECT = "one_per_project" + ONE_OF = "one_of" + ALL_OF = "all_of" + # Outside any known project: the instance holds only the segments that are certain. Never in a snapshot. + UNROOTED = "unrooted" + + +class Finding(FrozenModel): + """A structured diagnostic produced while inspecting or validating a project item. + + Findings describe observable issues, warnings, or informational conditions + without modifying project data. + - Stable ``code`` values support programmatic handling, and carry the + human-readable text as ``code.description`` + - ``schema_id``: the layout node it is about; consumers scope by it, never by ``path`` + - ``reach``: whether it is about the only node of its kind, one instance, or every instance + - ``instance``: which instance of a repeated layout node it is about, as + project-relative path segments; ``()`` for ``ONE_PER_PROJECT``, a prefix for ``ALL_OF``, the certain + trailing segments for ``UNROOTED`` + - ``path`` and ``field_location``: where in the project it was observed + - ``evidence``: the observations supporting it, e.g. "actual" vs "expected" + """ + + code: FindingCode + severity: Severity + schema_id: SchemaId + reach: Reach + instance: LayoutInstance = () + path: Path | None = None + field_location: tuple[str | int, ...] = () + evidence: dict[str, JsonValue] = Field(default_factory=dict) + + @model_validator(mode="before") + @classmethod + def _resolve_evidence(cls, data: object) -> object: + """Resolve the code, take its severity, and require its declared evidence. + + Raises: + ValueError: If the evidence the code declares is not all present. + """ + + if not isinstance(data, dict) or data.get("code") is None: + return data + + code = finding_code(data["code"]) + evidence = data.get("evidence") + present = evidence.keys() if isinstance(evidence, dict) else () + missing = tuple(key for key in code.evidence_keys if key not in present) + + if missing: + raise ValueError(f"Finding {code.value} requires evidence keys {missing}.") + + return {**data, "code": code, "severity": code.severity} + + @model_validator(mode="after") + def _check_reach(self) -> Self: + """Refuse a reach the instance contradicts. + + Raises: + ValueError: If ``ONE_PER_PROJECT`` names an instance, or ``ONE_OF`` or ``UNROOTED`` names none. + """ + + if self.reach is Reach.ONE_PER_PROJECT and self.instance: + raise ValueError(f"Reach ONE_PER_PROJECT names no instance, but got {self.instance!r}.") + + if self.reach in {Reach.ONE_OF, Reach.UNROOTED} and not self.instance: + raise ValueError(f"Reach {self.reach.name} names one instance, but got none.") + + return self + + # Display hooks only IPython and Jupyter call; repr, str and serialization stay pydantic's. + # Imported on call so that schemas never load visualization. + + def _repr_pretty_(self, printer: RepresentationPrinter, cycle: bool) -> None: # noqa: FBT001 - IPython's signature + from dlc_octopus.visualization.findings import render_finding + + printer.text("Finding(...)" if cycle else render_finding(self)) + + def _repr_markdown_(self) -> str: + from dlc_octopus.visualization.findings import render_finding + + return render_finding(self, style="markdown") diff --git a/tests/project/schemas/test_finding_codes.py b/tests/project/schemas/test_finding_codes.py new file mode 100644 index 0000000..836963a --- /dev/null +++ b/tests/project/schemas/test_finding_codes.py @@ -0,0 +1,234 @@ +from __future__ import annotations + +import json + +import pytest +from pydantic import ValidationError + +from dlc_octopus.schemas.base.finding_codes import ( + ConfigFindingCode, + ConfiguredVideoFindingCode, + FindingCode, + FingerprintFindingCode, + LabeledDataFindingCode, + Severity, + StructureFindingCode, + iter_finding_codes, +) +from dlc_octopus.schemas.base.findings import Finding, Reach + +_UNREADABLE = StructureFindingCode.PROJECT_NODE_UNREADABLE +_SCHEMA_ID = "dlc.videos.source_video" + + +def _declared_evidence(code: FindingCode) -> dict[str, str]: + """Return placeholder evidence satisfying one code's declared keys.""" + + return dict.fromkeys(code.evidence_keys, "placeholder") + + +def test_finding_keeps_a_declared_code_as_its_enum_member() -> None: + code = StructureFindingCode.PROJECT_NODE_WRONG_TYPE + + finding = Finding( + code=code, + schema_id=_SCHEMA_ID, + reach=Reach.ONE_PER_PROJECT, + evidence=_declared_evidence(code), + ) + + assert finding.code is code + assert finding.code == "PROJECT_NODE_WRONG_TYPE" + + +def test_finding_code_renders_as_the_bare_code() -> None: + code = StructureFindingCode.PROJECT_NODE_WRONG_TYPE + + assert str(code) == "PROJECT_NODE_WRONG_TYPE" + assert f"{code}" == "PROJECT_NODE_WRONG_TYPE" + assert ", ".join([code]) == "PROJECT_NODE_WRONG_TYPE" + + +def test_finding_rejects_an_undeclared_code() -> None: + with pytest.raises(ValidationError): + Finding( + code="NOT_A_DECLARED_CODE", + schema_id=_SCHEMA_ID, + reach=Reach.ONE_PER_PROJECT, + ) + + +def test_finding_severity_comes_from_its_code() -> None: + finding = Finding( + code=_UNREADABLE, + schema_id=_SCHEMA_ID, + reach=Reach.ONE_PER_PROJECT, + evidence=_declared_evidence(_UNREADABLE), + ) + + assert finding.severity is Severity.ERROR + assert finding.model_dump()["severity"] == Severity.ERROR + + +def test_finding_ignores_a_caller_supplied_severity() -> None: + finding = Finding( + code=_UNREADABLE, + schema_id=_SCHEMA_ID, + reach=Reach.ONE_PER_PROJECT, + severity=Severity.NOTE, + evidence=_declared_evidence(_UNREADABLE), + ) + + assert finding.severity is Severity.ERROR + + +def test_finding_requires_the_evidence_its_code_declares() -> None: + with pytest.raises(ValidationError, match="requires evidence keys"): + Finding( + code=_UNREADABLE, + schema_id=_SCHEMA_ID, + reach=Reach.ONE_PER_PROJECT, + ) + + +def test_finding_reports_only_the_missing_evidence_keys() -> None: + partial = _declared_evidence(_UNREADABLE) + del partial["error_message"] + + with pytest.raises(ValidationError, match=r"\('error_message',\)"): + Finding( + code=_UNREADABLE, + schema_id=_SCHEMA_ID, + reach=Reach.ONE_PER_PROJECT, + evidence=partial, + ) + + +def test_finding_accepts_declared_evidence_that_was_not_observed() -> None: + evidence: dict[str, str | None] = dict.fromkeys(_UNREADABLE.evidence_keys, None) + + finding = Finding( + code=_UNREADABLE, + schema_id=_SCHEMA_ID, + reach=Reach.ONE_PER_PROJECT, + evidence=evidence, + ) + + assert finding.evidence["error_message"] is None + + +def test_finding_round_trips_through_serialized_form() -> None: + finding = Finding( + code=_UNREADABLE, + schema_id=_SCHEMA_ID, + reach=Reach.ONE_PER_PROJECT, + evidence=_declared_evidence(_UNREADABLE), + ) + + restored = Finding.model_validate(json.loads(finding.model_dump_json())) + + assert restored == finding + assert restored.code is _UNREADABLE + + +def test_finding_rejects_an_undeclared_code_from_serialized_form() -> None: + with pytest.raises(ValidationError, match="Unknown finding code"): + Finding.model_validate({"code": "NOT_A_DECLARED_CODE"}) + + +@pytest.mark.parametrize("code", iter_finding_codes(), ids=str) +def test_every_finding_code_is_described(code: FindingCode) -> None: + assert code.value == code.name + assert code.description + assert isinstance(code.severity, Severity) + + +@pytest.mark.parametrize("code", iter_finding_codes(), ids=str) +def test_every_finding_code_declares_well_formed_evidence_keys(code: FindingCode) -> None: + """A code may declare none: ``path`` and ``field_location`` carry the location, and evidence never repeats it.""" + + assert len(set(code.evidence_keys)) == len(code.evidence_keys) + assert all(key and key.islower() for key in code.evidence_keys) + + +def test_finding_code_values_are_unique_across_namespaces() -> None: + codes = iter_finding_codes() + + assert len({code.value for code in codes}) == len(codes) + + +def test_iter_finding_codes_covers_every_namespace() -> None: + namespaces = {type(code) for code in iter_finding_codes()} + + assert namespaces == set(FindingCode.__subclasses__()) + + +@pytest.mark.xfail( + reason="the train-side split reconciliation is not built; when it is, delete this and add " + "a test under tests/upstream/ recording where ours intentionally differs from DeepLabCut's " + "`_validate_dataframes`, which is disabled and known incomplete", + strict=True, + raises=AssertionError, +) +def test_training_split_reconciliation_declares_a_finding_code() -> None: + assert "TRAINING_SPLIT_TABLE_MISMATCH" in {code.value for code in iter_finding_codes()} + + +def test_the_finding_code_catalogue_is_closed() -> None: + """The catalogue is closed: adding a namespace is deliberate, so it fails here first.""" + + assert set(FindingCode.__subclasses__()) == { + StructureFindingCode, + ConfigFindingCode, + ConfiguredVideoFindingCode, + FingerprintFindingCode, + LabeledDataFindingCode, + } + + +def test_severity_has_three_rungs() -> None: + assert {member.name for member in Severity} == {"NOTE", "WARNING", "ERROR"} + + +def test_schema_id_is_a_required_finding_field() -> None: + field = Finding.model_fields.get("schema_id") + + assert field is not None + assert field.is_required() + + +def test_instance_is_a_finding_field() -> None: + assert "instance" in Finding.model_fields + + +def test_a_finding_states_its_reach() -> None: + evidence = _declared_evidence(_UNREADABLE) + + def finding(reach: Reach, instance: tuple[str, ...]) -> Finding: + return Finding(code=_UNREADABLE, schema_id=_SCHEMA_ID, reach=reach, instance=instance, evidence=evidence) + + assert {member.name for member in Reach} == {"ONE_PER_PROJECT", "ONE_OF", "ALL_OF", "UNROOTED"} + + with pytest.raises(ValidationError): + finding(Reach.ONE_PER_PROJECT, ("videos", "m1.mp4")) + + with pytest.raises(ValidationError): + finding(Reach.ONE_OF, ()) + + with pytest.raises(ValidationError): + finding(Reach.UNROOTED, ()) + + assert finding(Reach.ONE_OF, ("videos", "m1.mp4")).reach is Reach.ONE_OF + assert finding(Reach.ALL_OF, ()).instance == () + assert finding(Reach.ALL_OF, ("labeled-data", "m2")).instance == ("labeled-data", "m2") + + +@pytest.mark.xfail( + reason="a released code must never disappear silently: renamed, merged or split codes are to " + "declare what they supersede; once they do, replace this with a tripwire over the released " + "code list that also requires a version bump whenever the catalogue changes", + strict=True, + raises=AssertionError, +) +def test_a_released_code_cannot_disappear_without_a_successor() -> None: + assert all(hasattr(code, "supersedes") for code in iter_finding_codes()) diff --git a/tests/project/schemas/test_layout_instance.py b/tests/project/schemas/test_layout_instance.py new file mode 100644 index 0000000..c96ddbb --- /dev/null +++ b/tests/project/schemas/test_layout_instance.py @@ -0,0 +1,64 @@ +from __future__ import annotations + +import json +from pathlib import Path + +import pytest +from pydantic import ValidationError + +from dlc_octopus.schemas.base.core import instance_from_path +from dlc_octopus.schemas.base.finding_codes import StructureFindingCode +from dlc_octopus.schemas.base.findings import Finding, Reach + +_CODE = StructureFindingCode.PROJECT_NODE_UNREADABLE +_EVIDENCE = dict.fromkeys(_CODE.evidence_keys, "placeholder") +_SCHEMA_ID = "dlc.labeled_data.dataset" + + +def test_a_finding_has_no_instance_by_default() -> None: + assert Finding(code=_CODE, schema_id=_SCHEMA_ID, reach=Reach.ONE_PER_PROJECT, evidence=_EVIDENCE).instance == () + + +def test_an_instance_serializes_as_a_plain_list() -> None: + finding = Finding( + code=_CODE, schema_id=_SCHEMA_ID, reach=Reach.ONE_OF, instance=("labeled-data", "ds1"), evidence=_EVIDENCE + ) + + assert json.loads(finding.model_dump_json())["instance"] == ["labeled-data", "ds1"] + + +@pytest.mark.parametrize("segment", ["", "labeled-data/ds1"], ids=["empty", "joined"]) +def test_an_instance_refuses_a_segment_only_a_caller_can_produce(segment: str) -> None: + with pytest.raises(ValidationError, match="project-relative path segment"): + Finding( + code=_CODE, schema_id=_SCHEMA_ID, reach=Reach.ONE_OF, instance=("labeled-data", segment), evidence=_EVIDENCE + ) + + +@pytest.mark.parametrize("segment", ["..", "12:30.mp4", "a\\b.mp4"]) +def test_an_instance_keeps_user_data_segments(segment: str) -> None: + assert Finding( + code=_CODE, schema_id=_SCHEMA_ID, reach=Reach.ONE_OF, instance=("videos", segment), evidence=_EVIDENCE + ).instance == ( + "videos", + segment, + ) + + +@pytest.mark.parametrize( + "instance", + [("C:\\", "x.mp4"), ("\\\\server\\share\\", "x.mp4"), ("C:rel", "x.mp4")], + ids=["drive-root", "unc-share", "drive-relative"], +) +def test_an_instance_refuses_segments_that_carry_a_drive_or_root(instance: tuple[str, ...]) -> None: + with pytest.raises(ValidationError, match="project-relative"): + Finding(code=_CODE, schema_id=_SCHEMA_ID, reach=Reach.ONE_OF, instance=instance, evidence=_EVIDENCE) + + +def test_instance_from_path_splits_a_project_relative_path() -> None: + assert instance_from_path(Path("labeled-data/ds1/img001.png")) == ("labeled-data", "ds1", "img001.png") + + +def test_instance_from_path_refuses_an_anchored_path() -> None: + with pytest.raises(ValueError, match="project-relative"): + instance_from_path(Path("Z:/shared/DLC/videos/a.mp4")) From d879f7171c4c8815cb481d12ad2af7559b760680 Mon Sep 17 00:00:00 2001 From: Cyril Achard Date: Thu, 26 Nov 2026 14:19:22 +0100 Subject: [PATCH 2/3] Adapt project finding codes --- dlccore/project/errors.py | 17 +- dlccore/project/policy.py | 19 +- dlccore/project/schemas/base/finding_codes.py | 302 +----------------- dlccore/project/schemas/base/findings.py | 33 +- pyproject.toml | 2 +- tests/project/schemas/test_finding_codes.py | 71 ++-- tests/project/schemas/test_layout_instance.py | 31 +- 7 files changed, 125 insertions(+), 350 deletions(-) diff --git a/dlccore/project/errors.py b/dlccore/project/errors.py index 47c898c..5ae8ff1 100644 --- a/dlccore/project/errors.py +++ b/dlccore/project/errors.py @@ -1,14 +1,25 @@ +# +# DeepLabCut Toolbox (deeplabcut.org) +# © A. & M.W. Mathis Labs +# https://github.com/DeepLabCut/dlccore +# +# Contributors: +# https://github.com/DeepLabCut/dlccore/graphs/contributors +# +# Licensed under GNU Lesser General Public License v3.0 +# + """Data validation-specific errors.""" from __future__ import annotations from typing import TYPE_CHECKING -from dlc_octopus.schemas.base.findings import Severity +from dlccore.project.schemas.base.findings import Severity if TYPE_CHECKING: - from dlc_octopus.schemas.base.findings import Finding - from dlc_octopus.schemas.snapshots import ProjectSnapshot + from dlccore.project.schemas.base.findings import Finding + from dlccore.project.schemas.snapshots import ProjectSnapshot class ConfigUnavailableError(RuntimeError): diff --git a/dlccore/project/policy.py b/dlccore/project/policy.py index 8d95067..ac33035 100644 --- a/dlccore/project/policy.py +++ b/dlccore/project/policy.py @@ -1,4 +1,15 @@ -"""A consumer's policy over findings: Octopus's severity default, adjusted by the consumer's own finding codes. +# +# DeepLabCut Toolbox (deeplabcut.org) +# © A. & M.W. Mathis Labs +# https://github.com/DeepLabCut/dlccore +# +# Contributors: +# https://github.com/DeepLabCut/dlccore/graphs/contributors +# +# Licensed under GNU Lesser General Public License v3.0 +# + +"""A consumer's policy over findings: the severity default, adjusted by the consumer's own finding codes. The codes are the consumer's decision; these helpers only apply them. """ @@ -7,9 +18,9 @@ from collections.abc import Collection, Iterable -from dlc_octopus.errors import BLOCKING_SEVERITIES -from dlc_octopus.schemas.base.finding_codes import FindingCode -from dlc_octopus.schemas.base.findings import Finding +from dlccore.project.errors import BLOCKING_SEVERITIES +from dlccore.project.schemas.base.finding_codes import FindingCode +from dlccore.project.schemas.base.findings import Finding def get_blocking_findings( diff --git a/dlccore/project/schemas/base/finding_codes.py b/dlccore/project/schemas/base/finding_codes.py index 0c125cf..5c786e8 100644 --- a/dlccore/project/schemas/base/finding_codes.py +++ b/dlccore/project/schemas/base/finding_codes.py @@ -1,4 +1,14 @@ -# schemas/base/finding_codes.py +# +# DeepLabCut Toolbox (deeplabcut.org) +# © A. & M.W. Mathis Labs +# https://github.com/DeepLabCut/dlccore +# +# Contributors: +# https://github.com/DeepLabCut/dlccore/graphs/contributors +# +# Licensed under GNU Lesser General Public License v3.0 +# + """Finding vocabulary: severities, and the stable codes to emit. Validation-check, baseline-check and validator-suite identifiers share the @@ -46,296 +56,6 @@ def __new__( return member -class StructureFindingCode(FindingCode): - """Findings about the project's schema-defined layout.""" - - PROJECT_REQUIRED_NODE_MISSING = ( - "PROJECT_REQUIRED_NODE_MISSING", - "A required project-layout node is missing.", - Severity.ERROR, - ("resource_kind",), - ) - PROJECT_SYMLINK_TARGET_MISSING = ( - "PROJECT_SYMLINK_TARGET_MISSING", - "A project resource is a symlink whose target does not exist.", - Severity.ERROR, - ("resource_kind", "raw_target", "absolute_target"), - ) - PROJECT_SYMLINK_TARGET_WRONG_TYPE = ( - "PROJECT_SYMLINK_TARGET_WRONG_TYPE", - "The symbolic-link target has an unexpected filesystem type.", - Severity.ERROR, - ("resource_kind", "raw_target", "absolute_target", "target_kind"), - ) - PROJECT_NODE_WRONG_TYPE = ( - "PROJECT_NODE_WRONG_TYPE", - "A project resource exists at the expected location but has the wrong filesystem type.", - Severity.ERROR, - ("resource_kind", "expected_type"), - ) - PROJECT_NODE_UNREADABLE = ( - "PROJECT_NODE_UNREADABLE", - "A project-layout node could not be read.", - Severity.ERROR, - ("resource_kind", "error_type", "error_message"), - ) - PROJECT_RESOURCE_PATH_COLLISION = ( - "PROJECT_RESOURCE_PATH_COLLISION", - "This project resource resolves to the same filesystem path as another; each one is reported.", - Severity.ERROR, - ("resource_kind", "collision_path", "collision_group"), - ) - - -class ConfigFindingCode(FindingCode): - """Findings about reading, parsing and interpreting ``config.yaml``.""" - - CONFIG_READ_FAILED = ( - "CONFIG_READ_FAILED", - "The config file could not be read.", - Severity.ERROR, - ("error_type", "error_message"), - ) - CONFIG_PARSE_FAILED = ( - "CONFIG_PARSE_FAILED", - "The config file could not be parsed.", - Severity.ERROR, - ("error_type", "error_message"), - ) - CONFIG_VALIDATION_ERROR = ( - "CONFIG_VALIDATION_ERROR", - "The config file failed canonical schema validation.", - Severity.ERROR, - ("error_type", "error_message"), - ) - CONFIG_LOAD_FAILED = ( - "CONFIG_LOAD_FAILED", - "The config file could not be loaded through the canonical schema, for a reason other than a field " - "failing validation, such as a config version with no migration path.", - Severity.ERROR, - ("error_type", "error_message"), - ) - CONFIG_VERSION_UPGRADED = ( - "CONFIG_VERSION_UPGRADED", - "The config declares an older config version; DeepLabCut migrated it in memory to the current one.", - Severity.NOTE, - ("declared_version", "loaded_version"), - ) - CONFIG_VERSION_DOWNGRADED = ( - "CONFIG_VERSION_DOWNGRADED", - "The config declares a newer config version than this code reads; DeepLabCut migrated it down in memory, " - "which can drop fields.", - Severity.WARNING, - ("declared_version", "loaded_version"), - ) - CONFIG_NO_KEYPOINTS = ( - "CONFIG_NO_KEYPOINTS", - "The config loads but declares no keypoints.", - Severity.WARNING, - ("multianimal_project", "declared"), - ) - CONFIG_NULL_KEY_DEFAULTED = ( - "CONFIG_NULL_KEY_DEFAULTED", - "A config key is written with no value, so the DeepLabCut field default was used.", - Severity.NOTE, - ("default",), - ) - CONFIG_PROJECT_PATH_MISMATCH = ( - "CONFIG_PROJECT_PATH_MISMATCH", - "The project path declared in config.yaml does not match the project root observed. A declared path " - "probed as missing may also be an unreachable network location or a path from another platform.", - Severity.NOTE, - ("declared_project_path", "observed_project_root", "declared_path_probe", "error_type", "error_message"), - ) - CONFIG_PROJECT_PATH_NOT_ABSOLUTE = ( - "CONFIG_PROJECT_PATH_NOT_ABSOLUTE", - "The project path in config.yaml is missing, empty or relative, and cannot be compared with the project root.", - Severity.NOTE, - ("declared_project_path",), - ) - - -class ConfiguredVideoFindingCode(FindingCode): - """Findings about video paths declared in ``config.yaml``.""" - - CONFIGURED_VIDEO_PATH_MISSING = ( - "CONFIGURED_VIDEO_PATH_MISSING", - "The configured video path does not exist.", - Severity.ERROR, - (), - ) - CONFIGURED_VIDEO_PATH_SYMLINK_TARGET_MISSING = ( - "CONFIGURED_VIDEO_PATH_SYMLINK_TARGET_MISSING", - "The configured video path is a symlink whose target does not exist.", - Severity.ERROR, - ("raw_target", "absolute_target"), - ) - CONFIGURED_VIDEO_PATH_UNREADABLE = ( - "CONFIGURED_VIDEO_PATH_UNREADABLE", - "The configured video path could not be read.", - Severity.ERROR, - ("error_type", "error_message"), - ) - CONFIGURED_VIDEO_PATH_NOT_FILE = ( - "CONFIGURED_VIDEO_PATH_NOT_FILE", - "The configured video path exists but is not a file.", - Severity.ERROR, - (), - ) - CONFIGURED_VIDEOS_UNDER_MISSING_ROOT = ( - "CONFIGURED_VIDEOS_UNDER_MISSING_ROOT", - "Configured video paths end in videos/, the video exists in this project, but the paths " - "themselves do not exist. Was the project moved or copied?", - Severity.WARNING, - ("declared_paths", "matched_paths"), - ) - CONFIGURED_VIDEO_IN_OTHER_COPY = ( - "CONFIGURED_VIDEO_IN_OTHER_COPY", - "The configured video path ends in videos/ and exists, but is a different file from this " - "project's video with the same name. DeepLabCut will read the configured one.", - Severity.WARNING, - ("matched_path",), - ) - CONFIGURED_VIDEO_OUTSIDE_PROJECT = ( - "CONFIGURED_VIDEO_OUTSIDE_PROJECT", - "The configured video path exists but is not in the project's videos directory.", - Severity.ERROR, - (), - ) - VIDEO_NOT_IN_VIDEO_SETS = ( - "VIDEO_NOT_IN_VIDEO_SETS", - "A video in the project's videos directory has no corresponding path in the configuration.", - Severity.NOTE, - ("resource_kind",), - ) - - -class FingerprintFindingCode(FindingCode): - """Findings about file and frame fingerprints of requested project resources.""" - - FILE_FINGERPRINT_FAILED = ( - "FILE_FINGERPRINT_FAILED", - "A requested resource could not be file-fingerprinted.", - Severity.ERROR, - ("resource_kind", "error_type", "error_message"), - ) - FILE_FINGERPRINT_CHANGED = ( - "FILE_FINGERPRINT_CHANGED", - "A resource's file fingerprint differs from the one recorded for it, or it was not fingerprinted.", - Severity.WARNING, - ("recorded_sha256", "observed_sha256"), - ) - - -class LabeledDataFindingCode(FindingCode): - """Findings about the content of labeled-data files.""" - - LABELED_DATA_UNREADABLE = ( - "LABELED_DATA_UNREADABLE", - "A labeled-data file could not be read.", - Severity.ERROR, - ("resource_kind", "error_type", "error_message"), - ) - LABELED_DATA_H5_MULTI_KEY = ( - "LABELED_DATA_H5_MULTI_KEY", - "An H5 labels file holds several tables; one was read by declared precedence and the others were not.", - Severity.ERROR, - ("keys_found", "selected_key"), - ) - LABELED_DATA_H5_LEGACY_KEY = ( - "LABELED_DATA_H5_LEGACY_KEY", - "An H5 labels file stores its table under a key older DeepLabCut releases wrote.", - Severity.WARNING, - ("key",), - ) - LABELED_DATA_H5_UNKNOWN_KEY = ( - "LABELED_DATA_H5_UNKNOWN_KEY", - "An H5 labels file stores its table under a key no DeepLabCut release is known to write.", - Severity.WARNING, - ("key",), - ) - LABELED_DATA_HEADER_UNRECOGNISED = ( - "LABELED_DATA_HEADER_UNRECOGNISED", - "A labels file's column levels are neither of the headers DeepLabCut writes, so no labels can be read from it.", - Severity.ERROR, - ("level_names",), - ) - LABELED_DATA_COORDS_UNRECOGNISED = ( - "LABELED_DATA_COORDS_UNRECOGNISED", - "Keypoints whose coordinates are not exactly x, y and optionally likelihood, so no labels can be read from " - "the file.", - Severity.ERROR, - ("keypoints",), - ) - LABELED_DATA_LIKELIHOOD_PARTIAL = ( - "LABELED_DATA_LIKELIHOOD_PARTIAL", - "Some keypoints store a likelihood and these do not, so no labels can be read from the file.", - Severity.ERROR, - ("keypoints",), - ) - LABELED_DATA_VALUES_NOT_NUMERIC = ( - "LABELED_DATA_VALUES_NOT_NUMERIC", - "Value columns hold something other than real numbers, so no labels can be read from the file.", - Severity.ERROR, - ("columns",), - ) - LABELED_DATA_NO_FRAMES = ( - "LABELED_DATA_NO_FRAMES", - "A labels file has a header and no frames, so it holds no labels.", - Severity.WARNING, - (), - ) - LABELED_DATA_ROW_INDEX_UNRECOGNISED = ( - "LABELED_DATA_ROW_INDEX_UNRECOGNISED", - "A labels file's row index is neither frame path parts nor path strings, so no labels can be read from it.", - Severity.ERROR, - ("first_entry",), - ) - LABELED_DATA_FRAME_DEPTH = ( - "LABELED_DATA_FRAME_DEPTH", - "Frames whose path has other than three parts, so no labels can be read from the file.", - Severity.ERROR, - ("row_count", "first_frame"), - ) - LABELED_DATA_FRAME_PART_UNNAMED = ( - "LABELED_DATA_FRAME_PART_UNNAMED", - "Frames with a path part that is neither text nor an integer, so no labels can be read from the file.", - Severity.ERROR, - ("row_count", "first_frame"), - ) - LABELED_DATA_CSV_FRAME_ABSORBED = ( - "LABELED_DATA_CSV_FRAME_ABSORBED", - "A CSV labels file's first frame has no values, so a CSV read takes it as the row index's names and the " - "file reads back without that frame.", - Severity.WARNING, - ("frame",), - ) - LABELED_DATA_WRITER_STAMP_MALFORMED = ( - "LABELED_DATA_WRITER_STAMP_MALFORMED", - "A labels file carries a writer stamp that could not be read.", - Severity.NOTE, - ("error_message",), - ) - LABELED_DATA_HUMAN_LIKELIHOOD = ( - "LABELED_DATA_HUMAN_LIKELIHOOD", - "Human labels store a likelihood, which ground truth never carries.", - Severity.WARNING, - (), - ) - LABELED_DATA_KEYPOINT_MISSING = ( - "LABELED_DATA_KEYPOINT_MISSING", - "Individuals lack a bodypart another individual of the same scorer has.", - Severity.WARNING, - ("missing",), - ) - LABELED_DATA_INDIVIDUAL_EMPTY = ( - "LABELED_DATA_INDIVIDUAL_EMPTY", - "Keypoints whose individual is named with an empty string, which names no individual.", - Severity.ERROR, - ("keypoints",), - ) - - def iter_finding_codes() -> tuple[FindingCode, ...]: """Return every declared finding code, namespace by namespace.""" diff --git a/dlccore/project/schemas/base/findings.py b/dlccore/project/schemas/base/findings.py index cf651aa..f5a7f83 100644 --- a/dlccore/project/schemas/base/findings.py +++ b/dlccore/project/schemas/base/findings.py @@ -1,4 +1,14 @@ -# schemas/base/findings.py +# +# DeepLabCut Toolbox (deeplabcut.org) +# © A. & M.W. Mathis Labs +# https://github.com/DeepLabCut/dlccore +# +# Contributors: +# https://github.com/DeepLabCut/dlccore/graphs/contributors +# +# Licensed under GNU Lesser General Public License v3.0 +# + """Simple diagnostic facts generated from walking through the project structure. These are the main enablers for downstream reporting, consumption by GUI/CLI/LLM agents, @@ -10,16 +20,12 @@ from enum import Enum from pathlib import Path -from typing import TYPE_CHECKING from pydantic import Field, JsonValue, model_validator from typing_extensions import Self -from dlc_octopus.schemas.base.core import FrozenModel, LayoutInstance, SchemaId -from dlc_octopus.schemas.base.finding_codes import FindingCode, Severity, finding_code - -if TYPE_CHECKING: - from IPython.lib.pretty import RepresentationPrinter +from dlccore.project.schemas.base.core import FrozenModel, LayoutInstance, SchemaId +from dlccore.project.schemas.base.finding_codes import FindingCode, Severity, finding_code class Reach(str, Enum): @@ -94,16 +100,3 @@ def _check_reach(self) -> Self: raise ValueError(f"Reach {self.reach.name} names one instance, but got none.") return self - - # Display hooks only IPython and Jupyter call; repr, str and serialization stay pydantic's. - # Imported on call so that schemas never load visualization. - - def _repr_pretty_(self, printer: RepresentationPrinter, cycle: bool) -> None: # noqa: FBT001 - IPython's signature - from dlc_octopus.visualization.findings import render_finding - - printer.text("Finding(...)" if cycle else render_finding(self)) - - def _repr_markdown_(self) -> str: - from dlc_octopus.visualization.findings import render_finding - - return render_finding(self, style="markdown") diff --git a/pyproject.toml b/pyproject.toml index debf6c6..a54dffd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,7 @@ dynamic = [ "version" ] dependencies = [ "numpy>=1.22.4", "pandas>=2.3.3", - "pydantic>=2.1,<3", + "pydantic>=2.5.2,<3", "ruamel-yaml>=0.16", "typing-extensions", ] diff --git a/tests/project/schemas/test_finding_codes.py b/tests/project/schemas/test_finding_codes.py index 836963a..c7cde59 100644 --- a/tests/project/schemas/test_finding_codes.py +++ b/tests/project/schemas/test_finding_codes.py @@ -1,3 +1,14 @@ +# +# DeepLabCut Toolbox (deeplabcut.org) +# © A. & M.W. Mathis Labs +# https://github.com/DeepLabCut/dlccore +# +# Contributors: +# https://github.com/DeepLabCut/dlccore/graphs/contributors +# +# Licensed under GNU Lesser General Public License v3.0 +# + from __future__ import annotations import json @@ -5,19 +16,28 @@ import pytest from pydantic import ValidationError -from dlc_octopus.schemas.base.finding_codes import ( - ConfigFindingCode, - ConfiguredVideoFindingCode, - FindingCode, - FingerprintFindingCode, - LabeledDataFindingCode, - Severity, - StructureFindingCode, - iter_finding_codes, -) -from dlc_octopus.schemas.base.findings import Finding, Reach +from dlccore.project.schemas.base.finding_codes import FindingCode, Severity, iter_finding_codes +from dlccore.project.schemas.base.findings import Finding, Reach + + +class ExampleFindingCode(FindingCode): + """Declared by these tests; each real namespace lands with the check that first emits it.""" + + TEST_NODE_WRONG_TYPE = ( + "TEST_NODE_WRONG_TYPE", + "A project resource exists at the expected location but has the wrong filesystem type.", + Severity.ERROR, + ("resource_kind", "expected_type"), + ) + TEST_NODE_UNREADABLE = ( + "TEST_NODE_UNREADABLE", + "A project-layout node could not be read.", + Severity.ERROR, + ("resource_kind", "error_type", "error_message"), + ) + -_UNREADABLE = StructureFindingCode.PROJECT_NODE_UNREADABLE +_UNREADABLE = ExampleFindingCode.TEST_NODE_UNREADABLE _SCHEMA_ID = "dlc.videos.source_video" @@ -28,7 +48,7 @@ def _declared_evidence(code: FindingCode) -> dict[str, str]: def test_finding_keeps_a_declared_code_as_its_enum_member() -> None: - code = StructureFindingCode.PROJECT_NODE_WRONG_TYPE + code = ExampleFindingCode.TEST_NODE_WRONG_TYPE finding = Finding( code=code, @@ -38,15 +58,15 @@ def test_finding_keeps_a_declared_code_as_its_enum_member() -> None: ) assert finding.code is code - assert finding.code == "PROJECT_NODE_WRONG_TYPE" + assert finding.code == "TEST_NODE_WRONG_TYPE" def test_finding_code_renders_as_the_bare_code() -> None: - code = StructureFindingCode.PROJECT_NODE_WRONG_TYPE + code = ExampleFindingCode.TEST_NODE_WRONG_TYPE - assert str(code) == "PROJECT_NODE_WRONG_TYPE" - assert f"{code}" == "PROJECT_NODE_WRONG_TYPE" - assert ", ".join([code]) == "PROJECT_NODE_WRONG_TYPE" + assert str(code) == "TEST_NODE_WRONG_TYPE" + assert f"{code}" == "TEST_NODE_WRONG_TYPE" + assert ", ".join([code]) == "TEST_NODE_WRONG_TYPE" def test_finding_rejects_an_undeclared_code() -> None: @@ -175,15 +195,12 @@ def test_training_split_reconciliation_declares_a_finding_code() -> None: def test_the_finding_code_catalogue_is_closed() -> None: - """The catalogue is closed: adding a namespace is deliberate, so it fails here first.""" - - assert set(FindingCode.__subclasses__()) == { - StructureFindingCode, - ConfigFindingCode, - ConfiguredVideoFindingCode, - FingerprintFindingCode, - LabeledDataFindingCode, - } + """Adding a namespace is deliberate, so it fails here first. Namespaces declared by tests are outside it.""" + + namespaces = set(FindingCode.__subclasses__()) + + assert ExampleFindingCode in namespaces + assert {namespace for namespace in namespaces if namespace.__module__.startswith("dlccore.")} == set() def test_severity_has_three_rungs() -> None: diff --git a/tests/project/schemas/test_layout_instance.py b/tests/project/schemas/test_layout_instance.py index c96ddbb..d7c20cf 100644 --- a/tests/project/schemas/test_layout_instance.py +++ b/tests/project/schemas/test_layout_instance.py @@ -1,3 +1,14 @@ +# +# DeepLabCut Toolbox (deeplabcut.org) +# © A. & M.W. Mathis Labs +# https://github.com/DeepLabCut/dlccore +# +# Contributors: +# https://github.com/DeepLabCut/dlccore/graphs/contributors +# +# Licensed under GNU Lesser General Public License v3.0 +# + from __future__ import annotations import json @@ -6,11 +17,23 @@ import pytest from pydantic import ValidationError -from dlc_octopus.schemas.base.core import instance_from_path -from dlc_octopus.schemas.base.finding_codes import StructureFindingCode -from dlc_octopus.schemas.base.findings import Finding, Reach +from dlccore.project.schemas.base.core import instance_from_path +from dlccore.project.schemas.base.finding_codes import FindingCode, Severity +from dlccore.project.schemas.base.findings import Finding, Reach + + +class InstanceFindingCode(FindingCode): + """Declared by these tests; each real namespace lands with the check that first emits it.""" + + TEST_INSTANCE_NODE_UNREADABLE = ( + "TEST_INSTANCE_NODE_UNREADABLE", + "A project-layout node could not be read.", + Severity.ERROR, + ("resource_kind", "error_type", "error_message"), + ) + -_CODE = StructureFindingCode.PROJECT_NODE_UNREADABLE +_CODE = InstanceFindingCode.TEST_INSTANCE_NODE_UNREADABLE _EVIDENCE = dict.fromkeys(_CODE.evidence_keys, "placeholder") _SCHEMA_ID = "dlc.labeled_data.dataset" From 10f234806694180f53f8a2e23334728c24cbc0e2 Mon Sep 17 00:00:00 2001 From: Cyril Achard Date: Thu, 26 Nov 2026 15:00:07 +0100 Subject: [PATCH 3/3] Keep the finding-code catalogue closed in tests - Declare the example namespace per test, through the example_codes fixture, and collect it before the next test runs, so no other test finds it in the catalogue - The closed-catalogue test asserts the exact set of namespaces again, with no exemption; a control shows the previous test's namespace is gone - Add test_only_error_blocks from tests/inspection/test_validation_error.py; its other tests need inspect_project --- tests/conftest.py | 46 ++++++++ .../inspection/test_validation_error.py | 19 ++++ tests/project/schemas/test_finding_codes.py | 101 +++++++++--------- tests/project/schemas/test_layout_instance.py | 44 ++++---- 4 files changed, 139 insertions(+), 71 deletions(-) create mode 100644 tests/project/inspection/test_validation_error.py diff --git a/tests/conftest.py b/tests/conftest.py index d52b0a8..c048e39 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,12 +9,15 @@ # Licensed under GNU Lesser General Public License v3.0 # +import gc import os from collections.abc import Callable from pathlib import Path import pytest +from dlccore.project.schemas.base.finding_codes import FindingCode, Severity + def _create_symlink_or_skip( link: Path, @@ -54,3 +57,46 @@ def stat_without_file_id(path: object, *args: object, **kwargs: object) -> os.st return os.stat_result((result[0], 0, *result[2:])) monkeypatch.setattr(os, "stat", stat_without_file_id) + + +def _declare_example_codes() -> type[FindingCode]: + class ExampleFindingCode(FindingCode): + """Declared for one test; each real namespace lands with the check that first emits it.""" + + TEST_NODE_WRONG_TYPE = ( + "TEST_NODE_WRONG_TYPE", + "A project resource exists at the expected location but has the wrong filesystem type.", + Severity.ERROR, + ("resource_kind", "expected_type"), + ) + TEST_NODE_UNREADABLE = ( + "TEST_NODE_UNREADABLE", + "A project-layout node could not be read.", + Severity.ERROR, + ("resource_kind", "error_type", "error_message"), + ) + + return ExampleFindingCode + + +_example_codes_declared = False + + +@pytest.fixture +def example_codes() -> type[FindingCode]: + """A finding-code namespace that exists for one test only, so the catalogue every other test sees stays closed.""" + + global _example_codes_declared + _example_codes_declared = True + + return _declare_example_codes() + + +def pytest_runtest_setup() -> None: + """Collect the example namespace an earlier test declared; an enum class lingers in a reference cycle.""" + + global _example_codes_declared + + if _example_codes_declared: + gc.collect() + _example_codes_declared = False diff --git a/tests/project/inspection/test_validation_error.py b/tests/project/inspection/test_validation_error.py new file mode 100644 index 0000000..db65e64 --- /dev/null +++ b/tests/project/inspection/test_validation_error.py @@ -0,0 +1,19 @@ +# +# DeepLabCut Toolbox (deeplabcut.org) +# © A. & M.W. Mathis Labs +# https://github.com/DeepLabCut/dlccore +# +# Contributors: +# https://github.com/DeepLabCut/dlccore/graphs/contributors +# +# Licensed under GNU Lesser General Public License v3.0 +# + +from __future__ import annotations + +from dlccore.project.errors import BLOCKING_SEVERITIES +from dlccore.project.schemas.base.finding_codes import Severity + + +def test_only_error_blocks() -> None: + assert {Severity.ERROR} == BLOCKING_SEVERITIES diff --git a/tests/project/schemas/test_finding_codes.py b/tests/project/schemas/test_finding_codes.py index c7cde59..47c163b 100644 --- a/tests/project/schemas/test_finding_codes.py +++ b/tests/project/schemas/test_finding_codes.py @@ -12,6 +12,7 @@ from __future__ import annotations import json +import weakref import pytest from pydantic import ValidationError @@ -19,25 +20,6 @@ from dlccore.project.schemas.base.finding_codes import FindingCode, Severity, iter_finding_codes from dlccore.project.schemas.base.findings import Finding, Reach - -class ExampleFindingCode(FindingCode): - """Declared by these tests; each real namespace lands with the check that first emits it.""" - - TEST_NODE_WRONG_TYPE = ( - "TEST_NODE_WRONG_TYPE", - "A project resource exists at the expected location but has the wrong filesystem type.", - Severity.ERROR, - ("resource_kind", "expected_type"), - ) - TEST_NODE_UNREADABLE = ( - "TEST_NODE_UNREADABLE", - "A project-layout node could not be read.", - Severity.ERROR, - ("resource_kind", "error_type", "error_message"), - ) - - -_UNREADABLE = ExampleFindingCode.TEST_NODE_UNREADABLE _SCHEMA_ID = "dlc.videos.source_video" @@ -47,8 +29,8 @@ def _declared_evidence(code: FindingCode) -> dict[str, str]: return dict.fromkeys(code.evidence_keys, "placeholder") -def test_finding_keeps_a_declared_code_as_its_enum_member() -> None: - code = ExampleFindingCode.TEST_NODE_WRONG_TYPE +def test_finding_keeps_a_declared_code_as_its_enum_member(example_codes: type[FindingCode]) -> None: + code = example_codes.TEST_NODE_WRONG_TYPE finding = Finding( code=code, @@ -61,8 +43,8 @@ def test_finding_keeps_a_declared_code_as_its_enum_member() -> None: assert finding.code == "TEST_NODE_WRONG_TYPE" -def test_finding_code_renders_as_the_bare_code() -> None: - code = ExampleFindingCode.TEST_NODE_WRONG_TYPE +def test_finding_code_renders_as_the_bare_code(example_codes: type[FindingCode]) -> None: + code = example_codes.TEST_NODE_WRONG_TYPE assert str(code) == "TEST_NODE_WRONG_TYPE" assert f"{code}" == "TEST_NODE_WRONG_TYPE" @@ -78,57 +60,57 @@ def test_finding_rejects_an_undeclared_code() -> None: ) -def test_finding_severity_comes_from_its_code() -> None: +def test_finding_severity_comes_from_its_code(example_codes: type[FindingCode]) -> None: finding = Finding( - code=_UNREADABLE, + code=example_codes.TEST_NODE_UNREADABLE, schema_id=_SCHEMA_ID, reach=Reach.ONE_PER_PROJECT, - evidence=_declared_evidence(_UNREADABLE), + evidence=_declared_evidence(example_codes.TEST_NODE_UNREADABLE), ) assert finding.severity is Severity.ERROR assert finding.model_dump()["severity"] == Severity.ERROR -def test_finding_ignores_a_caller_supplied_severity() -> None: +def test_finding_ignores_a_caller_supplied_severity(example_codes: type[FindingCode]) -> None: finding = Finding( - code=_UNREADABLE, + code=example_codes.TEST_NODE_UNREADABLE, schema_id=_SCHEMA_ID, reach=Reach.ONE_PER_PROJECT, severity=Severity.NOTE, - evidence=_declared_evidence(_UNREADABLE), + evidence=_declared_evidence(example_codes.TEST_NODE_UNREADABLE), ) assert finding.severity is Severity.ERROR -def test_finding_requires_the_evidence_its_code_declares() -> None: +def test_finding_requires_the_evidence_its_code_declares(example_codes: type[FindingCode]) -> None: with pytest.raises(ValidationError, match="requires evidence keys"): Finding( - code=_UNREADABLE, + code=example_codes.TEST_NODE_UNREADABLE, schema_id=_SCHEMA_ID, reach=Reach.ONE_PER_PROJECT, ) -def test_finding_reports_only_the_missing_evidence_keys() -> None: - partial = _declared_evidence(_UNREADABLE) +def test_finding_reports_only_the_missing_evidence_keys(example_codes: type[FindingCode]) -> None: + partial = _declared_evidence(example_codes.TEST_NODE_UNREADABLE) del partial["error_message"] with pytest.raises(ValidationError, match=r"\('error_message',\)"): Finding( - code=_UNREADABLE, + code=example_codes.TEST_NODE_UNREADABLE, schema_id=_SCHEMA_ID, reach=Reach.ONE_PER_PROJECT, evidence=partial, ) -def test_finding_accepts_declared_evidence_that_was_not_observed() -> None: - evidence: dict[str, str | None] = dict.fromkeys(_UNREADABLE.evidence_keys, None) +def test_finding_accepts_declared_evidence_that_was_not_observed(example_codes: type[FindingCode]) -> None: + evidence: dict[str, str | None] = dict.fromkeys(example_codes.TEST_NODE_UNREADABLE.evidence_keys, None) finding = Finding( - code=_UNREADABLE, + code=example_codes.TEST_NODE_UNREADABLE, schema_id=_SCHEMA_ID, reach=Reach.ONE_PER_PROJECT, evidence=evidence, @@ -137,18 +119,18 @@ def test_finding_accepts_declared_evidence_that_was_not_observed() -> None: assert finding.evidence["error_message"] is None -def test_finding_round_trips_through_serialized_form() -> None: +def test_finding_round_trips_through_serialized_form(example_codes: type[FindingCode]) -> None: finding = Finding( - code=_UNREADABLE, + code=example_codes.TEST_NODE_UNREADABLE, schema_id=_SCHEMA_ID, reach=Reach.ONE_PER_PROJECT, - evidence=_declared_evidence(_UNREADABLE), + evidence=_declared_evidence(example_codes.TEST_NODE_UNREADABLE), ) restored = Finding.model_validate(json.loads(finding.model_dump_json())) assert restored == finding - assert restored.code is _UNREADABLE + assert restored.code is example_codes.TEST_NODE_UNREADABLE def test_finding_rejects_an_undeclared_code_from_serialized_form() -> None: @@ -171,12 +153,14 @@ def test_every_finding_code_declares_well_formed_evidence_keys(code: FindingCode assert all(key and key.islower() for key in code.evidence_keys) +@pytest.mark.usefixtures("example_codes") def test_finding_code_values_are_unique_across_namespaces() -> None: codes = iter_finding_codes() assert len({code.value for code in codes}) == len(codes) +@pytest.mark.usefixtures("example_codes") def test_iter_finding_codes_covers_every_namespace() -> None: namespaces = {type(code) for code in iter_finding_codes()} @@ -194,13 +178,25 @@ def test_training_split_reconciliation_declares_a_finding_code() -> None: assert "TRAINING_SPLIT_TABLE_MISMATCH" in {code.value for code in iter_finding_codes()} -def test_the_finding_code_catalogue_is_closed() -> None: - """Adding a namespace is deliberate, so it fails here first. Namespaces declared by tests are outside it.""" +_example_namespace: list[weakref.ref[type[FindingCode]]] = [] + - namespaces = set(FindingCode.__subclasses__()) +def test_an_example_namespace_is_in_the_catalogue_during_its_test(example_codes: type[FindingCode]) -> None: + _example_namespace.append(weakref.ref(example_codes)) - assert ExampleFindingCode in namespaces - assert {namespace for namespace in namespaces if namespace.__module__.startswith("dlccore.")} == set() + assert example_codes in FindingCode.__subclasses__() + + +def test_an_example_namespace_leaves_the_catalogue_after_its_test() -> None: + # Control for the closed-catalogue test below: the previous test's namespace is gone, not exempted. + assert _example_namespace + assert _example_namespace[0]() is None + + +def test_the_finding_code_catalogue_is_closed() -> None: + """The catalogue is closed: adding a namespace is deliberate, so it fails here first.""" + + assert set(FindingCode.__subclasses__()) == set() def test_severity_has_three_rungs() -> None: @@ -218,11 +214,17 @@ def test_instance_is_a_finding_field() -> None: assert "instance" in Finding.model_fields -def test_a_finding_states_its_reach() -> None: - evidence = _declared_evidence(_UNREADABLE) +def test_a_finding_states_its_reach(example_codes: type[FindingCode]) -> None: + evidence = _declared_evidence(example_codes.TEST_NODE_UNREADABLE) def finding(reach: Reach, instance: tuple[str, ...]) -> Finding: - return Finding(code=_UNREADABLE, schema_id=_SCHEMA_ID, reach=reach, instance=instance, evidence=evidence) + return Finding( + code=example_codes.TEST_NODE_UNREADABLE, + schema_id=_SCHEMA_ID, + reach=reach, + instance=instance, + evidence=evidence, + ) assert {member.name for member in Reach} == {"ONE_PER_PROJECT", "ONE_OF", "ALL_OF", "UNROOTED"} @@ -247,5 +249,6 @@ def finding(reach: Reach, instance: tuple[str, ...]) -> Finding: strict=True, raises=AssertionError, ) +@pytest.mark.usefixtures("example_codes") def test_a_released_code_cannot_disappear_without_a_successor() -> None: assert all(hasattr(code, "supersedes") for code in iter_finding_codes()) diff --git a/tests/project/schemas/test_layout_instance.py b/tests/project/schemas/test_layout_instance.py index d7c20cf..4f8d406 100644 --- a/tests/project/schemas/test_layout_instance.py +++ b/tests/project/schemas/test_layout_instance.py @@ -18,50 +18,48 @@ from pydantic import ValidationError from dlccore.project.schemas.base.core import instance_from_path -from dlccore.project.schemas.base.finding_codes import FindingCode, Severity +from dlccore.project.schemas.base.finding_codes import FindingCode from dlccore.project.schemas.base.findings import Finding, Reach +_SCHEMA_ID = "dlc.labeled_data.dataset" -class InstanceFindingCode(FindingCode): - """Declared by these tests; each real namespace lands with the check that first emits it.""" - TEST_INSTANCE_NODE_UNREADABLE = ( - "TEST_INSTANCE_NODE_UNREADABLE", - "A project-layout node could not be read.", - Severity.ERROR, - ("resource_kind", "error_type", "error_message"), - ) +@pytest.fixture +def code(example_codes: type[FindingCode]) -> FindingCode: + return example_codes.TEST_NODE_UNREADABLE -_CODE = InstanceFindingCode.TEST_INSTANCE_NODE_UNREADABLE -_EVIDENCE = dict.fromkeys(_CODE.evidence_keys, "placeholder") -_SCHEMA_ID = "dlc.labeled_data.dataset" +@pytest.fixture +def evidence(code: FindingCode) -> dict[str, str]: + return dict.fromkeys(code.evidence_keys, "placeholder") -def test_a_finding_has_no_instance_by_default() -> None: - assert Finding(code=_CODE, schema_id=_SCHEMA_ID, reach=Reach.ONE_PER_PROJECT, evidence=_EVIDENCE).instance == () +def test_a_finding_has_no_instance_by_default(code: FindingCode, evidence: dict[str, str]) -> None: + assert Finding(code=code, schema_id=_SCHEMA_ID, reach=Reach.ONE_PER_PROJECT, evidence=evidence).instance == () -def test_an_instance_serializes_as_a_plain_list() -> None: +def test_an_instance_serializes_as_a_plain_list(code: FindingCode, evidence: dict[str, str]) -> None: finding = Finding( - code=_CODE, schema_id=_SCHEMA_ID, reach=Reach.ONE_OF, instance=("labeled-data", "ds1"), evidence=_EVIDENCE + code=code, schema_id=_SCHEMA_ID, reach=Reach.ONE_OF, instance=("labeled-data", "ds1"), evidence=evidence ) assert json.loads(finding.model_dump_json())["instance"] == ["labeled-data", "ds1"] @pytest.mark.parametrize("segment", ["", "labeled-data/ds1"], ids=["empty", "joined"]) -def test_an_instance_refuses_a_segment_only_a_caller_can_produce(segment: str) -> None: +def test_an_instance_refuses_a_segment_only_a_caller_can_produce( + segment: str, code: FindingCode, evidence: dict[str, str] +) -> None: with pytest.raises(ValidationError, match="project-relative path segment"): Finding( - code=_CODE, schema_id=_SCHEMA_ID, reach=Reach.ONE_OF, instance=("labeled-data", segment), evidence=_EVIDENCE + code=code, schema_id=_SCHEMA_ID, reach=Reach.ONE_OF, instance=("labeled-data", segment), evidence=evidence ) @pytest.mark.parametrize("segment", ["..", "12:30.mp4", "a\\b.mp4"]) -def test_an_instance_keeps_user_data_segments(segment: str) -> None: +def test_an_instance_keeps_user_data_segments(segment: str, code: FindingCode, evidence: dict[str, str]) -> None: assert Finding( - code=_CODE, schema_id=_SCHEMA_ID, reach=Reach.ONE_OF, instance=("videos", segment), evidence=_EVIDENCE + code=code, schema_id=_SCHEMA_ID, reach=Reach.ONE_OF, instance=("videos", segment), evidence=evidence ).instance == ( "videos", segment, @@ -73,9 +71,11 @@ def test_an_instance_keeps_user_data_segments(segment: str) -> None: [("C:\\", "x.mp4"), ("\\\\server\\share\\", "x.mp4"), ("C:rel", "x.mp4")], ids=["drive-root", "unc-share", "drive-relative"], ) -def test_an_instance_refuses_segments_that_carry_a_drive_or_root(instance: tuple[str, ...]) -> None: +def test_an_instance_refuses_segments_that_carry_a_drive_or_root( + instance: tuple[str, ...], code: FindingCode, evidence: dict[str, str] +) -> None: with pytest.raises(ValidationError, match="project-relative"): - Finding(code=_CODE, schema_id=_SCHEMA_ID, reach=Reach.ONE_OF, instance=instance, evidence=_EVIDENCE) + Finding(code=code, schema_id=_SCHEMA_ID, reach=Reach.ONE_OF, instance=instance, evidence=evidence) def test_instance_from_path_splits_a_project_relative_path() -> None: