Example #1
0
    def test_repr_local_truncated(self):
        loc = {"l": [i for i in range(10)]}
        p = FormattedExcinfo(showlocals=True)
        truncated_reprlocals = p.repr_locals(loc)
        assert truncated_reprlocals.lines
        assert truncated_reprlocals.lines[0] == "l          = [0, 1, 2, 3, 4, 5, ...]"

        q = FormattedExcinfo(showlocals=True, truncate_locals=False)
        full_reprlocals = q.repr_locals(loc)
        assert full_reprlocals.lines
        assert full_reprlocals.lines[0] == "l          = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
Example #2
0
    def test_repr_local_truncated(self):
        loc = {"l": [i for i in range(10)]}
        p = FormattedExcinfo(showlocals=True)
        truncated_reprlocals = p.repr_locals(loc)
        assert truncated_reprlocals.lines
        assert truncated_reprlocals.lines[0] == "l          = [0, 1, 2, 3, 4, 5, ...]"

        q = FormattedExcinfo(showlocals=True, truncate_locals=False)
        full_reprlocals = q.repr_locals(loc)
        assert full_reprlocals.lines
        assert full_reprlocals.lines[0] == "l          = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
Example #3
0
 def test_repr_local(self):
     p = FormattedExcinfo(showlocals=True)
     loc = {"y": 5, "z": 7, "x": 3, "@x": 2, "__builtins__": {}}
     reprlocals = p.repr_locals(loc)
     assert reprlocals.lines
     assert reprlocals.lines[0] == "__builtins__ = <builtins>"
     assert reprlocals.lines[1] == "x          = 3"
     assert reprlocals.lines[2] == "y          = 5"
     assert reprlocals.lines[3] == "z          = 7"
Example #4
0
 def test_repr_local(self):
     p = FormattedExcinfo(showlocals=True)
     loc = {'y': 5, 'z': 7, 'x': 3, '@x': 2, '__builtins__': {}}
     reprlocals = p.repr_locals(loc)
     assert reprlocals.lines
     assert reprlocals.lines[0] == '__builtins__ = <builtins>'
     assert reprlocals.lines[1] == 'x          = 3'
     assert reprlocals.lines[2] == 'y          = 5'
     assert reprlocals.lines[3] == 'z          = 7'
Example #5
0
 def test_repr_local(self):
     p = FormattedExcinfo(showlocals=True)
     loc = {'y': 5, 'z': 7, 'x': 3, '@x': 2, '__builtins__': {}}
     reprlocals = p.repr_locals(loc)
     assert reprlocals.lines
     assert reprlocals.lines[0] == '__builtins__ = <builtins>'
     assert reprlocals.lines[1] == 'x          = 3'
     assert reprlocals.lines[2] == 'y          = 5'
     assert reprlocals.lines[3] == 'z          = 7'
Example #6
0
 def test_repr_local(self):
     p = FormattedExcinfo(showlocals=True)
     loc = {"y": 5, "z": 7, "x": 3, "@x": 2, "__builtins__": {}}
     reprlocals = p.repr_locals(loc)
     assert reprlocals.lines
     assert reprlocals.lines[0] == "__builtins__ = <builtins>"
     assert reprlocals.lines[1] == "x          = 3"
     assert reprlocals.lines[2] == "y          = 5"
     assert reprlocals.lines[3] == "z          = 7"
Example #7
0
    def test_repr_local_with_error(self):
        class ObjWithErrorInRepr:
            def __repr__(self):
                raise NotImplementedError

        p = FormattedExcinfo(showlocals=True, truncate_locals=False)
        loc = {"x": ObjWithErrorInRepr(), "__builtins__": {}}
        reprlocals = p.repr_locals(loc)
        assert reprlocals.lines
        assert reprlocals.lines[0] == "__builtins__ = <builtins>"
        assert '[NotImplementedError("") raised in repr()]' in reprlocals.lines[1]
Example #8
0
    def test_repr_local_with_exception_in_class_property(self):
        class ExceptionWithBrokenClass(Exception):
            @property
            def __class__(self):
                raise TypeError("boom!")

        class ObjWithErrorInRepr:
            def __repr__(self):
                raise ExceptionWithBrokenClass()

        p = FormattedExcinfo(showlocals=True, truncate_locals=False)
        loc = {"x": ObjWithErrorInRepr(), "__builtins__": {}}
        reprlocals = p.repr_locals(loc)
        assert reprlocals.lines
        assert reprlocals.lines[0] == "__builtins__ = <builtins>"
        assert '[ExceptionWithBrokenClass("") raised in repr()]' in reprlocals.lines[1]
Example #9
0
    def test_repr_local_with_exception_in_class_property(self):
        class ExceptionWithBrokenClass(Exception):
            # Type ignored because it's bypassed intentionally.
            @property  # type: ignore
            def __class__(self):
                raise TypeError("boom!")

        class ObjWithErrorInRepr:
            def __repr__(self):
                raise ExceptionWithBrokenClass()

        p = FormattedExcinfo(showlocals=True, truncate_locals=False)
        loc = {"x": ObjWithErrorInRepr(), "__builtins__": {}}
        reprlocals = p.repr_locals(loc)
        assert reprlocals.lines
        assert reprlocals.lines[0] == "__builtins__ = <builtins>"
        assert "[ExceptionWithBrokenClass() raised in repr()]" in reprlocals.lines[1]