Changeset View
Changeset View
Standalone View
Standalone View
swh/core/tests/test_utils.py
# Copyright (C) 2015-2017 The Software Heritage developers | # Copyright (C) 2015-2018 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import unittest | import unittest | ||||
from swh.core import utils | from swh.core import utils | ||||
Show All 14 Lines | def test_grouper(self): | ||||
actual_data = utils.grouper((i for i in range(9, 0, -1)), 4) | actual_data = utils.grouper((i for i in range(9, 0, -1)), 4) | ||||
out = [] | out = [] | ||||
for d in actual_data: | for d in actual_data: | ||||
out.append(list(d)) # force generator resolution for checks | out.append(list(d)) # force generator resolution for checks | ||||
self.assertEqual(out, [[9, 8, 7, 6], [5, 4, 3, 2], [1]]) | self.assertEqual(out, [[9, 8, 7, 6], [5, 4, 3, 2], [1]]) | ||||
def test_grouper_with_fillvalue(self): | |||||
# given | |||||
actual_data = utils.grouper(((i, i+1) for i in range(0, 9)), 2, | |||||
fillvalue=(None, None)) | |||||
out = [] | |||||
for d in actual_data: | |||||
out.append(list(d)) # force generator resolution for checks | |||||
self.assertEqual(out, [ | |||||
[(0, 1), (1, 2)], | |||||
[(2, 3), (3, 4)], | |||||
[(4, 5), (5, 6)], | |||||
[(6, 7), (7, 8)], | |||||
vlorentz: That line should be `[(8, 9), (None, None)]` | |||||
Done Inline ActionsAccording to the wrong docstring (because incomplete), you are correct! ardumont: According to the wrong docstring (because incomplete), you are correct! | |||||
[(8, 9)]]) | |||||
# given | |||||
actual_data = utils.grouper((i for i in range(9, 0, -1)), 4, | |||||
fillvalue='a') | |||||
out = [] | |||||
for d in actual_data: | |||||
out.append(list(d)) # force generator resolution for checks | |||||
Not Done Inline ActionsThat line should be: self.assertEqual(out, [[9, 8, 7, 6], [5, 4, 3, 2], [1, 'a', 'a', 'a']]) vlorentz: That line should be:
```
self.assertEqual(out, [[9, 8, 7, 6], [5, 4, 3, 2], [1, 'a', 'a'… | |||||
Done Inline ActionsAccording to the wrong docstring (because incomplete) you are correct! ardumont: According to the wrong docstring (because incomplete) you are correct! | |||||
self.assertEqual(out, [[9, 8, 7, 6], [5, 4, 3, 2], [1]]) | |||||
def test_backslashescape_errors(self): | def test_backslashescape_errors(self): | ||||
raw_data_err = b'abcd\x80' | raw_data_err = b'abcd\x80' | ||||
with self.assertRaises(UnicodeDecodeError): | with self.assertRaises(UnicodeDecodeError): | ||||
raw_data_err.decode('utf-8', 'strict') | raw_data_err.decode('utf-8', 'strict') | ||||
self.assertEqual( | self.assertEqual( | ||||
raw_data_err.decode('utf-8', 'backslashescape'), | raw_data_err.decode('utf-8', 'backslashescape'), | ||||
'abcd\\x80', | 'abcd\\x80', | ||||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |
That line should be [(8, 9), (None, None)]