Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/konfai_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
run: pip install ruff==0.15.2

- name: Run ruff lint
run: ruff check konfai konfai-apps/konfai_apps
run: ruff check konfai konfai-apps/konfai_apps tests

format:
runs-on: ubuntu-latest
Expand All @@ -75,7 +75,7 @@ jobs:
run: pip install ruff==0.15.2

- name: Check formatting
run: ruff format --check konfai konfai-apps/konfai_apps
run: ruff format --check konfai konfai-apps/konfai_apps tests

build:
runs-on: ubuntu-latest
Expand Down
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ scikit-image = "*"
test = { cmd = "pytest -q tests/", description = "Run the test suite" }
test-apps = { cmd = "pytest -q konfai-apps/tests", description = "Run the konfai-apps test suite" }
test-cov = { cmd = "pytest --cov=konfai --cov-report=term-missing tests/", description = "Run tests with coverage" }
lint = { cmd = "ruff check konfai konfai-apps/konfai_apps", description = "Lint source code" }
format = { cmd = "ruff format konfai konfai-apps/konfai_apps", description = "Format source code" }
format-check = { cmd = "ruff format --check konfai konfai-apps/konfai_apps", description = "Check formatting without modifying files" }
lint = { cmd = "ruff check konfai konfai-apps/konfai_apps tests", description = "Lint source code" }
format = { cmd = "ruff format konfai konfai-apps/konfai_apps tests", description = "Format source code" }
format-check = { cmd = "ruff format --check konfai konfai-apps/konfai_apps tests", description = "Check formatting without modifying files" }
typecheck = { cmd = "python -m mypy konfai --ignore-missing-imports --no-site-packages", description = "Type-check the konfai package" }
build = { cmd = "python -m build", description = "Build sdist and wheel" }
check = { depends-on = ["lint", "format-check", "test", "test-apps"], description = "Run all quality checks" }
Expand All @@ -181,9 +181,9 @@ ruff = "==0.15.2"
pre-commit = "*"

[tool.pixi.feature.lint.tasks]
lint = { cmd = "ruff check konfai konfai-apps/konfai_apps", description = "Lint source code" }
format = { cmd = "ruff format konfai konfai-apps/konfai_apps", description = "Format source code" }
format-check = { cmd = "ruff format --check konfai konfai-apps/konfai_apps", description = "Check formatting without modifying files" }
lint = { cmd = "ruff check konfai konfai-apps/konfai_apps tests", description = "Lint source code" }
format = { cmd = "ruff format konfai konfai-apps/konfai_apps tests", description = "Format source code" }
format-check = { cmd = "ruff format --check konfai konfai-apps/konfai_apps tests", description = "Check formatting without modifying files" }
pre-commit-install = { cmd = "pre-commit install --hook-type pre-commit --hook-type commit-msg", description = "Install pre-commit and commit-msg hooks" }
pre-commit-run = { cmd = "pre-commit run --all-files", description = "Run pre-commit hooks on all repository files" }

Expand Down
1 change: 0 additions & 1 deletion tests/assets/Workflows/TinySynth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import torch

from konfai.network import network


Expand Down
63 changes: 63 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright (c) 2025 Valentin Boussot
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

"""Shared fixtures for the KonfAI test suite."""

from collections.abc import Callable
from pathlib import Path

import numpy as np
import pytest


@pytest.fixture(autouse=True)
def _konfai_env(monkeypatch: pytest.MonkeyPatch) -> None:
"""Harmless per-test defaults for the mandatory KONFAI environment variables.

``Config()`` requires ``KONFAI_config_file`` and ``KONFAI_CONFIG_MODE`` (AGENTS.md §7).
Tests that exercise the config engine override these with ``monkeypatch.setenv``.
"""
monkeypatch.setenv("KONFAI_config_file", "/tmp/konfai-none.yml")
monkeypatch.setenv("KONFAI_CONFIG_MODE", "Done")


@pytest.fixture
def write_config(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Callable[..., Path]:
"""Write a YAML config to ``tmp_path`` and point the KONFAI env vars at it."""

def write(content: str, *, mode: str = "Done", name: str = "config.yml") -> Path:
config_path = tmp_path / name
config_path.write_text(content, encoding="utf-8")
monkeypatch.setenv("KONFAI_config_file", str(config_path))
monkeypatch.setenv("KONFAI_CONFIG_MODE", mode)
return config_path

return write


@pytest.fixture
def image_attributes():
"""Factory for an ``Attribute`` carrying Origin/Spacing/Direction geometry."""
from konfai.utils.dataset import Attribute

def make(origin: list[float], spacing: list[float]) -> Attribute:
attributes = Attribute()
attributes["Origin"] = np.asarray(origin, dtype=np.float64)
attributes["Spacing"] = np.asarray(spacing, dtype=np.float64)
attributes["Direction"] = np.eye(len(origin), dtype=np.float64).reshape(-1)
return attributes

return make
7 changes: 3 additions & 4 deletions tests/integration/test_konfai_core_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@

import numpy as np
import pytest

from konfai.evaluator import build_evaluate
from konfai.predictor import build_predict
from konfai.trainer import build_train

pytestmark = pytest.mark.integration

ASSETS_DIR = Path(__file__).resolve().parents[1] / "assets" / "Workflows"
REPO_ROOT = Path(__file__).resolve().parents[2]
SimpleITK = pytest.importorskip("SimpleITK")
Expand Down Expand Up @@ -219,9 +220,7 @@ def main() -> None:

if __name__ == "__main__":
main()
""".replace(
"__TRAIN_NAME__", train_name
)
""".replace("__TRAIN_NAME__", train_name)
),
encoding="utf-8",
)
Expand Down
Loading
Loading