Test examples from RFC 7529

pull/667/head
Nicco Kunzmann 2024-06-26 23:59:49 +01:00
rodzic 39fef78ec0
commit 65537b4cb5
3 zmienionych plików z 65 dodań i 5 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -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

Wyświetl plik

@ -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]