~homeworkprod/byceps

ref: 1181a35dd06d48c779208a6d2a4b3672dd38d812 byceps/tests/util/datetime/test_monthday.py -rw-r--r-- 1.1 KiB
1181a35d — Jochen Kupperschmidt Ported tests from nose2 to pytest 4 years ago
                                                                                
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
"""
:Copyright: 2006-2017 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.
"""

from datetime import date

import pytest

from byceps.util.datetime.monthday import MonthDay


@pytest.mark.parametrize('date, expected_month, expected_day', [
    (date(1994,  3, 18),  3, 18),
    (date(2012,  9, 27),  9, 27),
    (date(2015,  1,  1),  1,  1),
    (date(2022, 12, 31), 12, 31),
])
def test_of(date, expected_month, expected_day):
    month_day = MonthDay.of(date)

    assert month_day.month == expected_month
    assert month_day.day == expected_day


@pytest.mark.parametrize('month, day, date, expected', [
    ( 3, 17, date(2005,  2, 17), False),
    ( 3, 17, date(2005,  3, 16), False),
    ( 3, 17, date(2005,  3, 17), True ),
    ( 3, 17, date(2014,  3, 17), True ),
    ( 3, 17, date(2017,  3, 17), True ),
    ( 3, 17, date(2005,  3, 18), False),
    ( 3, 17, date(2005,  4, 17), False),
    (12, 31, date(2010, 12, 30), False),
    (12, 31, date(2010, 12, 31), True ),
])
def test_matches(month, day, date, expected):
    month_day = MonthDay(month=month, day=day)

    actual = month_day.matches(date)

    assert actual == expected