Changeset View
Changeset View
Standalone View
Standalone View
swh/journal/tests/test_serializers.py
# Copyright (C) 2017 The Software Heritage developers | # Copyright (C) 2017-2020 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 | ||||
from collections import OrderedDict | |||||
import itertools | import itertools | ||||
from collections import OrderedDict | |||||
from typing import Iterable | |||||
from swh.journal import serializers | from swh.journal import serializers | ||||
from .conftest import TEST_OBJECTS | from .conftest import TEST_OBJECTS | ||||
def test_key_to_kafka_repeatable(): | def test_key_to_kafka_repeatable(): | ||||
"""Check the kafka key encoding is repeatable""" | """Check the kafka key encoding is repeatable""" | ||||
base_dict = { | base_dict = { | ||||
Show All 29 Lines | for object_type, objects in TEST_OBJECTS.items(): | ||||
if isinstance(key, dict): | if isinstance(key, dict): | ||||
assert pprinted_key[0], pprinted_key[-1] == "{}" | assert pprinted_key[0], pprinted_key[-1] == "{}" | ||||
for dict_key in key.keys(): | for dict_key in key.keys(): | ||||
assert f"{dict_key}:" in pprinted_key | assert f"{dict_key}:" in pprinted_key | ||||
if isinstance(key, bytes): | if isinstance(key, bytes): | ||||
assert pprinted_key == key.hex() | assert pprinted_key == key.hex() | ||||
def test_kafka_to_key(): | |||||
"""Standard back and forth serialization with keys | |||||
""" | |||||
# All KeyType(s) | |||||
keys: Iterable[serializers.KeyType] = [ | |||||
{"a": "foo", "b": "bar", "c": "baz",}, | |||||
{"a": b"foobarbaz",}, | |||||
b"foo", | |||||
] | |||||
for key in keys: | |||||
ktk = serializers.key_to_kafka(key) | |||||
v = serializers.kafka_to_key(ktk) | |||||
ardumont: Note that i tried to mock my way into testing the compatibility behavior.
But i hit a… | |||||
assert v == key |
Note that i tried to mock my way into testing the compatibility behavior.
But i hit a recursion problem. Since the current tox uses a msgpack version > 6
which has that optional (strict_map_key=False).