File: test_literals.py

package info (click to toggle)
python-cattrs 25.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,812 kB
  • sloc: python: 12,236; makefile: 155
file content (19 lines) | stat: -rw-r--r-- 549 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from enum import Enum
from typing import Literal

from cattrs import BaseConverter
from cattrs.fns import identity


class AnEnum(Enum):
    TEST = "test"


def test_unstructure_literal(converter: BaseConverter):
    """Literals without enums are passed through by default."""
    assert converter.get_unstructure_hook(1, Literal[1]) == identity


def test_unstructure_literal_with_enum(converter: BaseConverter):
    """Literals with enums are properly unstructured."""
    assert converter.unstructure(AnEnum.TEST, Literal[AnEnum.TEST]) == "test"