| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 | # ical2vdir - convert .ics file to vdir directory## Copyright (C) 2020 Fabian Peter Hammerle <fabian@hammerle.me>## This program is free software: you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation, either version 3 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program.  If not, see <https://www.gnu.org/licenses/>.import datetimeimport typingimport pytestfrom icalendar.prop import vCalAddress, vDDDLists, vDDDTypes, vInt, vRecur, vTextfrom ical2vdir import _event_prop_equal_CEST = datetime.timezone(datetime.timedelta(hours=+2))def _parametrize(obj: typing.Any, params: typing.Dict[str, str]) -> typing.Any:    for key, value in params.items():        obj.params.__setitem__(key, value)    return obj@pytest.mark.parametrize(    ("prop_a", "prop_b", "expected_result"),    [        (vText("CONFIRMED"), vText("CONFIRMED"), True),        (vText("TENTATIVE"), vText("TENTATIVE"), True),        (vText("CONFIRMED"), vText("TENTATIVE"), False),        (vText("CONFIRMED"), vInt(0), False),        (vInt(0), vInt(0), True),        (vInt(0), vInt(21), False),        (            vCalAddress("mailto:someone@somewhere.com"),            vCalAddress("mailto:someone@somewhere.com"),            True,        ),        (            vCalAddress("mailto:someone@somewhere.com"),            vCalAddress("mailto:someelse@somewhere.com"),            False,        ),        (            vRecur(FREQ="WEEKLY", COUNT=21),            vRecur(FREQ="WEEKLY", COUNT=21),            True,        ),        (            vRecur(FREQ="WEEKLY", COUNT=21),            vRecur(FREQ="WEEKLY", COUNT=42),            False,        ),        (            vDDDTypes(                datetime.datetime(2012, 7, 3, 16, 39, 2, tzinfo=datetime.timezone.utc)            ),            vDDDTypes(                datetime.datetime(2012, 7, 3, 16, 39, 2, tzinfo=datetime.timezone.utc)            ),            True,        ),        (            vDDDTypes(                datetime.datetime(2012, 7, 3, 16, 39, 2, tzinfo=datetime.timezone.utc)            ),            vDDDTypes(datetime.datetime(2012, 7, 3, 18, 39, 2, tzinfo=_CEST)),            # logically that should be True            # but shouldn't hurt to update the ics file            False,        ),        (            vDDDTypes(                datetime.datetime(2012, 7, 3, 16, 39, 3, tzinfo=datetime.timezone.utc)            ),            vDDDTypes(                datetime.datetime(2012, 7, 3, 16, 39, 2, tzinfo=datetime.timezone.utc)            ),            False,        ),        (            vDDDLists(                [datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc)]            ),            vDDDLists(                [datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc)]            ),            True,        ),        (            vDDDLists(                [                    datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc),                    datetime.datetime(2020, 2, 5, 20, 5, tzinfo=datetime.timezone.utc),                ]            ),            vDDDLists(                [                    datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc),                    datetime.datetime(2020, 2, 5, 20, 5, tzinfo=datetime.timezone.utc),                ]            ),            True,        ),        (            vDDDLists(                [                    datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc),                    datetime.datetime(2020, 2, 5, 20, 5, tzinfo=datetime.timezone.utc),                ]            ),            vDDDLists(                [                    datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc),                    datetime.datetime(2020, 2, 5, 20, 7, tzinfo=datetime.timezone.utc),                ]            ),            False,        ),        (            vDDDLists(                [                    datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc),                    datetime.datetime(2020, 2, 5, 20, 5, tzinfo=datetime.timezone.utc),                ]            ),            vDDDLists(                [                    datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc),                    datetime.datetime(2020, 2, 5, 20, 5, tzinfo=datetime.timezone.utc),                    datetime.datetime(2020, 2, 5, 20, 7, tzinfo=datetime.timezone.utc),                ]            ),            False,        ),        (            vCalAddress("someelse@somewhere.com"),            _parametrize(                vCalAddress("someelse@somewhere.com"),                dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),            ),            False,        ),        (            _parametrize(                vCalAddress("someelse@somewhere.com"),                dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),            ),            _parametrize(                vCalAddress("someelse@somewhere.com"),                dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),            ),            True,        ),        (            [                vCalAddress(                    "someone@somewhere.com",                ),                vCalAddress("someelse@somewhere.com"),            ],            [                vCalAddress(                    "someone@somewhere.com",                ),                _parametrize(                    vCalAddress("someelse@somewhere.com"),                    dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),                ),            ],            False,        ),        (            [                vCalAddress(                    "someone@somewhere.com",                ),                _parametrize(                    vCalAddress("someelse@somewhere.com"),                    dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),                ),            ],            [                vCalAddress(                    "someone@somewhere.com",                ),                _parametrize(                    vCalAddress("someelse@somewhere.com"),                    dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),                ),            ],            True,        ),    ],)def test__event_prop_equal(    prop_a: object, prop_b: object, expected_result: bool) -> None:    assert _event_prop_equal(prop_a, prop_b) == expected_result
 |