def test_display_attr(): @attr.s class AttrDemo: a = attr.ib() b = attr.ib() d = AttrDemo("word", 42) assert _display(d) == "{'a': 'word', 'b': 42}"
def test_display_dataclass(): @dataclass class DataclassDemo: a: str b: int d = DataclassDemo("word", 42) assert _display(d) == "{'a': 'word', 'b': 42}"
def test_display_pydantic(): class ToDictDemo: # fake a pydantic-looking class without depending upon pydantic for tests __fields__ = ["a", "b"] def __init__(self, a, b): self.a = a self.b = b def dict(self): return {"val1": self.a, "b": self.b} d = ToDictDemo("a", [1, 2, 3, 4, 5, 6, 7, 8, 9]) assert _display(d) == "{'b': [1, 2, 3, 4, 5, 6, 7, 8, 9], 'val1': 'a'}"
def test_display_simple(item, output): assert _display(item) == output
def test_display_element(element, output): assert _display(lxml.html.fromstring(element)) == output
def test_display_pretty(data): assert _display(data) == pprint.pformat(data)