Repository navigation
feat(recur): add interval property accessor #2066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aspire488
wants to merge
27
commits into
PyCalendar:main
Choose a base branch
from
aspire488:feat/vrecur-interval-accessor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
0d00f86
feat(recur): add interval property accessor
aspire488 efd7cbe
fix(recur): align interval accessor docs and errors
aspire488 54d9f27
test(recur): cover deleting multiple interval values
aspire488 ee6c8c1
fix(recur): reject boolean interval values
aspire488 5856f11
Merge branch 'main' into feat/vrecur-interval-accessor
angatha 77af158
Add positive integer value type for recurrence intervals
aspire488 9f53729
Validate INTERVAL with positive integer parser
aspire488 fbfb138
Test positive INTERVAL parsing and accessor behavior
aspire488 fcf8a98
Validate positive integers in xCal recurrence parsing
aspire488 d7fe84b
Clarify INTERVAL accessor documentation
aspire488 025fe61
Cover invalid parsed and stored recurrence intervals
aspire488 e29247c
Fix recurrence interval tests after CI lint feedback
aspire488 84c26f2
Clarify invalid RRULE parsing behavior in accessor docs
aspire488 48742db
Cover malformed INTERVAL values during parsing
aspire488 e3661e3
docs(recur): clarify INTERVAL accessor documentation
aspire488 e99015c
test(recur): align xCal interval expectations with positive integer
aspire488 20b575b
test(recur): accept positive integer validation for jCal interval
aspire488 26f330d
style(recur): format xCal interval regression test
aspire488 3851d56
Merge branch 'main' into feat/vrecur-interval-accessor
stevepiercy e343f7c
Merge branch 'main' into feat/vrecur-interval-accessor
stevepiercy 85965c1
Clarify interval accessor parsing errors
aspire488 4855bfb
Polish positive integer docstring
aspire488 022ab05
Cover zero and negative stored intervals
aspire488 488b6bb
fix(recur): clarify interval access errors
aspire488 8d8a90f
test(recur): cover interval dictionary access errors
aspire488 b921445
test(recur): assert interval error value types
aspire488 7f6e06d
Merge branch 'main' into feat/vrecur-interval-accessor
stevepiercy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Added an :attr:`~icalendar.prop.recur.recur.vRecur.interval` accessor for reading, setting, and deleting the positive INTERVAL value of a recurrence rule. I used OpenAI GPT-6 to assist with implementation and tests. @aspire488 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| """Tests for the vRecur.interval accessor (issue #1851).""" | ||
|
|
||
| import pytest | ||
|
|
||
| from icalendar.error import InvalidCalendar | ||
| from icalendar.prop import vRecur | ||
| from icalendar.prop.integer import vPositiveInt | ||
|
|
||
|
|
||
| def test_interval_returns_none_when_absent(): | ||
| assert vRecur.from_ical("FREQ=DAILY").interval is None | ||
|
|
||
|
|
||
| def test_interval_returns_the_value(): | ||
| assert vRecur.from_ical("FREQ=DAILY;INTERVAL=2").interval == 2 | ||
|
|
||
|
|
||
| def test_interval_returns_first_value_when_multiple_are_present(): | ||
| recur = vRecur(FREQ=["DAILY"], INTERVAL=[2, 3]) | ||
| assert recur.interval == 2 | ||
|
|
||
|
|
||
| def test_interval_returns_none_when_value_is_an_empty_list(): | ||
| recur = vRecur(FREQ=["DAILY"], INTERVAL=[]) | ||
| assert recur.interval is None | ||
|
|
||
|
|
||
| def test_setting_interval_stores_a_registered_positive_int(): | ||
| recur = vRecur.from_ical("FREQ=DAILY") | ||
| recur.interval = 3 | ||
|
|
||
| assert recur.interval == 3 | ||
| assert isinstance(recur["INTERVAL"][0], vPositiveInt) | ||
| assert recur.to_ical() == b"FREQ=DAILY;INTERVAL=3" | ||
|
|
||
|
|
||
| def test_setting_interval_to_none_deletes_the_value(): | ||
| recur = vRecur.from_ical("FREQ=DAILY;INTERVAL=2") | ||
| recur.interval = None | ||
|
|
||
| assert recur.interval is None | ||
| assert "INTERVAL" not in recur | ||
|
|
||
|
|
||
| def test_setting_interval_to_none_removes_all_multiple_values(): | ||
| recur = vRecur(FREQ=["DAILY"], INTERVAL=[2, 3]) | ||
| recur.interval = None | ||
|
|
||
| assert recur.interval is None | ||
| assert "INTERVAL" not in recur | ||
|
|
||
|
|
||
| def test_deleting_interval_removes_the_value(): | ||
| recur = vRecur.from_ical("FREQ=DAILY;INTERVAL=2") | ||
| del recur.interval | ||
|
|
||
| assert recur.interval is None | ||
| assert "INTERVAL" not in recur | ||
|
angatha marked this conversation as resolved.
Resolved
|
||
|
|
||
|
|
||
| def test_deleting_interval_removes_all_multiple_values(): | ||
| recur = vRecur(FREQ=["DAILY"], INTERVAL=[2, 3]) | ||
| del recur.interval | ||
|
|
||
| assert recur.interval is None | ||
| assert "INTERVAL" not in recur | ||
|
|
||
|
|
||
| def test_deleting_interval_when_absent_does_not_raise(): | ||
| recur = vRecur.from_ical("FREQ=DAILY") | ||
| del recur.interval | ||
| assert recur.interval is None | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("value", ["2", 2.0, True]) | ||
| def test_setting_interval_to_non_int_raises_type_error(value): | ||
| recur = vRecur.from_ical("FREQ=DAILY") | ||
| with pytest.raises(TypeError): | ||
| recur.interval = value | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("value", [0, -1]) | ||
| def test_setting_interval_to_non_positive_value_raises_invalid_calendar(value): | ||
| recur = vRecur.from_ical("FREQ=DAILY") | ||
| with pytest.raises(InvalidCalendar, match="INTERVAL must be >= 1"): | ||
| recur.interval = value | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("value", ["0", "-1", "True", "abc"]) | ||
| def test_parsing_invalid_interval_raises_value_error(value): | ||
| with pytest.raises(ValueError): | ||
| vRecur.from_ical(f"FREQ=DAILY;INTERVAL={value}") | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("stored", [0, -1]) | ||
| def test_dictionary_access_non_positive_interval_raises_invalid_calendar(stored): | ||
| recur = vRecur.from_ical("FREQ=DAILY") | ||
| recur["INTERVAL"] = [stored] | ||
| with pytest.raises(InvalidCalendar, match="INTERVAL must be >= 1"): | ||
| recur.interval | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("stored", "value_type"), | ||
| [("abc", "str"), ("", "str"), (["abc"], "str"), (True, "bool")], | ||
| ) | ||
| def test_dictionary_access_unreadable_interval_raises_invalid_calendar( | ||
| stored, value_type | ||
| ): | ||
| recur = vRecur.from_ical("FREQ=DAILY") | ||
| recur["INTERVAL"] = stored | ||
| with pytest.raises( | ||
| InvalidCalendar, | ||
| match=f"INTERVAL must be an int, got {value_type}", | ||
| ): | ||
| recur.interval | ||
|
|
||
|
|
||
| def test_interval_roundtrips_through_ical(): | ||
| recur = vRecur.from_ical("FREQ=DAILY;INTERVAL=3") | ||
| roundtripped = vRecur.from_ical(recur.to_ical().decode()) | ||
|
|
||
| assert roundtripped.interval == 3 | ||
| assert isinstance(roundtripped["INTERVAL"][0], vPositiveInt) | ||
|
|
||
|
|
||
| def test_setting_interval_matches_parsed_vrecur(): | ||
| parsed = vRecur.from_ical("FREQ=DAILY;INTERVAL=3") | ||
| assigned = vRecur.from_ical("FREQ=DAILY") | ||
| assigned.interval = 3 | ||
|
|
||
| assert assigned == parsed | ||
| assert assigned["INTERVAL"] == parsed["INTERVAL"] | ||
| assert assigned.to_ical() == parsed.to_ical() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.