def test_inheritance(self): class A(object): def __init__(self): pass class B(A): pass class C(A): pass class D(C): pass class C2(C): pass class C3(C, B): pass class B2(B, C): pass class A2(A): pass @register_repr(A) def repr_A(_x, _helper): return 'A' @register_repr(C) def repr_C(_x, _helper): return 'C' @register_repr(B) def repr_B(_x, _helper): return 'B' @register_repr(D) def repr_D(_x, _helper): return 'D' self.assert_cheap_repr(A(), 'A') self.assert_cheap_repr(B(), 'B') self.assert_cheap_repr(C(), 'C') self.assert_cheap_repr(D(), 'D') self.assert_cheap_repr(C2(), 'C') self.assert_cheap_repr(C3(), 'C') self.assert_cheap_repr(B2(), 'B') self.assert_cheap_repr(A2(), 'A') self.assertEqual(find_repr_function(A), repr_A) self.assertEqual(find_repr_function(B), repr_B) self.assertEqual(find_repr_function(C), repr_C) self.assertEqual(find_repr_function(D), repr_D) self.assertEqual(find_repr_function(C2), repr_C) self.assertEqual(find_repr_function(C3), repr_C) self.assertEqual(find_repr_function(B2), repr_B) self.assertEqual(find_repr_function(A2), repr_A)
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]')
import re import sys import threading from collections import OrderedDict import six # noinspection PyUnresolvedReferences from cheap_repr import cheap_repr, find_repr_function, try_register_repr from snoop.utils import my_cheap_repr, ArgDefaultDict, iscoroutinefunction, \ truncate_list, ensure_tuple, is_comprehension_frame, no_args_decorator, pp_name_prefix, NO_BIRDSEYE, \ _register_cheap_reprs, PY34 from .formatting import Event, Source from .variables import CommonVariable, Exploding, BaseVariable find_repr_function(six.text_type).maxparts = 100 find_repr_function(six.binary_type).maxparts = 100 find_repr_function(object).maxparts = 100 find_repr_function(int).maxparts = 999999 cheap_repr.suppression_threshold = 999999 class FrameInfo(object): def __init__(self, frame): self.frame = frame self.local_reprs = {} self.last_line_no = frame.f_lineno self.comprehension_variables = OrderedDict() self.source = Source.for_frame(frame) code = frame.f_code self.is_generator = code.co_flags & inspect.CO_GENERATOR