Skip to content

Commit

Permalink
test dict serialization with numeric keys
Browse files Browse the repository at this point in the history
  • Loading branch information
malcolmgreaves committed Mar 9, 2022
1 parent 9cdc59f commit 5fe5007
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tests/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from collections import namedtuple
from dataclasses import dataclass
from enum import Enum, IntEnum
from typing import NamedTuple, Sequence, Optional, Mapping, Set, Tuple, Union, Any
from typing import NamedTuple, Sequence, Optional, Mapping, Set, Tuple, Union, Any, List, Dict

from pytest import raises, fixture
import yaml
Expand Down Expand Up @@ -493,3 +493,22 @@ def test_serialize_none_special_cases_mapping():
assert len(s) == 1
assert deserialize(Mapping[str, Optional[int]], s) == m_empty
assert deserialize(Mapping[str, Optional[int]], serialize(m_empty)) == {}

def test_serialize_dict_with_numeric_keys():
d1: Dict[int, List[str]] = {
i: [x for x in 'hello world! how are you today?'] for i in range(10)
}
s1 = serialize(d1)
assert deserialize(Dict[int, List[str]], s1) == d1

j1 = json.dumps(s1)
assert deserialize(Dict[int, List[str]], json.loads(j1)) == d1

d2: Dict[float, List[str]] = {
float(i): xs for i, xs in d1.items()
}
s2 = serialize(d2)
assert deserialize(Dict[int, List[str]], s2) == d2

j2 = json.dumps(s2)
assert deserialize(Dict[int, List[str]], json.loads(j2)) == d2

0 comments on commit 5fe5007

Please sign in to comment.