File: test_recursive.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 (25 lines) | stat: -rw-r--r-- 420 bytes parent folder | download | duplicates (2)
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
"""Test un/structuring recursive class graphs."""

from __future__ import annotations

from typing import List

from attr import define

from cattr import Converter


@define
class A:
    inner: List[A]


def test_simple_recursive():
    c = Converter()

    orig = A([A([])])
    unstructured = c.unstructure(orig)

    assert unstructured == {"inner": [{"inner": []}]}

    assert c.structure(unstructured, A) == orig