Test/add test modules#1
Merged
Merged
Conversation
There was a problem hiding this comment.
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 plainpytestinvocation 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 skipslowtests 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", | ||
| ) |
| class TestRegistry: | ||
| def test_detectors_registered(self): | ||
| names = list_detectors() | ||
| assert len(names) >= 24, f"Expected >=24 detectors, got {len(names)}: {names}" |
| 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)}" |
| (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()} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.