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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
import pytest
import sys
sys.path.insert(0,'.')
sys.path.insert(1,'..')
from datetime import datetime, date
from calendar_cli.cal import parse_timespec
from calendar_cli.template import Template
"""calendar-cli is a command line utility, and it's an explicit design
goal that it should contain minimal logic except for parsing and
passing command line options and parameters to the caldav library and
printing output from the caldav library. Functional tests verifying
that the tool actually works as intended is done through shell
scripts, and can be run through test_calendar-cli.sh. There is no
goal to get complete code coverage through this unit test, though any
"extra" logic except for simple passing of options and parameters to
the caldav library ought to be tested here. """
class TestTemplate:
def setup_method(self):
self.date = date(1990, 10, 10)
def test_formatting_with_timespec(self):
template=Template("This is an ISO date: {date:%F}")
text = template.format(date=self.date)
assert text == "This is an ISO date: 1990-10-10"
text = template.format(foo=self.date)
assert text == "This is an ISO date: "
def test_formatting_with_simple_default(self):
template=Template("This is an ISO date: {date:?(date is missing)?%F}")
text = template.format(date=self.date)
assert text == "This is an ISO date: 1990-10-10"
text = template.format(foo=self.date)
assert text == "This is an ISO date: (date is missing)"
def test_subvalue_with_default(self):
template = Template("This is a year: {date.year:?NA?>5}")
text = template.format(date=self.date)
assert text == "This is a year: 1990"
text = template.format(foo=self.date)
assert text == "This is a year: NA"
def test_missing_replaced_with_advanced_default(self):
template = Template("Date is maybe {date:?{foo}?%F}")
text = template.format(date=self.date)
assert text == "Date is maybe 1990-10-10"
text = template.format(foo=self.date)
assert text == "Date is maybe 1990-10-10"
text = template.format(foo=self.date, date=self.date)
assert text == "Date is maybe 1990-10-10"
def test_missing_replaced_with_even_more_advanced_default(self):
template = Template("Date is maybe {date:?{foo:?bar?}?%F}")
text = template.format(date=self.date)
assert text == "Date is maybe 1990-10-10"
text = template.format(foo=self.date)
assert text == "Date is maybe 1990-10-10"
text = template.format(foo=self.date, date=self.date)
assert text == "Date is maybe 1990-10-10"
text = template.format()
assert text == "Date is maybe bar"
class TestParseTimestamp:
def _testTimeSpec(self, expected):
for input in expected:
assert parse_timespec(input) == expected[input]
@pytest.mark.skip(reason="Not implemented yet, waiting for feedback on https://github.com/gweis/isodate/issues/77")
def testIsoIntervals(self):
raise pytest.SkipTest("")
expected = {
"2007-03-01T13:00:00Z/2008-05-11T15:30:00Z":
(datetime(2007,3,1,13), datetime(2008,5,11,15,30)),
"2007-03-01T13:00:00Z/P1Y2M10DT2H30M":
(datetime(2007,3,1,13), datetime(2008,5,11,15,30)),
"P1Y2M10DT2H30M/2008-05-11T15:30:00Z":
(datetime(2007,3,1,13), datetime(2008,5,11,15,30))
}
self._testTimeSpec(expected)
def testOneTimestamp(self):
expected = {
"2007-03-01T13:00:00":
(datetime(2007,3,1,13), None),
"2007-03-01 13:00:00":
(datetime(2007,3,1,13), None),
}
self._testTimeSpec(expected)
def testOneDate(self):
expected = {
"2007-03-01":
(date(2007,3,1), None)
}
self._testTimeSpec(expected)
def testTwoTimestamps(self):
expected = {
"2007-03-01T13:00:00 2007-03-11T13:30:00":
(datetime(2007,3,1,13), datetime(2007,3,11,13,30)),
"2007-03-01 13:00:00 2007-03-11 13:30:00":
(datetime(2007,3,1,13), datetime(2007,3,11,13,30)),
}
self._testTimeSpec(expected)
def testTwoDates(self):
expected = {
"2007-03-01 2007-03-11":
(date(2007,3,1), date(2007,3,11))
}
self._testTimeSpec(expected)
def testCalendarCliFormat(self):
expected = {
"2007-03-01T13:00:00+10d":
(datetime(2007,3,1,13), datetime(2007,3,11,13)),
"2007-03-01T13:00:00+2h":
(datetime(2007,3,1,13), datetime(2007,3,1,15)),
"2007-03-01T13:00:00+2.5h":
(datetime(2007,3,1,13), datetime(2007,3,1,15,30)),
"2007-03-01T13:00:00+2h30m":
(datetime(2007,3,1,13), datetime(2007,3,1,15,30)),
"2007-03-01+10d":
(date(2007,3,1), date(2007,3,11))
}
self._testTimeSpec(expected)
|