WritingStudio / tests /unit /test_rubric_service.py
jmisak's picture
Upload 41 files
aeb3f7c verified
"""Unit tests for rubric service."""
import pytest
from writing_studio.services.rubric_service import RubricService
class TestRubricService:
"""Tests for RubricService."""
@pytest.fixture
def service(self):
"""Create rubric service instance."""
return RubricService()
def test_analyze_empty_text(self, service):
"""Test analysis of empty text."""
results = service.analyze_text("")
assert all(data["score"] == 0 for data in results.values())
def test_analyze_valid_text(self, service):
"""Test analysis of valid text."""
text = """This is a clear and concise text. It demonstrates good writing.
Furthermore, it has proper organization. The sentences are well-structured.
According to research, good writing includes evidence."""
results = service.analyze_text(text)
assert "Clarity" in results
assert "Conciseness" in results
assert results["Clarity"]["score"] > 0
assert results["Clarity"]["max_score"] == 5
def test_score_clarity(self, service):
"""Test clarity scoring."""
# Short sentences - should get lower clarity
text = "Short. Very short. Too short."
score, _ = service._score_clarity(text)
assert score <= 3
# Good sentence length
text = "This is a well-structured sentence with appropriate length and clarity."
score, _ = service._score_clarity(text)
assert score >= 3
def test_score_conciseness(self, service):
"""Test conciseness scoring."""
# Wordy text
text = "In order to achieve the goal, due to the fact that we need results."
score, _ = service._score_conciseness(text)
assert score <= 3
def test_format_feedback(self, service):
"""Test feedback formatting."""
results = {
"Clarity": {"score": 4, "max_score": 5, "feedback": "Good clarity"},
}
feedback = service.format_feedback(results)
assert "Clarity: 4/5" in feedback
assert "Good clarity" in feedback