-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_cli.py
More file actions
51 lines (37 loc) · 1.49 KB
/
test_cli.py
File metadata and controls
51 lines (37 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import datetime
import io
import os
import zoneinfo
import pytest
from yaml2ics import event_from_yaml, files_to_events, main
basedir = os.path.abspath(os.path.join(os.path.dirname(__file__)))
example_calendar = os.path.join(basedir, "../example/test_calendar.yaml")
def test_cli():
main(["yaml2ics.py", example_calendar])
with pytest.raises(RuntimeError) as e:
main(["yaml2ics.py"])
assert "Usage:" in str(e)
with pytest.raises(RuntimeError) as e:
main(["yaml2ics.py", "syzygy.yaml"])
assert "is not a file" in str(e)
def test_errors():
begin = datetime.date(2025, 12, 1)
with pytest.raises(RuntimeError) as e:
event_from_yaml({"begin": begin, "repeat": {"interval": {}}})
assert "interval must specify" in str(e)
with pytest.raises(RuntimeError) as e:
event_from_yaml({"begin": begin, "ics": "123"})
assert "Invalid custom ICS" in str(e)
with pytest.raises(RuntimeError) as e:
event_from_yaml({"begin": begin, "repeat": {"interval": {"weeks": 1}}})
assert "must specify end date for repeating events" in str(e)
with pytest.raises(RuntimeError) as e:
event_from_yaml({"begin": begin, "repeat": {"interval": {"epochs": 4}}})
assert "expected interval to be specified in seconds, minutes" in str(e)
def test_invalid_timezone():
f = io.BytesIO(b"""
name: Invalid tz cal
timezone: US/Pacificana
""")
with pytest.raises(zoneinfo.ZoneInfoNotFoundError):
files_to_events([f])