Example #1
0
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}"
Example #2
0
def test_display_dataclass():
    @dataclass
    class DataclassDemo:
        a: str
        b: int

    d = DataclassDemo("word", 42)
    assert _display(d) == "{'a': 'word', 'b': 42}"
Example #3
0
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'}"
Example #4
0
def test_display_simple(item, output):
    assert _display(item) == output
Example #5
0
def test_display_element(element, output):
    assert _display(lxml.html.fromstring(element)) == output
Example #6
0
def test_display_pretty(data):
    assert _display(data) == pprint.pformat(data)