File: test_all.py

package info (click to toggle)
python-recurring-ical-events 3.3.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,128 kB
  • sloc: python: 2,896; sh: 15; makefile: 3
file content (91 lines) | stat: -rw-r--r-- 2,965 bytes parent folder | download | duplicates (2)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""The all() function can be exposed now that we have the after() function.

all() becomes a Generator.
We do not wish to retain a high memory footprint on the occurrences.
"""

from __future__ import annotations

from datetime import date
from typing import TYPE_CHECKING, NamedTuple

import pytest

from recurring_ical_events import Occurrence

if TYPE_CHECKING:
    from recurring_ical_events import RecurrenceIDs, Time


class Adapter(NamedTuple):
    uid: str
    name: str
    recurrence_ids: RecurrenceIDs
    start: Time
    end: Time = date(2020, 10, 10)

    def component_name(self):
        return self.name


@pytest.mark.parametrize(
    ("adapter1", "adapter2", "equality", "message"),
    [
        (
            Adapter("asd", "asd", (date(2020, 10, 2),), date(2020, 10, 2)),
            Adapter("asd", "asd", (date(2020, 10, 2),), date(2020, 10, 2)),
            True,
            "same copy",
        ),
        (
            Adapter("asd1", "asd", (date(2020, 10, 2),), date(2020, 10, 2)),
            Adapter("asd", "asd", (date(2020, 10, 2),), date(2020, 10, 2)),
            False,
            "different name",
        ),
        (
            Adapter("asd", "asd", (date(2020, 10, 2),), date(2020, 10, 2)),
            Adapter("asd", "asd1", (date(2020, 10, 2),), date(2020, 10, 2)),
            False,
            "different uid",
        ),
        (
            Adapter("asd", "asd", (date(2020, 10, 1),), date(2020, 10, 2)),
            Adapter("asd", "asd", (date(2020, 10, 2),), date(2020, 10, 2)),
            False,
            "different recurrence id",
        ),
        (
            Adapter("asd", "asd", (date(2020, 10, 2),), date(2020, 10, 1)),
            Adapter("asd", "asd", (date(2020, 10, 2),), date(2020, 10, 2)),
            True,
            "different start but recurrence id is the same",
        ),
        (
            Adapter("asd", "asd", (), date(2020, 10, 2)),
            Adapter("asd", "asd", (), date(2020, 10, 2)),
            True,
            "no recurrence id but copy",
        ),
        (
            Adapter("asd", "asd", (), date(2020, 10, 2)),
            Adapter("asd", "asd", (), date(2020, 10, 1)),
            False,
            "no recurrence id but start differs",
        ),
    ],
)
def test_equality(adapter1, adapter2, equality, message):
    """Check the equality of Occurrences."""
    occurrence1 = Occurrence(adapter1)
    occurrence2 = Occurrence(adapter2)
    assert (occurrence1 == occurrence2) == equality, "1 == 2 - " + message
    assert (occurrence1 != occurrence2) != equality, "1 != 2 - " + message
    assert (occurrence2 == occurrence1) == equality, "2 == 1 - " + message
    assert (occurrence2 != occurrence1) != equality, "2 != 1 - " + message
    assert (hash(occurrence1) == hash(occurrence2)) == equality, (
        "hash1 == hash2 - " + message
    )
    assert (hash(occurrence1) != hash(occurrence2)) != equality, (
        "hash1 != hash2 - " + message
    )