|
4 | 4 | import sys
|
5 | 5 | import pytest
|
6 | 6 | import datetime
|
| 7 | +from typing import NamedTuple, Optional |
7 | 8 | from pickle import UnpicklingError
|
8 | 9 | from decimal import Decimal
|
| 10 | +from collections import Counter |
9 | 11 | from deepdiff import DeepDiff
|
10 | 12 | from deepdiff.helper import pypy3
|
11 | 13 | from deepdiff.serialization import (
|
|
23 | 25 | t2 = {1: 1, 2: 2, 3: 3, 4: {"a": "hello", "b": "world\n\n\nEnd"}}
|
24 | 26 |
|
25 | 27 |
|
| 28 | +class SomeStats(NamedTuple): |
| 29 | + counter: Optional[Counter] |
| 30 | + context_aware_counter: Optional[Counter] = None |
| 31 | + min_int: Optional[int] = 0 |
| 32 | + max_int: Optional[int] = 0 |
| 33 | + |
| 34 | + |
| 35 | +field_stats1 = SomeStats( |
| 36 | + counter=Counter(["a", "a", "b"]), |
| 37 | + max_int=10 |
| 38 | +) |
| 39 | + |
| 40 | + |
26 | 41 | class TestSerialization:
|
27 | 42 | """Tests for Serializations."""
|
28 | 43 |
|
@@ -323,6 +338,7 @@ def test_pretty_form_method(self, expected, verbose_level):
|
323 | 338 | (5, {1, 2, 10}, set),
|
324 | 339 | (6, datetime.datetime(2023, 10, 11), datetime.datetime.fromisoformat),
|
325 | 340 | (7, datetime.datetime.utcnow(), datetime.datetime.fromisoformat),
|
| 341 | + (8, field_stats1, lambda x: SomeStats(**x)), |
326 | 342 | ])
|
327 | 343 | def test_json_dumps_and_loads(self, test_num, value, func_to_convert_back):
|
328 | 344 | serialized = json_dumps(value)
|
|
0 commit comments