any2human / tests /test_force_rewrite.py
idnameraj's picture
Upload 3155 files
67f284e verified
Raw
History Blame Contribute Delete
2.31 kB
"""Forced rule-based coverage fallback tests."""
from __future__ import annotations
from app.engine.force import force_cleft_rewrite
from app.engine.orchestrator import rewrite_document
SAMPLE = (
"Time management is an essential skill that helps individuals achieve "
"their personal and professional goals. Planning daily tasks and setting "
"priorities allow people to complete their work more efficiently.\n\n"
"Using calendars, to-do lists, and reminders can help organize "
"responsibilities and reduce stress. Avoiding procrastination and "
"focusing on one task at a time also improves productivity.\n\n"
"By managing time effectively, individuals can maintain a better "
"work-life balance and accomplish more with less pressure."
)
def test_force_cleft_rewrites_subject_predicate():
result = force_cleft_rewrite(
"Planning daily tasks allow people to complete their work more efficiently."
)
assert result
assert result.lower().startswith("it is planning")
assert "that" in result.lower()
assert result != (
"Planning daily tasks allow people to complete their work more efficiently."
)
def test_force_rewrite_changes_every_rewriteable_sentence():
result = rewrite_document(SAMPLE, force_rewrite=True, use_lexical_refinement=False)
rewriteable = [
record
for record in result.sentences
if record.original.strip()
and record.sentence_type
in {"simple_declarative", "compound", "complex", "because_clause"}
]
assert rewriteable
unchanged = [
record
for record in rewriteable
if record.rewritten.strip().lower().rstrip(".!?")
== record.original.strip().lower().rstrip(".!?")
]
assert not unchanged, [
(record.original, record.status, record.reasons) for record in unchanged
]
assert "Daily, planning tasks" not in result.text
assert result.stats.forced_rewrites >= 1
def test_force_rewrite_can_be_disabled():
result = rewrite_document(
"Using calendars can help organize responsibilities and reduce stress.",
force_rewrite=False,
use_lexical_refinement=False,
)
assert result.stats.forced_rewrites == 0