-
Notifications
You must be signed in to change notification settings - Fork 1
/
ics_to_csv_test.py
73 lines (61 loc) · 2.1 KB
/
ics_to_csv_test.py
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
import ics_to_csv
import pytest
import ics
import subprocess
import os
import uuid
# Bare minimum tests to make sure my sample doesn't break as time goes on
UUID = uuid.uuid4().hex[:10]
OUTPUT_FILE = f"holidays-test-{UUID}.csv"
TEST_CALENDAR_STRING=(
"BEGIN:VCALENDAR\n"
"VERSION:2.0\n"
"PRODID:-//Telerik Inc.//NONSGML RadScheduler//EN\n"
"METHOD:PUBLISH\n"
"BEGIN:VEVENT\n"
"DTSTART:19970101\n"
"DTEND:19970102\n"
"UID:20210211T185111Z-05fe6751-ec1d-4532-b3a8-60e48e0eb064\n"
"DTSTAMP:20210211T185111Z\n"
"SUMMARY:New Year’s Day\n"
"DESCRIPTION:\n"
"END:VEVENT\n"
"END:VCALENDAR\n"
)
# Test string is missing END:VCALENDAR and BEGIN: VEVENT lines
TEST_BAD_CALENDAR_STRING=(
"BEGIN:VCALENDAR\n"
"VERSION:2.0\n"
"PRODID:-//Telerik Inc.//NONSGML RadScheduler//EN\n"
"METHOD:PUBLISH\n"
"DTSTART:19970101\n"
"DTEND:19970102\n"
"UID:20210211T185111Z-05fe6751-ec1d-4532-b3a8-60e48e0eb064\n"
"DTSTAMP:20210211T185111Z\n"
"SUMMARY:New Year’s Day\n"
"DESCRIPTION:\n"
"END:VEVENT\n"
)
TEST_EVENT_LIST = [['Date', 'Holiday'], ['1997-1-1', 'New Year’s Day']]
@pytest.fixture
def cleanup_csv_test():
yield
subprocess.run(["rm", OUTPUT_FILE])
def test_convert_ics_to_string_fails_bad_ics():
with pytest.raises(Exception):
assert(ics_to_csv.convert_ics_to_string("test_data/holidays-test-bad.ics"))
with pytest.raises(Exception):
assert(ics_to_csv.convert_ics_to_string("test_data/test.txt"))
def test_convert_ics_to_string():
output = ics_to_csv.convert_ics_to_string("test_data/holidays-test.ics")
assert "BEGIN:VCALENDAR" in output
def test_make_event_list():
output = ics_to_csv.make_event_list(TEST_CALENDAR_STRING)
assert "New Year’s Day" in output[1]
assert len(output)==2
def test_make_event_list_fails():
with pytest.raises(ics.grammar.parse.ParseError):
ics_to_csv.make_event_list(TEST_BAD_CALENDAR_STRING)
def test_convert_list_to_csv(cleanup_csv_test):
ics_to_csv.convert_list_to_csv(TEST_EVENT_LIST, OUTPUT_FILE)
assert os.path.exists(OUTPUT_FILE)