Skip to content

Test/add test modules#1

Merged
sadjadeb merged 9 commits into
mainfrom
test/add-test-modules
Jun 2, 2026
Merged

Test/add test modules#1
sadjadeb merged 9 commits into
mainfrom
test/add-test-modules

Conversation

@sadjadeb

@sadjadeb sadjadeb commented Jun 2, 2026

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a baseline pytest suite for DetectZoo’s core infrastructure (registry/base classes/results), datasets, benchmarks, and utility helpers, plus modality-specific detector tests (with “slow” tests intended for model/checkpoint downloads).

Changes:

  • Adds unit tests for core registry/base behavior, dataset implementations/registry, and benchmark evaluator behavior.
  • Adds detector registry/interface tests for text/image/audio modalities plus opt-in slow inference tests.
  • Adds utility tests for I/O helpers, metrics computation, and logger helper, plus shared pytest helpers/fixtures.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
tests/conftest.py Adds shared helpers/fixtures for tests (registry population, modality availability checks).
tests/test_core.py Tests core registry invariants, aliasing, and BaseDetector/DetectionResult behavior.
tests/test_datasets.py Tests dataset base classes, directory/CSV datasets, max-sampling, and dataset registry.
tests/test_benchmarks.py Tests BenchmarkEvaluator orchestration and JSON persistence without model downloads.
tests/test_utils.py Tests load_text, load_image, compute_metrics, and get_logger.
tests/test_text_detectors.py Tests text detector registry plus slow prediction smoke-tests (HF models).
tests/test_image_detectors.py Tests image detector registry/invariants and a slow CNNSpot predict smoke-test.
tests/test_audio_detectors.py Tests audio detector registry/invariants and a slow AASIST predict smoke-test.
tests/init.py Adds tests package marker file.
Comments suppressed due to low confidence (1)

tests/conftest.py:42

  • Tests marked with @pytest.mark.slow (model/checkpoint downloads) currently run by default, which will make a plain pytest invocation attempt large network downloads (e.g. HuggingFace models, Dropbox checkpoints) and can easily fail or time out in CI/offline environments. Add a small conftest hook to skip slow tests unless an explicit opt-in flag is provided (e.g. --runslow).
@pytest.fixture
def dummy_detector() -> DummyDetector:
    return DummyDetector(threshold=0.5)


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +3 to +7
Tests marked ``@pytest.mark.slow`` download HuggingFace models (``gpt2``)
and are skipped by default. Run with ``pytest -m slow`` to include them.
All slow tests pin the (tiny) ``gpt2`` model on CPU to stay practical —
detectors that use a separate reference model default to multi-billion
parameter models, so those must be overridden explicitly.
def test_predict(self):
from detectzoo.detectors.text.log_likelihood import LogLikelihoodDetector

det = LogLikelihoodDetector(model_name="gpt2", device="cpu")
def test_predict(self):
from detectzoo.detectors.text.log_rank import LogRankDetector

det = LogRankDetector(model_name="gpt2", device="cpu")
def test_predict(self):
from detectzoo.detectors.text.entropy import EntropyDetector

det = EntropyDetector(model_name="gpt2", device="cpu")
Comment on lines +71 to +75
det = FastDetectGPTDetector(
model_name="gpt2",
reference_model_name="gpt2",
device="cpu",
)
Comment thread tests/test_core.py
class TestRegistry:
def test_detectors_registered(self):
names = list_detectors()
assert len(names) >= 24, f"Expected >=24 detectors, got {len(names)}: {names}"
Comment thread tests/test_core.py
def test_text_detectors_present(self):
# Text detectors have no heavy optional deps, so they always load.
text = set(list_detectors("text"))
assert len(text) >= 18, f"Expected >=18 text detectors, got {sorted(text)}"
Comment thread tests/test_datasets.py
(real / "a.txt").write_text("r")
(fake / "b.txt").write_text("f")

items = {Path(it.data).name: it.label for it in SimpleDirectoryDataset(real, fake).load()}
@sadjadeb sadjadeb merged commit 4f6177f into main Jun 2, 2026
2 checks passed
@sadjadeb sadjadeb deleted the test/add-test-modules branch June 2, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants