Skip to content

Commit

Permalink
added tests to get_language_info
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-pawelek committed Jan 29, 2025
1 parent 2cf55a3 commit 1ba75b4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
5 changes: 1 addition & 4 deletions llmtranslate/translator.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import asyncio
import json
import re
from langchain_core.prompts import ChatPromptTemplate
from pydantic import BaseModel, Field
from langchain_core.language_models import BaseChatModel
from llmtranslate.exceptions import MissingAPIKeyError, NoneAPIKeyProvidedError, InvalidModelName
from llmtranslate.utils.available_languages import get_language_info
from pydantic import BaseModel
from llmtranslate.utils.text_splitter import split_text_to_chunks, get_first_n_words
from abc import ABC, abstractmethod
from abc import ABC


MAX_LENGTH = 1000
Expand Down
41 changes: 41 additions & 0 deletions tests/test_available_languages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pytest

from llmtranslate import get_language_info


@pytest.mark.parametrize(
"identifier,expected",
[
# Valid inputs
("English", {
"language_name": "English",
"ISO_639_1_code": "en",
"ISO_639_2_code": "eng",
"ISO_639_3_code": "eng",
}),
("en", {
"language_name": "English",
"ISO_639_1_code": "en",
"ISO_639_2_code": "eng",
"ISO_639_3_code": "eng",
}),
("spa", {
"language_name": "Spanish",
"ISO_639_1_code": "es",
"ISO_639_2_code": "spa",
"ISO_639_3_code": "spa",
}),
("eng", {
"language_name": "English",
"ISO_639_1_code": "en",
"ISO_639_2_code": "eng",
"ISO_639_3_code": "eng",
}),
# Invalid inputs
("xyz", None),
("", None),
("123", None),
],
)
def test_get_language_info(identifier, expected):
assert get_language_info(identifier) == expected

0 comments on commit 1ba75b4

Please sign in to comment.