Spaces:
Runtime error
Runtime error
File size: 4,368 Bytes
ce2ce69 |
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
import pytest
from app.services.translation import Translator
from app.services.tone_classification import ToneClassifier
from app.services.voice_detection import VoiceDetector
from app.services.gpt4_rewrite import GPT4Rewriter
from app.services.grammar import GrammarCorrector
from app.services.paraphrase import Paraphraser
from app.services.inclusive_language import InclusiveLanguageChecker
# --- Translation Tests ---
@pytest.fixture(scope="module")
def translator():
return Translator()
def test_translate_valid(translator):
response = translator.translate("Hello", "fr")
assert "result" in response
assert response["error"] is None
def test_translate_empty(translator):
response = translator.translate("", "fr")
assert response["result"] == ""
assert response["error"] == "Input text is empty."
def test_translate_invalid_lang(translator):
response = translator.translate("Hello", "xx")
assert "Unsupported target language" in response["error"]
# --- Tone Classification Tests ---
@pytest.fixture(scope="module")
def tone_classifier():
return ToneClassifier()
def test_tone_classify_valid(tone_classifier):
response = tone_classifier.classify("I am very happy today!")
assert "result" in response
assert response["error"] is None
def test_tone_classify_empty(tone_classifier):
response = tone_classifier.classify("")
assert response["result"] == ""
assert response["error"] == "Input text is empty."
# --- Voice Detection Tests ---
@pytest.fixture(scope="module")
def voice_detector():
return VoiceDetector()
def test_voice_classify_active(voice_detector):
response = voice_detector.classify("The dog chased the cat.")
assert response["result"] in ["Active", "Passive"]
assert response["error"] is None
def test_voice_classify_empty(voice_detector):
response = voice_detector.classify("")
assert response["result"] == ""
assert response["error"] == "Input text is empty."
# --- GPT-4 Rewrite Tests ---
@pytest.fixture(scope="module")
def gpt4_rewriter():
return GPT4Rewriter()
def test_gpt4_rewrite_valid(gpt4_rewriter):
response = gpt4_rewriter.rewrite(
"Rewrite this professionally.", "your_key_here", "You are a helpful assistant."
)
assert "result" in response or "error" in response
def test_gpt4_rewrite_missing_input(gpt4_rewriter):
response = gpt4_rewriter.rewrite("", "your_key_here", "instruction")
assert response["error"] == "Input text is empty."
def test_gpt4_rewrite_missing_key(gpt4_rewriter):
response = gpt4_rewriter.rewrite("Text", "", "instruction")
assert response["error"] == "Missing OpenAI API key."
def test_gpt4_rewrite_missing_instruction(gpt4_rewriter):
response = gpt4_rewriter.rewrite("Text", "your_key_here", "")
assert response["error"] == "Missing rewrite instruction."
# --- Grammar Correction Tests ---
@pytest.fixture(scope="module")
def grammar_corrector():
return GrammarCorrector()
def test_grammar_correct_valid(grammar_corrector):
response = grammar_corrector.correct("She go to school.")
assert "result" in response
assert response["error"] is None
def test_grammar_correct_empty(grammar_corrector):
response = grammar_corrector.correct("")
assert response["result"] == ""
assert response["error"] == "Input text is empty."
# --- Paraphraser Tests ---
@pytest.fixture(scope="module")
def paraphraser():
return Paraphraser()
def test_paraphrase_valid(paraphraser):
response = paraphraser.paraphrase("This is a test sentence.")
assert "result" in response
assert response["error"] is None
def test_paraphrase_empty(paraphraser):
response = paraphraser.paraphrase("")
assert response["result"] == ""
assert response["error"] == "Input text is empty."
# --- Inclusive Language Checker Tests ---
@pytest.fixture(scope="module")
def inclusive_checker():
return InclusiveLanguageChecker()
def test_inclusive_check_valid(inclusive_checker):
response = inclusive_checker.check("The chairman will arrive soon.")
assert "result" in response
assert isinstance(response["result"], list)
def test_inclusive_check_empty(inclusive_checker):
response = inclusive_checker.check("")
assert response["result"] == ""
assert response["error"] == "Input text is empty."
|