File: helpers.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 (20 lines) | stat: -rw-r--r-- 573 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
"""Helpers for tests."""

from typing import Any


def assert_only_unstructured(obj: Any):
    """Assert the object is comprised of only unstructured data:

    * dicts, lists, tuples
    * strings, ints, floats, bools, None
    """
    if isinstance(obj, dict):
        for k, v in obj.items():
            assert_only_unstructured(k)
            assert_only_unstructured(v)
    elif isinstance(obj, (list, tuple, frozenset, set)):
        for e in obj:
            assert_only_unstructured(e)
    else:
        assert isinstance(obj, (int, float, str, bool, type(None)))