| 1 |
"""These tests make sure that you can select which components should be returned. |
| 2 |
|
| 3 |
By default, it should be events. |
| 4 |
If a component is not supported, an error is raised. |
| 5 |
""" |
| 6 |
|
| 7 |
import pytest |
| 8 |
|
| 9 |
|
| 10 |
@pytest.mark.parametrize( |
| 11 |
("components", "count", "calendar", "message"), |
| 12 |
[ |
| 13 |
(None, 0, "issue_97_simple_todo", "by default, only events are returned"), |
| 14 |
(None, 0, "issue_97_simple_journal", "by default, only events are returned"), |
| 15 |
([], 0, "rdate", "no components, no result"), |
| 16 |
([], 0, "issue_97_simple_todo", "no components, no result"), |
| 17 |
([], 0, "issue_97_simple_journal", "no components, no result"), |
| 18 |
(["VEVENT"], 0, "issue_97_simple_todo", "no events in the calendar"), |
| 19 |
(["VEVENT"], 0, "issue_97_simple_journal", "no events in the calendar"), |
| 20 |
(["VJOURNAL"], 0, "issue_97_simple_todo", "no journal, just a todo"), |
| 21 |
(["VTODO"], 1, "issue_97_simple_todo", "one todo is found"), |
| 22 |
(["VTODO"], 0, "issue_97_simple_journal", "no todo, just a journal"), |
| 23 |
(["VJOURNAL"], 1, "issue_97_simple_journal", "one journal is found"), |
| 24 |
(["VTODO", "VEVENT"], 0, "issue_97_simple_journal", "no todo, just a journal"), |
| 25 |
(["VJOURNAL", "VEVENT"], 1, "issue_97_simple_journal", "one journal is found"), |
| 26 |
( |
| 27 |
["VJOURNAL", "VEVENT", "VTODO"], |
| 28 |
1, |
| 29 |
"issue_97_simple_journal", |
| 30 |
"one journal is found", |
| 31 |
), |
| 32 |
], |
| 33 |
) |
| 34 |
def test_components_and_their_count(calendars, components, count, calendar, message): |
| 35 |
calendars.components = components |
| 36 |
repeated_components = calendars[calendar].at(2022) |
| 37 |
print(repeated_components) |
| 38 |
assert len(repeated_components) == count, f"{message}: {components}, {calendar}" |
| 39 |
|
| 40 |
|
| 41 |
@pytest.mark.parametrize( |
| 42 |
"component", |
| 43 |
[ |
| 44 |
"VTIMEZONE", |
| 45 |
"vevent", |
| 46 |
"ALDHKSJHK", |
| 47 |
], |
| 48 |
) |
| 49 |
def test_unsupported_component_raises_error(component, calendars): |
| 50 |
"""If a component is not recognized, we want to inform the user.""" |
| 51 |
with pytest.raises(ValueError) as error: |
| 52 |
calendars.components = [component] |
| 53 |
calendars.rdate |
| 54 |
assert f'"{component}"' in str(error) |