kopia lustrzana https://github.com/collective/icalendar
Test examples from RFC 7529
rodzic
39fef78ec0
commit
65537b4cb5
|
@ -275,23 +275,29 @@ class Component(CaselessDict):
|
|||
"""
|
||||
self.subcomponents.append(component)
|
||||
|
||||
def _walk(self, name):
|
||||
def _walk(self, name, select):
|
||||
"""Walk to given component.
|
||||
"""
|
||||
result = []
|
||||
if name is None or self.name == name:
|
||||
if (name is None or self.name == name) and select(self):
|
||||
result.append(self)
|
||||
for subcomponent in self.subcomponents:
|
||||
result += subcomponent._walk(name)
|
||||
result += subcomponent._walk(name, select)
|
||||
return result
|
||||
|
||||
def walk(self, name=None):
|
||||
def walk(self, name=None, select=lambda c: True):
|
||||
"""Recursively traverses component and subcomponents. Returns sequence
|
||||
of same. If name is passed, only components with name will be returned.
|
||||
|
||||
:param name: The name of the component or None such as ``VEVENT``.
|
||||
:param select: A function that takes the component as first argument
|
||||
and returns True/False.
|
||||
:returns: A list of components that match.
|
||||
:rtype: list[Component]
|
||||
"""
|
||||
if name is not None:
|
||||
name = name.upper()
|
||||
return self._walk(name)
|
||||
return self._walk(name, select)
|
||||
|
||||
#####################
|
||||
# Generation
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID://RESEARCH IN MOTION//BIS 3.0
|
||||
METHOD:REQUEST
|
||||
BEGIN:VEVENT
|
||||
UID:4.3.1
|
||||
DTSTART;VALUE=DATE:20130210
|
||||
RRULE:RSCALE=CHINESE;FREQ=YEARLY
|
||||
SUMMARY:Chinese New Year
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
UID:4.3.2
|
||||
DTSTART;VALUE=DATE:20130906
|
||||
RRULE:RSCALE=ETHIOPIC;FREQ=MONTHLY;BYMONTH=13
|
||||
SUMMARY:First day of 13th month
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
UID:4.3.3
|
||||
DTSTART;VALUE=DATE:20140208
|
||||
RRULE:RSCALE=HEBREW;FREQ=YEARLY;BYMONTH=5L;BYMONTHDAY=8;SKIP=FORWARD
|
||||
SUMMARY:Anniversary
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
UID:4.3.4
|
||||
DTSTART;VALUE=DATE:20120229
|
||||
RRULE:RSCALE=GREGORIAN;FREQ=YEARLY;SKIP=FORWARD
|
||||
SUMMARY:Anniversary
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
|
@ -0,0 +1,25 @@
|
|||
"""This tests the compatibility with RFC 7529.
|
||||
|
||||
See
|
||||
- https://github.com/collective/icalendar/issues/653
|
||||
- https://www.rfc-editor.org/rfc/rfc7529.html
|
||||
"""
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"uid,scale",
|
||||
[
|
||||
("4.3.1", "CHINESE"),
|
||||
("4.3.2", "ETHIOPIC"),
|
||||
("4.3.3", "HEBREW"),
|
||||
("4.3.4", "GREGORIAN"),
|
||||
]
|
||||
)
|
||||
def test_rscale(calendars, uid, scale):
|
||||
"""Check that the RSCALE is parsed correctly."""
|
||||
event = calendars.rfc_7529.walk(select=lambda c: c.get("UID") == uid)[0]
|
||||
print(event.errors)
|
||||
rrule = event["RRULE"]
|
||||
print(rrule)
|
||||
assert rrule["RSCALE"] == [scale]
|
Ładowanie…
Reference in New Issue