51 lines
1.8 KiB
Python
51 lines
1.8 KiB
Python
import unittest
|
|
|
|
from page_state import MarkerError, find_marker
|
|
|
|
|
|
VALID = "anwarpy: status=pending | access=free | category=نماذج | queued_at=2026-10-09T15:12:00+03:00"
|
|
|
|
|
|
class PageStateTests(unittest.TestCase):
|
|
def test_finds_one_exact_marker_after_unrelated_blocks(self):
|
|
result = find_marker([
|
|
{"id": "a", "text": "ملاحظات"},
|
|
{"id": "b", "text": VALID},
|
|
{"id": "c", "text": "مصدر عام"},
|
|
])
|
|
self.assertEqual(result.block_id, "b")
|
|
self.assertEqual(result.meta["status"], "pending")
|
|
|
|
def test_returns_none_when_anwarpy_is_never_mentioned(self):
|
|
self.assertIsNone(find_marker([{"id": "a", "text": "لا توجد علامة"}]))
|
|
|
|
def test_reports_every_near_miss(self):
|
|
for text in (
|
|
VALID.replace("anwarpy:", "Anwarpy:"),
|
|
"prefix " + VALID,
|
|
"documentation mentions anwarpy but has no marker",
|
|
VALID.replace("anwarpy:", "anwarpy ="),
|
|
):
|
|
with self.subTest(text=text):
|
|
with self.assertRaisesRegex(MarkerError, "near-miss"):
|
|
find_marker([{"id": "bad", "text": text}])
|
|
|
|
def test_scans_all_blocks_and_rejects_ambiguity(self):
|
|
with self.assertRaisesRegex(MarkerError, "multiple"):
|
|
find_marker([
|
|
{"id": "first", "text": VALID},
|
|
{"id": "middle", "text": "unrelated"},
|
|
{"id": "last", "text": VALID.replace("category=نماذج", "category=أدوات")},
|
|
])
|
|
|
|
def test_exact_plus_near_miss_is_ambiguous(self):
|
|
with self.assertRaisesRegex(MarkerError, "ambiguous"):
|
|
find_marker([
|
|
{"id": "good", "text": VALID},
|
|
{"id": "bad", "text": "Anwarpy: pending"},
|
|
])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|