Skip to content

test: add unit tests for make_detector factory (#48)#53

Merged
adaamko merged 1 commit into
KRLabsOrg:mainfrom
gitcommit90:test/issue-48-factory-tests
Jun 24, 2026
Merged

test: add unit tests for make_detector factory (#48)#53
adaamko merged 1 commit into
KRLabsOrg:mainfrom
gitcommit90:test/issue-48-factory-tests

Conversation

@gitcommit90

Copy link
Copy Markdown
Contributor

Summary

Adds unit tests for make_detector() in lettucedetect/detectors/factory.py, the first item suggested in #48. The factory is the public entry point used by HallucinationDetector but had no direct test coverage.

Tests added

New file tests/test_factory_pytest.py (follows the repo's test_*_pytest.py naming):

  1. method="transformer" → returns a TransformerDetector, kwargs forwarded
  2. method="llm" → returns an LLMDetector, kwargs forwarded
  3. method="rag_fact_checker" → returns a RAGFactCheckerDetector
  4. unknown method → raises ValueError listing valid options

Each 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 passed
  • pytest 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 clean

Scope

Factory item from #48 only. No library/runtime code touched, no new dependencies.

Closes #48

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.
@adaamko adaamko merged commit 5230ee6 into KRLabsOrg:main Jun 24, 2026
2 checks passed
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.

Expand unit tests: factory, detector output formats, taxonomy cascade

2 participants