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

Add translator tests #46

Open
wants to merge 4 commits into
base: f24
Choose a base branch
from
Open
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
20 changes: 17 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ jobs:
services:
redis:
image: 'redis:7.2.4'
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps port 6379 on service container to the host
- 6379:6379

steps:
Expand Down Expand Up @@ -58,7 +56,6 @@ jobs:
"admin:email": "[email protected]",
"admin:password": "hAN3Eg8W",
"admin:password:confirm": "hAN3Eg8W",

"database": "redis",
"redis:host": "127.0.0.1",
"redis:port": 6379,
Expand All @@ -85,3 +82,20 @@ jobs:

- name: Test coverage
uses: coverallsapp/github-action@v2

# Python setup and run for Translator Tests
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.8' # Adjust to your version

- name: Install Python dependencies
run: |
python -m venv .venv
source .venv/bin/activate
pip install -r translator-service/requirements.txt

- name: Run Translator Tests
run: |
source .venv/bin/activate
pytest test/unit/test_translator.py # Adjust path if necessary
35 changes: 35 additions & 0 deletions test/translator_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from unittest.mock import Mock, patch
import unittest

class TestTranslator(unittest.TestCase):
def test_llm_normal_response(self):
"""Test normal LLM response"""
with patch('openai.AzureOpenAI') as mock_client:
mock_responses = [
Mock(choices=[Mock(message=Mock(content="No"))]), # Language detection
Mock(choices=[Mock(message=Mock(content="Hello world"))]), # Translation
]
mock_client.return_value.chat.completions.create.side_effect = mock_responses

# Test translation
is_english, translation = translate("Hallo Welt")

self.assertEqual(is_english, False)
self.assertEqual(translation, "Hello world")

def test_llm_gibberish_response(self):
"""Test handling of gibberish input"""
with patch('openai.AzureOpenAI') as mock_client:
# Mock an unexpected response
mock_client.return_value.chat.completions.create.return_value = Mock(
choices=[Mock(message=Mock(content="I don't understand"))]
)

# Test translation of gibberish
is_english, translation = translate("asdfghjkl")

self.assertEqual(is_english, False)
self.assertEqual(translation, "Error: Could not determine language")

if __name__ == '__main__':
unittest.main()
Loading