From 5300ada1167888fcdedbae9bb55209a5c57b1d97 Mon Sep 17 00:00:00 2001 From: Mohamed Elzeni Date: Sun, 17 Nov 2024 21:19:20 +0300 Subject: [PATCH] Update test_translator.py --- .../f24_translation-service-logic-lords.yml | 1 + test/unit/test_translator.py | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/workflows/f24_translation-service-logic-lords.yml b/.github/workflows/f24_translation-service-logic-lords.yml index c3741aa..7583822 100644 --- a/.github/workflows/f24_translation-service-logic-lords.yml +++ b/.github/workflows/f24_translation-service-logic-lords.yml @@ -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 diff --git a/test/unit/test_translator.py b/test/unit/test_translator.py index 8c02a1b..2bc429f 100644 --- a/test/unit/test_translator.py +++ b/test/unit/test_translator.py @@ -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") @@ -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(): @@ -249,3 +258,4 @@ def test_non_english2(): # def test_gibberish35(): # eval_post("qwertyuiopasdfghjklzxcvbnm", (False, "LLM error: cannot translate content.")) +