1 # This file is part of Indico.
2 # Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
4 # Indico is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3 of the
7 # License, or (at your option) any later version.
9 # Indico is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Indico; if not, see <http://www.gnu.org/licenses/>.
17 from datetime
import timedelta
20 from dateutil
.parser
import parse
22 from indico
.util
.date_time
import round_up_month
, format_human_timedelta
25 @pytest.mark
.parametrize(('current_date', 'from_day', 'expected_month'), (
26 ('2014-10-01', None, 11),
27 ('2014-10-01', 1, 11),
28 ('2014-10-01', 2, 10),
30 def test_round_up_month(current_date
, from_day
, expected_month
):
31 assert round_up_month(parse(current_date
), from_day
=from_day
).month
== expected_month
34 @pytest.mark
.parametrize(('delta', 'granularity', 'expected'), (
35 (timedelta(days
=0, hours
=0, minutes
=0, seconds
=0), 'seconds', '0 seconds'),
36 (timedelta(days
=0, hours
=0, minutes
=0, seconds
=0), 'minutes', '0 minutes'),
37 (timedelta(days
=0, hours
=0, minutes
=0, seconds
=0), 'hours', '0 hours'),
38 (timedelta(days
=0, hours
=0, minutes
=0, seconds
=0), 'days', '0 days'),
39 (timedelta(days
=0, hours
=0, minutes
=0, seconds
=5), 'seconds', '5 seconds'),
40 (timedelta(days
=0, hours
=0, minutes
=0, seconds
=5), 'minutes', '5 seconds'),
41 (timedelta(days
=0, hours
=0, minutes
=1, seconds
=5), 'seconds', '1m 5s'),
42 (timedelta(days
=0, hours
=0, minutes
=1, seconds
=5), 'minutes', '1 minute'),
43 (timedelta(days
=0, hours
=0, minutes
=1, seconds
=5), 'hours', '1 minute'),
44 (timedelta(days
=0, hours
=1, minutes
=10, seconds
=0), 'hours', '1 hour'),
45 (timedelta(days
=0, hours
=1, minutes
=30, seconds
=0), 'minutes', '1h 30m'),
46 (timedelta(days
=1, hours
=1, minutes
=0, seconds
=0), 'minutes', '1d 1h'),
47 (timedelta(days
=1, hours
=1, minutes
=10, seconds
=0), 'minutes', '1d 1h 10m'),
48 (timedelta(days
=1, hours
=1, minutes
=10, seconds
=0), 'hours', '1d 1h'),
49 (timedelta(days
=1, hours
=1, minutes
=0, seconds
=0), 'days', '1 day'),
50 (timedelta(days
=1, hours
=12, minutes
=0, seconds
=0), 'days', '1 day'),
51 (timedelta(days
=2, hours
=0, minutes
=0, seconds
=0), 'days', '2 days'),
52 (timedelta(days
=7, hours
=0, minutes
=0, seconds
=0), 'days', '7 days')
54 def test_format_human_timedelta(delta
, granularity
, expected
):
55 assert format_human_timedelta(delta
, granularity
) == expected