-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_ical.py
More file actions
94 lines (73 loc) · 2.82 KB
/
Copy pathtest_ical.py
File metadata and controls
94 lines (73 loc) · 2.82 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import os
import pytest
from iterable.datatypes import ICALIterable
try:
from icalendar import Calendar, Event # noqa: F401
HAS_ICALENDAR = True
except ImportError:
HAS_ICALENDAR = False
try:
import ics # noqa: F401
HAS_ICS = True
except ImportError:
HAS_ICS = False
@pytest.mark.skipif(not HAS_ICALENDAR and not HAS_ICS, reason="iCal support requires 'icalendar' or 'ics' package")
class TestICAL:
def test_id(self):
datatype_id = ICALIterable.id()
assert datatype_id == "ical"
def test_flatonly(self):
flag = ICALIterable.is_flatonly()
assert not flag
def test_openclose(self):
"""Test basic open/close"""
test_file = "testdata/test_ical.ics"
os.makedirs("testdata", exist_ok=True)
with open(test_file, "w") as f:
f.write("BEGIN:VCALENDAR\nVERSION:2.0\nBEGIN:VEVENT\nSUMMARY:Test Event\nEND:VEVENT\nEND:VCALENDAR\n")
iterable = ICALIterable(test_file)
iterable.close()
if os.path.exists(test_file):
os.unlink(test_file)
def test_read_one(self):
"""Test reading single event"""
test_file = "testdata/test_ical_read.ics"
os.makedirs("testdata", exist_ok=True)
with open(test_file, "w") as f:
f.write("BEGIN:VCALENDAR\nVERSION:2.0\nBEGIN:VEVENT\nSUMMARY:Test Event\nEND:VEVENT\nEND:VCALENDAR\n")
iterable = ICALIterable(test_file)
record = iterable.read()
assert isinstance(record, dict)
iterable.close()
if os.path.exists(test_file):
os.unlink(test_file)
def test_read_bulk(self):
"""Test reading bulk events"""
test_file = "testdata/test_ical_bulk.ics"
os.makedirs("testdata", exist_ok=True)
with open(test_file, "w") as f:
f.write("BEGIN:VCALENDAR\nVERSION:2.0\n")
f.write("BEGIN:VEVENT\nSUMMARY:Event 1\nEND:VEVENT\n")
f.write("BEGIN:VEVENT\nSUMMARY:Event 2\nEND:VEVENT\n")
f.write("END:VCALENDAR\n")
iterable = ICALIterable(test_file)
chunk = iterable.read_bulk(2)
assert isinstance(chunk, list)
assert len(chunk) > 0
iterable.close()
if os.path.exists(test_file):
os.unlink(test_file)
def test_reset(self):
"""Test reset functionality"""
test_file = "testdata/test_ical_reset.ics"
os.makedirs("testdata", exist_ok=True)
with open(test_file, "w") as f:
f.write("BEGIN:VCALENDAR\nVERSION:2.0\nBEGIN:VEVENT\nSUMMARY:Test\nEND:VEVENT\nEND:VCALENDAR\n")
iterable = ICALIterable(test_file)
record1 = iterable.read()
iterable.reset()
record2 = iterable.read()
assert record1 == record2
iterable.close()
if os.path.exists(test_file):
os.unlink(test_file)