Exemple #1
0
    def __getstate__(self):
        """Avoid pickling objects in the traceback.
        """
        if self.pickled:
            return self.__dict__
        c = self.__dict__.copy()

        c['frames'] = [
            [
                v[0], v[1], v[2],
                [(j[0], _reflect.safe_repr(j[1])) for j in v[3]],
                [(j[0], _reflect.safe_repr(j[1])) for j in v[4]]
            ] for v in self.frames
        ]

        # added 2003-06-23. See comment above in __init__
        c['tb'] = None

        if self.stack is not None:
            # XXX: This is a band-aid.  I can't figure out where these
            # (failure.stack is None) instances are coming from.
            c['stack'] = [
                [
                    v[0], v[1], v[2],
                    [(j[0], _reflect.safe_repr(j[1])) for j in v[3]],
                    [(j[0], _reflect.safe_repr(j[1])) for j in v[4]]
                ] for v in self.stack
            ]

        c['pickled'] = 1
        return c
Exemple #2
0
 def test_brokenStr(self):
     """
     L{_reflect.safe_repr} isn't affected by a broken C{__str__} method.
     """
     b = Breakable()
     b.breakStr = True
     self.assertEquals(_reflect.safe_repr(b), repr(b))
Exemple #3
0
 def test_workingRepr(self):
     """
     L{_reflect.safe_repr} produces the same output as C{repr} on a working
     object.
     """
     x = [1, 2, 3]
     self.assertEquals(_reflect.safe_repr(x), repr(x))
Exemple #4
0
 def test_brokenStr(self):
     """
     L{_reflect.safe_repr} isn't affected by a broken C{__str__} method.
     """
     b = Breakable()
     b.breakStr = True
     self.assertEquals(_reflect.safe_repr(b), repr(b))
Exemple #5
0
 def test_workingRepr(self):
     """
     L{_reflect.safe_repr} produces the same output as C{repr} on a working
     object.
     """
     x = [1, 2, 3]
     self.assertEquals(_reflect.safe_repr(x), repr(x))
Exemple #6
0
 def test_brokenClassNameAttribute(self):
     """
     If a class raises an exception when accessing its C{__name__} attribute
     B{and} when calling its C{__str__} implementation, L{_reflect.safe_repr}
     returns 'BROKEN CLASS' instead of the class name.
     """
     class X(BTBase):
         breakName = True
     xRepr = _reflect.safe_repr(X())
     self.assertIn("<BROKEN CLASS AT 0x", xRepr)
     self.assertIn(os.path.splitext(__file__)[0], xRepr)
     self.assertIn("RuntimeError: repr!", xRepr)
Exemple #7
0
 def test_brokenClassAttribute(self):
     """
     If an object raises an exception when accessing its C{__class__}
     attribute, L{_reflect.safe_repr} uses C{type} to retrieve the class
     object.
     """
     b = NoClassAttr()
     b.breakRepr = True
     bRepr = _reflect.safe_repr(b)
     self.assertIn("NoClassAttr instance at 0x", bRepr)
     self.assertIn(os.path.splitext(__file__)[0], bRepr)
     self.assertIn("RuntimeError: repr!", bRepr)
Exemple #8
0
 def test_brokenClassAttribute(self):
     """
     If an object raises an exception when accessing its C{__class__}
     attribute, L{_reflect.safe_repr} uses C{type} to retrieve the class
     object.
     """
     b = NoClassAttr()
     b.breakRepr = True
     bRepr = _reflect.safe_repr(b)
     self.assertIn("NoClassAttr instance at 0x", bRepr)
     self.assertIn(os.path.splitext(__file__)[0], bRepr)
     self.assertIn("RuntimeError: repr!", bRepr)
Exemple #9
0
 def test_brokenRepr(self):
     """
     L{_reflect.safe_repr} returns a string with class name, address, and
     traceback when the repr call failed.
     """
     b = Breakable()
     b.breakRepr = True
     bRepr = _reflect.safe_repr(b)
     self.assertIn("Breakable instance at 0x", bRepr)
     # Check that the file is in the repr, but without the extension as it
     # can be .py/.pyc
     self.assertIn(os.path.splitext(__file__)[0], bRepr)
     self.assertIn("RuntimeError: repr!", bRepr)
Exemple #10
0
 def test_brokenRepr(self):
     """
     L{_reflect.safe_repr} returns a string with class name, address, and
     traceback when the repr call failed.
     """
     b = Breakable()
     b.breakRepr = True
     bRepr = _reflect.safe_repr(b)
     self.assertIn("Breakable instance at 0x", bRepr)
     # Check that the file is in the repr, but without the extension as it
     # can be .py/.pyc
     self.assertIn(os.path.splitext(__file__)[0], bRepr)
     self.assertIn("RuntimeError: repr!", bRepr)
Exemple #11
0
    def test_brokenClassNameAttribute(self):
        """
        If a class raises an exception when accessing its C{__name__} attribute
        B{and} when calling its C{__str__} implementation, L{_reflect.safe_repr}
        returns 'BROKEN CLASS' instead of the class name.
        """
        class X(BTBase):
            breakName = True

        xRepr = _reflect.safe_repr(X())
        self.assertIn("<BROKEN CLASS AT 0x", xRepr)
        self.assertIn(os.path.splitext(__file__)[0], xRepr)
        self.assertIn("RuntimeError: repr!", xRepr)
Exemple #12
0
    def test_unsignedID(self):
        """
        L{unsignedID} is used to print ID of the object in case of error, not
        standard ID value which can be negative.
        """
        class X(BTBase):
            breakRepr = True

        ids = {X: 100}
        def fakeID(obj):
            try:
                return ids[obj]
            except (TypeError, KeyError):
                return id(obj)
        self.addCleanup(_util.setIDFunction, _util.setIDFunction(fakeID))

        xRepr = _reflect.safe_repr(X)
        self.assertIn("0x64", xRepr)
Exemple #13
0
    def test_unsignedID(self):
        """
        L{unsignedID} is used to print ID of the object in case of error, not
        standard ID value which can be negative.
        """
        class X(BTBase):
            breakRepr = True

        ids = {X: 100}

        def fakeID(obj):
            try:
                return ids[obj]
            except (TypeError, KeyError):
                return id(obj)

        self.addCleanup(_util.setIDFunction, _util.setIDFunction(fakeID))

        xRepr = _reflect.safe_repr(X)
        self.assertIn("0x64", xRepr)
Exemple #14
0
 def test_brokenClassRepr(self):
     class X(BTBase):
         breakRepr = True
     _reflect.safe_repr(X)
     _reflect.safe_repr(X())
Exemple #15
0
    def test_brokenClassRepr(self):
        class X(BTBase):
            breakRepr = True

        _reflect.safe_repr(X)
        _reflect.safe_repr(X())