mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-10 19:27:02 +01:00
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
38 lines
1.4 KiB
Python
38 lines
1.4 KiB
Python
"""The Dart and Kotlin copies of the workdays agree with ``freedays.WORKDAYS``.
|
|
|
|
The phone code cannot import the Python package that owns the definition, so
|
|
it keeps literal copies; this is the check that keeps them honest.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import re
|
|
|
|
import freedays
|
|
|
|
_PHONE = Path(__file__).resolve().parents[2] / "phone_app"
|
|
_KOTLIN = _PHONE / "android/app/src/main/kotlin/com/kuhy/wake_alarm_sync"
|
|
_NAMES = ("monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday")
|
|
|
|
|
|
def _weekdays(block: str) -> frozenset[int]:
|
|
"""Map the weekday names written in *block* to Python weekday() numbers."""
|
|
return frozenset(i for i, name in enumerate(_NAMES) if name in block.lower())
|
|
|
|
|
|
def test_dart_ramp_workdays() -> None:
|
|
"""``alarm_ramp.dart``'s ``workdays`` is ``freedays.WORKDAYS``."""
|
|
text = (_PHONE / "lib/services/alarm_ramp.dart").read_text()
|
|
match = re.search(r"const Set<int> workdays = \{(.*?)\};", text, re.DOTALL)
|
|
assert match is not None
|
|
assert _weekdays(match.group(1)) == freedays.WORKDAYS
|
|
|
|
|
|
def test_kotlin_workday_stick() -> None:
|
|
"""``WorkdayStick.kt``'s ``STICK_DAYS`` is ``freedays.WORKDAYS``."""
|
|
text = (_KOTLIN / "WorkdayStick.kt").read_text()
|
|
match = re.search(r"STICK_DAYS =\s*setOf\((.*?)\)", text, re.DOTALL)
|
|
assert match is not None
|
|
assert _weekdays(match.group(1)) == freedays.WORKDAYS
|