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
|
"""These tests make sure that you can select which components should be returned.
By default, it should be events.
If a component is not supported, an error is raised.
"""
import pytest
@pytest.mark.parametrize(
("components", "count", "calendar", "message"),
[
(None, 0, "issue_97_simple_todo", "by default, only events are returned"),
(None, 0, "issue_97_simple_journal", "by default, only events are returned"),
([], 0, "rdate", "no components, no result"),
([], 0, "issue_97_simple_todo", "no components, no result"),
([], 0, "issue_97_simple_journal", "no components, no result"),
(["VEVENT"], 0, "issue_97_simple_todo", "no events in the calendar"),
(["VEVENT"], 0, "issue_97_simple_journal", "no events in the calendar"),
(["VJOURNAL"], 0, "issue_97_simple_todo", "no journal, just a todo"),
(["VTODO"], 1, "issue_97_simple_todo", "one todo is found"),
(["VTODO"], 0, "issue_97_simple_journal", "no todo, just a journal"),
(["VJOURNAL"], 1, "issue_97_simple_journal", "one journal is found"),
(["VTODO", "VEVENT"], 0, "issue_97_simple_journal", "no todo, just a journal"),
(["VJOURNAL", "VEVENT"], 1, "issue_97_simple_journal", "one journal is found"),
(
["VJOURNAL", "VEVENT", "VTODO"],
1,
"issue_97_simple_journal",
"one journal is found",
),
],
)
def test_components_and_their_count(calendars, components, count, calendar, message):
calendars.components = components
repeated_components = calendars[calendar].at(2022)
print(repeated_components)
assert len(repeated_components) == count, f"{message}: {components}, {calendar}"
@pytest.mark.parametrize(
"component",
[
"VALARM", # existing but not supported, yet
"vevent", # misspelled
"ALDHKSJHK", # does not exist
],
)
def test_unsupported_component_raises_error(component, calendars):
"""If a component is not recognized, we want to inform the user."""
with pytest.raises(ValueError) as error:
calendars.components = [component]
calendars.rdate # noqa: B018
assert f'"{component}"' in str(error)
|