def test_maxparts(self):
     self.assert_cheap_repr(list(range(8)),
                            '[0, 1, 2, ..., 5, 6, 7]')
     self.assert_cheap_repr(list(range(20)),
                            '[0, 1, 2, ..., 17, 18, 19]')
     with temp_attrs(find_repr_function(list), 'maxparts', 10):
         self.assert_cheap_repr(list(range(8)),
                                '[0, 1, 2, 3, 4, 5, 6, 7]')
         self.assert_cheap_repr(list(range(20)),
                                '[0, 1, 2, 3, 4, ..., 15, 16, 17, 18, 19]')
Exemple #2
0
    def test_exceptions(self):
        with temp_attrs(cheap_repr, 'raise_exceptions', True):
            with self.assertRaises(ValueError):
                cheap_repr(ErrorClass(True))

        for C in [ErrorClass, OldStyleErrorClass]:
            name = C.__name__
            self.assert_usual_repr(C())
            self.assert_cheap_repr_warns(
                C(True),
                "Exception 'ValueError' in repr_object for object of type %s. "
                "The repr has been suppressed for this type." % name,
                '<%s instance at 0xXXX (exception in repr)>' % name,
            )
            self.assert_cheap_repr(C(), '<%s instance at 0xXXX (repr suppressed)>' % name)
        for C in [ErrorClassChild, OldStyleErrorClassChild]:
            name = C.__name__
            self.assert_cheap_repr(C(), '<%s instance at 0xXXX (repr suppressed)>' % name)
    def test_exceptions(self):
        with temp_attrs(cheap_repr, 'raise_exceptions', True):
            self.assertRaises(ValueError,
                              lambda: cheap_repr(ErrorClass(True)))

        for C in [ErrorClass, OldStyleErrorClass]:
            name = C.__name__
            self.assert_usual_repr(C())
            warning_message = "Exception 'ValueError' in repr_object for object of type %s. " \
                              "The repr has been suppressed for this type." % name
            if PY2 and C is OldStyleErrorClass:
                warning_message = warning_message.replace('repr_object', 'repr')
            self.assert_cheap_repr_warns(
                C(True),
                warning_message,
                '<%s instance at 0xXXX (exception in repr)>' % name,
            )
            self.assert_cheap_repr(C(), '<%s instance at 0xXXX (repr suppressed)>' % name)
        for C in [ErrorClassChild, OldStyleErrorClassChild]:
            name = C.__name__
            self.assert_cheap_repr(C(), '<%s instance at 0xXXX (repr suppressed)>' % name)