Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F13 136 il add more tests for language detection task #748

Merged
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ repos:
args:
[
"-L",
"newyorker,te,responde,ist,als,oder,technik,sie,rouge,unter,juli,fiel,couldn,mke, vor",
"newyorker,te,responde,ist,als,oder,technik,sie,rouge,unter,juli,fiel,couldn,mke, vor,fille,ans",
]
exclude: '^(poetry\.lock|trace-viewer/.*|tests/connectors/retrievers/test_document_index_retriever\.py|src/intelligence_layer/use_cases/qa/multiple_chunk_qa.py|src/intelligence_layer/use_cases/summarize/.*|tests/connectors/retrievers/test_document_index_retriever\.py|src/intelligence_layer/use_cases/classify/keyword_extract.py|tests/use_cases/summarize/test_single_chunk_few_shot_summarize.py|tests/use_cases/summarize/very_long_text.txt)$'
- repo: https://github.com/akaihola/darglint2
Expand Down
49 changes: 45 additions & 4 deletions tests/core/test_detect_language.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

from intelligence_layer.core import (
DetectLanguage,
DetectLanguageInput,
Expand All @@ -6,14 +8,53 @@
)


def test_detect_language_returns_correct_language() -> None:
text = "Hello, my name is Niklas. I am working with Pit on this language detection piece."
@pytest.mark.parametrize(
"text_input,expected_language",
[
(
"Hello, my name is Niklas. I am working with Pit on this language detection piece.",
Language("en"),
),
(
"Hola, mi nombre es Niklas. Estoy trabajando con Pit en esta pieza de detección de idioma.",
Language("es"),
),
(
"Ciao, mi chiamo Niklas. Sto lavorando con Pit su questo pezzo di rilevamento della lingua.",
Language("it"),
),
(
"Hallo, mein Name ist Niklas. Ich arbeite mit Pit an diesem Stück zur Spracherkennung.",
Language("de"),
),
(
"Bonjour, je m'appelle Niklas. Je travaille avec Pit sur cette pièce de détection de langue.",
Language("fr"),
),
],
)
def test_detect_language_returns_correct_language(
text_input: str, expected_language: Language
) -> None:
task = DetectLanguage()
input = DetectLanguageInput(
text=text,
text=text_input,
possible_languages=[Language(lang) for lang in ["en", "de", "fr", "it", "es"]],
)
tracer = NoOpTracer()
output = task.run(input, tracer)

assert output.best_fit == Language("en")
assert output.best_fit == expected_language


def test_detect_language_returns_non_if_no_language_can_be_detected() -> None:
text = "Je m’appelle Jessica. Je suis une fille, je suis française et j’ai treize ans." # codespell:ignore
task = DetectLanguage()
input = DetectLanguageInput(
text=text,
possible_languages=[Language(lang) for lang in ["en", "de"]],
)
tracer = NoOpTracer()
output = task.run(input, tracer)

assert output.best_fit is None