Skip to content

Commit

Permalink
No module Error
Browse files Browse the repository at this point in the history
  • Loading branch information
ConradKash committed Sep 7, 2023
1 parent c5b1c35 commit b7b8b88
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions app/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from fastapi.testclient import TestClient
from app.api import app
import json
from unittest.mock import MagicMock
from app.inference_services.translate import translate_text,create_payload_en_mul,inference_request_en_mul,predicted_language
from app.inference_services.translate import translate_text, predicted_language
client = TestClient(app)


Expand All @@ -14,29 +13,34 @@ def test_root_api():

def test_mul_mul(mocker):
fake_response_eng = MagicMock()
fake_response_eng = [{"generated_text":"Where are we heading?"}]
mocker.patch('app.inference_services.base.inference_request_mul_en', return_value=fake_response_eng)
fake_response_eng = [{"generated_text": "Where are we heading?"}]
mocker.patch('app.inference_services.base.inference_request_mul_en.reque'
'sts.post').return_value.text.return_value = fake_response_eng

fake_response_mul = MagicMock()
fake_response_mul = [{"generated_text":"Nituza nkahi?"}]
mocker.patch('app.inference_services.base.inference_request_en_mul', return_value=fake_response_mul)
fake_response_mul = [{"generated_text": "Nituza nkahi?"}]
mocker.patch('app.inference_services.base.inference_request_en_mul.reque'
'sts.post').return_value.text.return_value = fake_response_mul

assert translate_text('Tuli wa', 'lug', 'nyn') == 'Nituza nkahi?'



def test_mul_eng(mocker):
fake_response_eng = [{"generated_text":"Where are we heading?"}]
mocker.patch('app.inference_services.base.inference_request_mul_en', return_value=fake_response_eng)
# mocker.patch('app.inference_services.base.inference_request_mul_en.requests.post').return_value.text.return_value = fake_response_eng
fake_response_eng = [{"generated_text": "Where are we heading?"}]
mocker.patch('app.inference_services.base.inference_request_mul_en.reque'
'sts.post').return_value.text.return_value = fake_response_eng

assert translate_text('Tuli wa', 'lug',
'eng') == "Where are we heading?"

assert translate_text('Tuli wa', 'lug', 'eng') == "Where are we heading?"

def test_eng_mul(mocker):
fake_response_mul = [{"generated_text":"Nituza nkahi?"}]
mocker.patch('app.inference_services.base.inference_request_en_mul', return_value=fake_response_mul)
fake_response_mul = [{"generated_text": "Nituza nkahi?"}]
mocker.patch('app.inference_services.base.inference_request_mul_en.reque'
'sts.post').return_value.text.return_value = fake_response_mul

assert translate_text('Where are we heading?', 'eng', 'nyn') == "Nituza nkahi?"
assert translate_text('Where are we heading?',
'eng', 'nyn') == "Nituza nkahi?"


def test_language_detect():
Expand Down

0 comments on commit b7b8b88

Please sign in to comment.