Fix day filter
[cds-indico.git] / indico / util / event_test.py
blobb3d143cd625bcb829c5b3ec437bc1517816f29aa
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 import pytest
19 from indico.util.event import truncate_path
22 @pytest.mark.parametrize(('full_path', 'chars', 'skip_first', 'expected'), (
23 ([], 10, False, (None, None, None, False)),
24 (['aaa'], 5, False, (None, None, 'aaa', False)),
25 (['aaaaaa'], 5, False, (None, None, 'aaaaaa', False)),
26 (['aaa', 'bbb'], 10, False, ('aaa', None, 'bbb', False)),
27 (['aaa', 'bbb'], 5, False, (None, None, 'bbb', True)),
28 (['aaa', 'bbb', 'ccc'], 10, False, ('aaa', ['bbb'], 'ccc', False)),
29 (['aaa', 'bbb', 'ccc', 'ddd'], 20, False, ('aaa', ['bbb', 'ccc'], 'ddd', False)),
30 (['aaa', 'bbb', 'ccc', 'ddd'], 10, False, ('aaa', ['ccc'], 'ddd', True)),
31 (['aaa', 'bbb', 'ccc', 'ddd', 'eee'], 14, False, ('aaa', ['ccc', 'ddd'], 'eee', True)),
32 (['aaaaaaaa', 'bbb', 'ccc'], 10, False, (None, ['bbb'], 'ccc', True)),
33 (['aaaaaaaa', 'bbb', 'ccc', 'ddd'], 10, False, (None, ['bbb', 'ccc'], 'ddd', True)),
34 ([], 10, False, (None, None, None, False)),
35 (['aaa'], 5, True, (None, None, 'aaa', False)),
36 (['aaaaaa'], 5, True, (None, None, 'aaaaaa', False)),
37 (['aaa', 'bbb'], 10, True, ('aaa', None, 'bbb', False)),
38 (['aaa', 'bbb'], 5, True, (None, None, 'bbb', True)),
39 (['aaa', 'bbb', 'ccc'], 10, True, ('bbb', None, 'ccc', False)),
40 (['aaa', 'bbb', 'ccc', 'ddd'], 10, True, ('bbb', ['ccc'], 'ddd', False)),
41 (['aaa', 'bbb', 'ccc', 'ddd', 'eee'], 14, True, ('bbb', ['ccc', 'ddd'], 'eee', False)),
42 (['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff'], 14, True, ('bbb', ['ddd', 'eee'], 'fff', True)),
43 (['aaa', 'bbbbbbbb', 'ccc'], 10, True, (None, None, 'ccc', True)),
44 (['aaa', 'bbbbbbbb', 'ccc', 'ddd'], 10, True, (None, ['ccc'], 'ddd', True)),
45 (['aaa', 'bbbbbbbb', 'ccc', 'ddd', 'eee'], 10, True, (None, ['ccc', 'ddd'], 'eee', True)),
47 def test_truncate_path(full_path, chars, skip_first, expected):
48 assert truncate_path(full_path, chars=chars, skip_first=skip_first) == expected