test: add unit tests for make_detector factory (#48)#53
Merged
Conversation
Covers the previously-untested factory: - returns the correct detector class for each method (transformer, llm, rag_fact_checker), passing kwargs through - raises ValueError listing valid options on an unknown method Concrete detector classes are patched at their source modules (make_detector imports them lazily), so no model download is required, matching the mocking style in test_inference_pytest.py.
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.
Summary
Adds unit tests for
make_detector()inlettucedetect/detectors/factory.py, the first item suggested in #48. The factory is the public entry point used byHallucinationDetectorbut had no direct test coverage.Tests added
New file
tests/test_factory_pytest.py(follows the repo'stest_*_pytest.pynaming):method="transformer"→ returns aTransformerDetector, kwargs forwardedmethod="llm"→ returns anLLMDetector, kwargs forwardedmethod="rag_fact_checker"→ returns aRAGFactCheckerDetectorValueErrorlisting valid optionsEach concrete detector class is patched at its source module, so no model download or API key is needed — matching the mocking approach already used in
tests/test_inference_pytest.py.Verification
pytest tests/test_factory_pytest.py— 4 passedpytest tests/test_inference_pytest.py tests/test_factory_pytest.py -k "not TestAnswerStartToken"— 16 passed, 0 failed (no existing tests affected)ruff format --check+ruff check tests/— all cleanScope
Factory item from #48 only. No library/runtime code touched, no new dependencies.
Closes #48