-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_translate.py
More file actions
78 lines (53 loc) · 2.36 KB
/
Copy pathtest_translate.py
File metadata and controls
78 lines (53 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import pytest
from unittest.mock import patch, MagicMock
from translate import translate_signal
# ---------- Hindi ----------
@patch("translate.translate_client")
def test_hindi_translation(mock_client):
mock_client.translate_text.return_value = {
"SourceLanguageCode": "hi",
"TranslatedText": "There is a big pothole on the road"
}
result = translate_signal("सड़क पर बड़ा गड्ढा है")
assert result["detected_language"] == "hi"
assert result["translated_content"] == "There is a big pothole on the road"
assert result["was_translated"] is True
# ---------- Tamil ----------
@patch("translate.translate_client")
def test_tamil_translation(mock_client):
mock_client.translate_text.return_value = {
"SourceLanguageCode": "ta",
"TranslatedText": "There is a large pothole"
}
result = translate_signal("சாலையில் பெரிய குழி உள்ளது")
assert result["detected_language"] == "ta"
assert result["translated_content"] == "There is a large pothole"
assert result["was_translated"] is True
# ---------- Telugu ----------
@patch("translate.translate_client")
def test_telugu_translation(mock_client):
mock_client.translate_text.return_value = {
"SourceLanguageCode": "te",
"TranslatedText": "Big pothole on the road"
}
result = translate_signal("రోడ్డుపై పెద్ద గుంత ఉంది")
assert result["detected_language"] == "te"
assert result["translated_content"] == "Big pothole on the road"
assert result["was_translated"] is True
# ---------- English (no translation) ----------
@patch("translate.translate_client")
def test_english_passthrough(mock_client):
mock_client.translate_text.return_value = {
"SourceLanguageCode": "en",
"TranslatedText": "Huge pothole on MG Road"
}
result = translate_signal("Huge pothole on MG Road")
assert result["detected_language"] == "en"
assert result["translated_content"] == "Huge pothole on MG Road"
assert result["was_translated"] is False
# ---------- Empty Content ----------
def test_empty_content_passthrough():
result = translate_signal("")
assert result["detected_language"] == "unknown"
assert result["translated_content"] == ""
assert result["was_translated"] is False