~homeworkprod/byceps

ref: 1181a35dd06d48c779208a6d2a4b3672dd38d812 byceps/tests/util/datetime/test_calc.py -rw-r--r-- 887 bytes
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
"""
:Copyright: 2006-2017 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.
"""

from datetime import date

import pytest

from byceps.util.datetime.calc import calculate_age, calculate_days_until


SOME_DATE = date(1994, 3, 18)


@pytest.mark.parametrize('today, expected', [
    (date(2014, 3, 17), 19),
    (date(2014, 3, 18), 20),
    (date(2014, 3, 19), 20),
    (date(2015, 3, 17), 20),
    (date(2015, 3, 18), 21),
    (date(2015, 3, 19), 21),
])
def test_calculate_age(today, expected):
    actual = calculate_age(SOME_DATE, today)

    assert actual == expected


@pytest.mark.parametrize('today, expected', [
    (date(2014, 3, 16), 2),
    (date(2014, 3, 17), 1),
    (date(2014, 3, 18), 0),
    (date(2014, 3, 19), 364),
])
def test_calculate_days_until(today, expected):
    actual = calculate_days_until(SOME_DATE, today)

    assert actual == expected