Skip to content

Commit

Permalink
Update test_translator.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamed-elzeni committed Nov 17, 2024
1 parent 4d5ee95 commit 5300ada
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/f24_translation-service-logic-lords.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install --quiet pytest ipytest pytest-mock mock
pip install sentence_transformers==3.3.0
- name: Run translation tests
Expand Down
18 changes: 14 additions & 4 deletions test/unit/test_translator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from src.translator import translate_content
from sentence_transformers import SentenceTransformer, util
from mock import patch
import openai

model = SentenceTransformer("all-MiniLM-L6-v2")

Expand All @@ -26,11 +28,18 @@ def eval_post(post: str, expected_answer: tuple[bool, str]):
def test_non_english1():
eval_post("Hier ist dein erstes Beispiel.", (False, "Here is your first example."))

@patch.object(openai.ChatCompletion, 'create')
def test_unexpected_language(mocker):
# we mock the model's response to return a random message
mocker.return_value.choices[0].message.content = "I don't understand your request"

def test_non_english2():
eval_post(
"बहुत से लोग नाश्ते में अनाज खाते हैं।", (False, "Many people eat cereal for breakfast.")
)
assert translate_content("Hier ist dein erstes Beispiel.") == (False, "LLM error: cannot translate content.")


# def test_non_english2():
# eval_post(
# "बहुत से लोग नाश्ते में अनाज खाते हैं।", (False, "Many people eat cereal for breakfast.")
# )


# def test_non_english3():
Expand Down Expand Up @@ -249,3 +258,4 @@ def test_non_english2():

# def test_gibberish35():
# eval_post("qwertyuiopasdfghjklzxcvbnm", (False, "LLM error: cannot translate content."))

0 comments on commit 5300ada

Please sign in to comment.