Every 25 minutes a fullscreen break screen (one per monitor) guides you through eye exercises and then a walk. You can snooze it for 2 minutes or skip it. A scratchpad, focused as soon as the break starts, records what you were in the middle of and shows it back when the break ends. - Python + GTK 4 + libadwaita, runs in the background as a GApplication - CLI: now, snooze, skip, off/on, status, notes, stats, config, quit - Idle and suspend detection through Mutter's IdleMonitor - Warning notification with Snooze / Take it now buttons - install.sh for a per-user install with autostart and an app-grid entry - Unit tests for the scheduler, notes and exercise plan Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AVT21e1qRMx6WM5n8eoLNA
81 lines
3.2 KiB
Python
81 lines
3.2 KiB
Python
import datetime
|
|
import os
|
|
import tempfile
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
from pause import config, exercises, notes
|
|
|
|
|
|
class NotesTest(unittest.TestCase):
|
|
def setUp(self):
|
|
self.tmp = tempfile.TemporaryDirectory()
|
|
patcher = mock.patch.dict(os.environ, {"XDG_DATA_HOME": self.tmp.name,
|
|
"XDG_CONFIG_HOME": self.tmp.name})
|
|
patcher.start()
|
|
self.addCleanup(patcher.stop)
|
|
self.addCleanup(self.tmp.cleanup)
|
|
|
|
def test_draft_roundtrip(self):
|
|
self.assertEqual(notes.load_draft(), "")
|
|
notes.save_draft("fixing the parser")
|
|
self.assertEqual(notes.load_draft(), "fixing the parser")
|
|
notes.save_draft(" ")
|
|
self.assertEqual(notes.load_draft(), "")
|
|
|
|
def test_record_clears_draft_and_appends(self):
|
|
notes.save_draft("draft")
|
|
when = datetime.datetime(2026, 9, 28, 14, 5)
|
|
notes.record("first\n\n## not a heading", when)
|
|
notes.record("", when)
|
|
notes.record("second", when + datetime.timedelta(minutes=30))
|
|
self.assertEqual(notes.load_draft(), "")
|
|
self.assertEqual(notes.recent(), [
|
|
("2026-09-28 14:05", "first\n\n## not a heading"),
|
|
("2026-09-28 14:35", "second"),
|
|
])
|
|
self.assertEqual(notes.recent(1), [("2026-09-28 14:35", "second")])
|
|
|
|
def test_stats(self):
|
|
day = datetime.datetime(2026, 9, 28, 10, 0).astimezone()
|
|
notes.log_event("taken", day)
|
|
notes.log_event("taken", day)
|
|
notes.log_event("snoozed", day - datetime.timedelta(days=1))
|
|
result = dict(notes.stats(days=3, today=day.date()))
|
|
self.assertEqual(result[day.date()]["taken"], 2)
|
|
self.assertEqual(result[day.date() - datetime.timedelta(days=1)]["snoozed"], 1)
|
|
self.assertEqual(len(result), 3)
|
|
|
|
def test_config_defaults_and_validation(self):
|
|
path = config.write_default()
|
|
self.assertEqual(config.load(path), config.Config())
|
|
path.write_text('work_minutes = 50\nsounds = "yes"\nbogus = 1\n')
|
|
with mock.patch("sys.stderr"):
|
|
cfg = config.load(path)
|
|
self.assertEqual(cfg.work_minutes, 50)
|
|
self.assertTrue(cfg.sounds)
|
|
|
|
|
|
class ExercisesTest(unittest.TestCase):
|
|
def test_plan_fills_break(self):
|
|
for seconds in (30, 90, 120, 300, 600):
|
|
steps = exercises.plan(seconds)
|
|
self.assertAlmostEqual(sum(s.seconds for s in steps), seconds)
|
|
self.assertTrue(all(s.seconds > 0 for s in steps))
|
|
|
|
def test_five_minute_break_has_all_eye_steps_then_walk(self):
|
|
steps = exercises.plan(300)
|
|
self.assertEqual(steps[:-1], exercises.EYE_STEPS)
|
|
self.assertEqual(steps[-1].title, exercises.WALK.title)
|
|
self.assertGreaterEqual(steps[-1].seconds, exercises.MIN_WALK)
|
|
|
|
def test_position(self):
|
|
steps = exercises.plan(300)
|
|
self.assertEqual(exercises.position(steps, 0), (0, 20))
|
|
self.assertEqual(exercises.position(steps, 25), (1, 10))
|
|
self.assertEqual(exercises.position(steps, 299)[0], len(steps) - 1)
|
|
self.assertEqual(exercises.position(steps, 400), (len(steps) - 1, 0.0))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|