from templates import DEFAULT_TEMPLATES, load_templates, parse_color, save_templates def test_parse_color(): assert parse_color("#e67e22") == 0xE67E22 assert parse_color("e67e22") == 0xE67E22 assert parse_color("0xe67e22") == 0xE67E22 assert parse_color("15158306") == 15158306 def test_load_templates_missing_file(tmp_path): templates = load_templates(tmp_path / "missing.json") assert templates["420"]["text"] == DEFAULT_TEMPLATES["420"]["text"] def test_save_and_load_templates_roundtrip(tmp_path): path = tmp_path / "templates.json" data = { "420": {"text": "Custom", "color": 123}, } save_templates(path, data) raw = path.read_text(encoding="utf-8") assert '"color": "#00007B"' in raw loaded = load_templates(path) assert loaded["420"]["text"] == "Custom" assert loaded["420"]["color"] == 123 # defaults should still exist for other keys assert "reminder" in loaded