File: test_serializer.py

package info (click to toggle)
freeorion 0.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 194,940 kB
  • sloc: cpp: 186,508; python: 40,969; ansic: 1,164; xml: 719; makefile: 32; sh: 7
file content (31 lines) | stat: -rw-r--r-- 754 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import pytest

from common.statistic_interface._serizlizer import (
    DictSerializer,
    to_float,
    to_int,
    to_str,
)


@pytest.mark.parametrize(
    ("converter", "serialized", "deserialized"),
    (
        (to_int, "11", 11),
        (to_float, "11.11", 11.11),
        (to_str, "hello", "hello"),
        (
            DictSerializer(
                {
                    "int": to_int,
                    "float": to_float,
                    "str": to_str,
                }
            ),
            "int: 11, float: 11.11, str: hello",
            {"int": 11, "float": 11.11, "str": "hello"},
        ),
    ),
)
def test_conversion(converter, serialized, deserialized):
    assert converter.deserialize(serialized) == deserialized