~homeworkprod/byceps

ref: 9f63b62a2b4647a97ebd3b6356d937ffa1d88876 byceps/tests/util/datetime/test_calc.py -rw-r--r-- 828 bytes
9f63b62a — Jochen Kupperschmidt Note that Python 3.6 is a supported Python version 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

from nose2.tools import params

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


SOME_DATE = date(1994, 3, 18)


@params(
    (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


@params(
    (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