diff --git a/PKG-INFO b/PKG-INFO index 10903a6..acd0b00 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,10 +1,10 @@ Metadata-Version: 1.0 Name: swh.core -Version: 0.0.18 +Version: 0.0.19 Summary: Software Heritage core utilities Home-page: https://forge.softwareheritage.org/diffusion/DCORE/ Author: Software Heritage developers Author-email: swh-devel@inria.fr License: UNKNOWN Description: UNKNOWN Platform: UNKNOWN diff --git a/swh.core.egg-info/PKG-INFO b/swh.core.egg-info/PKG-INFO index 10903a6..acd0b00 100644 --- a/swh.core.egg-info/PKG-INFO +++ b/swh.core.egg-info/PKG-INFO @@ -1,10 +1,10 @@ Metadata-Version: 1.0 Name: swh.core -Version: 0.0.18 +Version: 0.0.19 Summary: Software Heritage core utilities Home-page: https://forge.softwareheritage.org/diffusion/DCORE/ Author: Software Heritage developers Author-email: swh-devel@inria.fr License: UNKNOWN Description: UNKNOWN Platform: UNKNOWN diff --git a/swh/core/tests/test_serializers.py b/swh/core/tests/test_serializers.py index 490dff0..49e5927 100644 --- a/swh/core/tests/test_serializers.py +++ b/swh/core/tests/test_serializers.py @@ -1,75 +1,75 @@ # Copyright (C) 2015 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import datetime import json import unittest from uuid import UUID from nose.tools import istest from swh.core.serializers import SWHJSONDecoder, SWHJSONEncoder from swh.core.serializers import msgpack_dumps, msgpack_loads class Serializers(unittest.TestCase): def setUp(self): self.tz = datetime.timezone(datetime.timedelta(minutes=118)) self.data = { - "bytes": b"123456789\x99\xaf\xff\x00\x12", - "datetime_naive": datetime.datetime(2015, 1, 1, 12, 4, 42, 231455), - "datetime_tz": datetime.datetime(2015, 3, 4, 18, 25, 13, 1234, + 'bytes': b'123456789\x99\xaf\xff\x00\x12', + 'datetime_naive': datetime.datetime(2015, 1, 1, 12, 4, 42, 231455), + 'datetime_tz': datetime.datetime(2015, 3, 4, 18, 25, 13, 1234, tzinfo=self.tz), - "datetime_utc": datetime.datetime(2015, 3, 4, 18, 25, 13, 1234, + 'datetime_utc': datetime.datetime(2015, 3, 4, 18, 25, 13, 1234, tzinfo=datetime.timezone.utc), - "swhtype": "fake", - "swh_dict": {"swhtype": 42, "d": "test"}, - "random_dict": {"swhtype": 43}, - "uuid": UUID('cdd8f804-9db6-40c3-93ab-5955d3836234'), + 'swhtype': 'fake', + 'swh_dict': {'swhtype': 42, 'd': 'test'}, + 'random_dict': {'swhtype': 43}, + 'uuid': UUID('cdd8f804-9db6-40c3-93ab-5955d3836234'), } self.encoded_data = { - "bytes": {"swhtype": "bytes", "d": "F)}kWH8wXmIhn8j01^"}, - "datetime_naive": {"swhtype": "datetime", - "d": "2015-01-01T12:04:42.231455"}, - "datetime_tz": {"swhtype": "datetime", - "d": "2015-03-04T18:25:13.001234+01:58"}, - "datetime_utc": {"swhtype": "datetime", - "d": "2015-03-04T18:25:13.001234+00:00"}, - "swhtype": "fake", - "swh_dict": {"swhtype": 42, "d": "test"}, - "random_dict": {"swhtype": 43}, - "uuid": {"swhtype": "uuid", - "d": "cdd8f804-9db6-40c3-93ab-5955d3836234"}, + 'bytes': {'swhtype': 'bytes', 'd': 'F)}kWH8wXmIhn8j01^'}, + 'datetime_naive': {'swhtype': 'datetime', + 'd': '2015-01-01T12:04:42.231455'}, + 'datetime_tz': {'swhtype': 'datetime', + 'd': '2015-03-04T18:25:13.001234+01:58'}, + 'datetime_utc': {'swhtype': 'datetime', + 'd': '2015-03-04T18:25:13.001234+00:00'}, + 'swhtype': 'fake', + 'swh_dict': {'swhtype': 42, 'd': 'test'}, + 'random_dict': {'swhtype': 43}, + 'uuid': {'swhtype': 'uuid', + 'd': 'cdd8f804-9db6-40c3-93ab-5955d3836234'}, } self.generator = (i for i in range(5)) self.gen_lst = list(range(5)) @istest def round_trip_json(self): data = json.dumps(self.data, cls=SWHJSONEncoder) self.assertEqual(self.data, json.loads(data, cls=SWHJSONDecoder)) @istest def encode_swh_json(self): data = json.dumps(self.data, cls=SWHJSONEncoder) self.assertEqual(self.encoded_data, json.loads(data)) @istest def round_trip_msgpack(self): data = msgpack_dumps(self.data) self.assertEqual(self.data, msgpack_loads(data)) @istest def generator_json(self): data = json.dumps(self.generator, cls=SWHJSONEncoder) self.assertEqual(self.gen_lst, json.loads(data, cls=SWHJSONDecoder)) @istest def generator_msgpack(self): data = msgpack_dumps(self.generator) self.assertEqual(self.gen_lst, msgpack_loads(data)) diff --git a/swh/core/tests/test_utils.py b/swh/core/tests/test_utils.py index 1475eaa..a2fe4a1 100644 --- a/swh/core/tests/test_utils.py +++ b/swh/core/tests/test_utils.py @@ -1,25 +1,33 @@ # Copyright (C) 2015-2016 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import unittest from nose.tools import istest from swh.core import utils -class UtilsTest(unittest.TestCase): +class UtilsLib(unittest.TestCase): + @istest def grouper(self): # given - gen = (d for d in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) + actual_data = utils.grouper((i for i in range(0, 9)), 2) + + out = [] + for d in actual_data: + out.append(list(d)) # force generator resolution for checks + + self.assertEqual(out, [[0, 1], [2, 3], [4, 5], [6, 7], [8]]) + + # given + actual_data = utils.grouper((i for i in range(9, 0, -1)), 4) - # when - actual_group = [] - for data in utils.grouper(gen, 3): - actual_group.append(list(data)) + out = [] + for d in actual_data: + out.append(list(d)) # force generator resolution for checks - # then - self.assertEquals(actual_group, [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]) + self.assertEqual(out, [[9, 8, 7, 6], [5, 4, 3, 2], [1]]) diff --git a/swh/core/utils.py b/swh/core/utils.py index 0559d96..4a225ef 100644 --- a/swh/core/utils.py +++ b/swh/core/utils.py @@ -1,26 +1,24 @@ -# Copyright (C) 2015-2016 The Software Heritage developers +# Copyright (C) 2016 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import itertools def grouper(iterable, n): """Collect data into fixed-length chunks or blocks. - The last block is exactly the size of the remaining data. Args: iterable: an iterable n: size of block + fillvalue: value to use for the last block Returns: - fixed-length chunks of blocks as iterables (except for the last - one which can be of size < n) + fixed-length chunks of blocks as iterables """ args = [iter(iterable)] * n - fv = None - for _data in itertools.zip_longest(*args, fillvalue=fv): - yield (d for d in _data if d is not fv) + for _data in itertools.zip_longest(*args, fillvalue=None): + yield (d for d in _data if d is not None) diff --git a/version.txt b/version.txt index 9acd593..dca3429 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v0.0.18-0-g5997d86 \ No newline at end of file +v0.0.19-0-g5a2ef92 \ No newline at end of file