Lines Matching refs:self

20     def __repr__(self):
21 return list.__repr__(self)
24 def __repr__(self):
25 return '*'*len(list.__repr__(self))
31 def __repr__(self):
32 return tuple.__repr__(self)
35 def __repr__(self):
36 return '*'*len(tuple.__repr__(self))
42 def __repr__(self):
43 return set.__repr__(self)
46 def __repr__(self):
47 return '*'*len(set.__repr__(self))
53 def __repr__(self):
54 return frozenset.__repr__(self)
57 def __repr__(self):
58 return '*'*len(frozenset.__repr__(self))
64 def __repr__(self):
65 return dict.__repr__(self)
68 def __repr__(self):
69 return '*'*len(dict.__repr__(self))
81 def __repr__(self):
104 def __repr__(self):
105 return str(id(self))
109 def __init__(self, hash):
110 self._hash = hash
111 def __lt__(self, other):
113 def __gt__(self, other):
114 return self != other
115 def __le__(self, other):
116 return self == other
117 def __ge__(self, other):
119 def __eq__(self, other):
120 return self is other
121 def __ne__(self, other):
122 return self is not other
123 def __hash__(self):
124 return self._hash
128 def setUp(self):
129 self.a = list(range(100))
130 self.b = list(range(200))
131 self.a[-12] = self.b
133 def test_init(self):
139 with self.assertRaises(TypeError):
141 self.assertRaises(ValueError, pprint.PrettyPrinter, indent=-1)
142 self.assertRaises(ValueError, pprint.PrettyPrinter, depth=0)
143 self.assertRaises(ValueError, pprint.PrettyPrinter, depth=-1)
144 self.assertRaises(ValueError, pprint.PrettyPrinter, width=0)
146 def test_basic(self):
151 self.a, self.b):
153 self.assertFalse(pprint.isrecursive(safe),
155 self.assertTrue(pprint.isreadable(safe),
158 self.assertFalse(pp.isrecursive(safe),
160 self.assertTrue(pp.isreadable(safe),
163 def test_stdout_is_None(self):
170 def test_knotted(self):
173 self.b[67] = self.a
175 self.d = {}
176 self.d[0] = self.d[1] = self.d[2] = self.d
180 for icky in self.a, self.b, self.d, (self.d, self.d):
181 self.assertTrue(pprint.isrecursive(icky), "expected isrecursive")
182 self.assertFalse(pprint.isreadable(icky), "expected not isreadable")
183 self.assertTrue(pp.isrecursive(icky), "expected isrecursive")
184 self.assertFalse(pp.isreadable(icky), "expected not isreadable")
187 self.d.clear()
188 del self.a[:]
189 del self.b[:]
191 for safe in self.a, self.b, self.d, (self.d, self.d):
193 self.assertFalse(pprint.isrecursive(safe),
195 self.assertTrue(pprint.isreadable(safe),
198 self.assertFalse(pp.isrecursive(safe),
200 self.assertTrue(pp.isreadable(safe),
203 def test_unreadable(self):
208 self.assertFalse(pprint.isrecursive(unreadable),
210 self.assertFalse(pprint.isreadable(unreadable),
213 self.assertFalse(pp.isrecursive(unreadable),
215 self.assertFalse(pp.isreadable(unreadable),
218 def test_same_as_repr(self):
234 self.assertTrue, pprint,
247 self.assertEqual(pprint.pformat(simple), native)
248 self.assertEqual(pprint.pformat(simple, width=1, indent=0)
250 self.assertEqual(pprint.pformat(simple, underscore_numbers=True), native)
251 self.assertEqual(pprint.saferepr(simple), native)
253 def test_container_repr_override_called(self):
275 self.assertEqual(pprint.pformat(cont), expected)
276 self.assertEqual(pprint.pformat(cont, width=1, indent=0), expected)
277 self.assertEqual(pprint.saferepr(cont), expected)
279 def test_basic_line_wrap(self):
297 self.assertEqual(pprint.pformat(type(o)), exp)
302 self.assertEqual(pprint.pformat(type(o)), exp)
307 self.assertEqual(pprint.pformat(type(o)), exp)
313 self.assertEqual(pprint.pformat(type(o), indent=4), exp)
315 def test_nested_indentations(self):
322 self.assertEqual(pprint.pformat(o, indent=4, width=42), expected)
328 self.assertEqual(pprint.pformat(o, indent=4, width=41), expected)
330 def test_width(self):
342 self.assertEqual(pprint.pformat(o, width=15), expected)
343 self.assertEqual(pprint.pformat(o, width=16), expected)
344 self.assertEqual(pprint.pformat(o, width=25), expected)
345 self.assertEqual(pprint.pformat(o, width=14), """\
368 def test_integer(self):
369 self.assertEqual(pprint.pformat(1234567), '1234567')
370 self.assertEqual(pprint.pformat(1234567, underscore_numbers=True), '1_234_567')
375 def __repr__(self):
376 kelvin_degrees = self + 273.15
378 self.assertEqual(pprint.pformat(Temperature(1000)), '1273.15°K')
380 def test_sorted_dict(self):
386 self.assertEqual(pprint.pformat(d), "{'a': 1, 'b': 1, 'c': 1}")
387 self.assertEqual(pprint.pformat([d, d]),
395 self.assertEqual(pprint.pformat({"xy\tab\n": (3,), 5: [[]], (): {}}),
398 def test_sort_dict(self):
400 self.assertEqual(pprint.pformat(d, sort_dicts=False), "{'c': None, 'b': None, 'a': None}")
401 self.assertEqual(pprint.pformat([d, d], sort_dicts=False),
404 def test_ordered_dict(self):
406 self.assertEqual(pprint.pformat(d, width=1), 'OrderedDict()')
408 self.assertEqual(pprint.pformat(d, width=1), 'OrderedDict()')
411 self.assertEqual(pprint.pformat(d),
423 def test_mapping_proxy(self):
427 self.assertEqual(pprint.pformat(m), """\
439 self.assertEqual(pprint.pformat(m), """\
450 def test_empty_simple_namespace(self):
453 self.assertEqual(formatted, "namespace()")
455 def test_small_simple_namespace(self):
458 self.assertEqual(formatted, "namespace(a=1, b=2)")
460 def test_simple_namespace(self):
473 self.assertEqual(formatted, """\
484 def test_simple_namespace_subclass(self):
498 self.assertEqual(formatted, """\
509 def test_empty_dataclass(self):
512 self.assertEqual(formatted, "MyDataclass()")
514 def test_small_dataclass(self):
517 self.assertEqual(formatted, "dataclass1(field1='text', field2=123, field3=False)")
519 def test_larger_dataclass(self):
522 self.assertEqual(formatted, """\
530 def test_dataclass_with_repr(self):
533 self.assertEqual(formatted, "custom repr that doesn't fit within pprint width")
535 def test_dataclass_no_repr(self):
538 self.assertRegex(formatted, r"<test.test_pprint.dataclass3 object at \w+>")
540 def test_recursive_dataclass(self):
544 self.assertEqual(formatted, """\
548 def test_cyclic_dataclass(self):
554 self.assertEqual(formatted, """\
559 def test_subclassing(self):
568 self.assertEqual(dotted_printer.pformat(o), exp)
573 self.assertEqual(dotted_printer.pformat(o1), exp1)
576 self.assertEqual(dotted_printer.pformat(o2), exp2)
578 def test_set_reprs(self):
579 self.assertEqual(pprint.pformat(set()), 'set()')
580 self.assertEqual(pprint.pformat(set(range(3))), '{0, 1, 2}')
581 self.assertEqual(pprint.pformat(set(range(7)), width=20), '''\
589 self.assertEqual(pprint.pformat(set2(range(7)), width=20), '''\
597 self.assertEqual(pprint.pformat(set3(range(7)), width=20),
600 self.assertEqual(pprint.pformat(frozenset()), 'frozenset()')
601 self.assertEqual(pprint.pformat(frozenset(range(3))),
603 self.assertEqual(pprint.pformat(frozenset(range(7)), width=20), '''\
611 self.assertEqual(pprint.pformat(frozenset2(range(7)), width=20), '''\
619 self.assertEqual(pprint.pformat(frozenset3(range(7)), width=20),
625 def test_set_of_sets_reprs(self):
672 self.assertEqual(pprint.pformat(cube), cube_repr_tgt)
832 self.assertEqual(pprint.pformat(cubo), cubo_repr_tgt)
834 def test_depth(self):
838 self.assertEqual(pprint.pformat(nested_tuple), repr(nested_tuple))
839 self.assertEqual(pprint.pformat(nested_dict), repr(nested_dict))
840 self.assertEqual(pprint.pformat(nested_list), repr(nested_list))
845 self.assertEqual(pprint.pformat(nested_tuple, depth=1), lv1_tuple)
846 self.assertEqual(pprint.pformat(nested_dict, depth=1), lv1_dict)
847 self.assertEqual(pprint.pformat(nested_list, depth=1), lv1_list)
849 def test_sort_unorderable_values(self):
857 self.assertEqual(clean(pprint.pformat(set(keys))),
859 self.assertEqual(clean(pprint.pformat(frozenset(keys))),
861 self.assertEqual(clean(pprint.pformat(dict.fromkeys(keys))),
865 self.assertEqual(pprint.pformat({Unorderable: 0, 1: 0}),
870 self.assertEqual(pprint.pformat(dict.fromkeys(keys, 0)),
873 def test_sort_orderable_and_unorderable_values(self):
877 # self-test
878 self.assertLess(a, b)
879 self.assertLess(str(type(b)), str(type(a)))
880 self.assertEqual(sorted([b, a]), [a, b])
881 self.assertEqual(sorted([a, b]), [a, b])
883 self.assertEqual(pprint.pformat(set([b, a]), width=1),
885 self.assertEqual(pprint.pformat(set([a, b]), width=1),
888 self.assertEqual(pprint.pformat(dict.fromkeys([b, a]), width=1),
890 self.assertEqual(pprint.pformat(dict.fromkeys([a, b]), width=1),
893 def test_str_wrap(self):
896 self.assertEqual(pprint.pformat(fox, width=19), """\
900 self.assertEqual(pprint.pformat({'a': 1, 'b': fox, 'c': 2},
913 self.assertEqual(pprint.pformat(special, width=68), repr(special))
914 self.assertEqual(pprint.pformat(special, width=31), """\
918 self.assertEqual(pprint.pformat(special, width=20), """\
924 self.assertEqual(pprint.pformat([[[[[special]]]]], width=35), """\
928 self.assertEqual(pprint.pformat([[[[[special]]]]], width=25), """\
934 self.assertEqual(pprint.pformat([[[[[special]]]]], width=23), """\
943 self.assertEqual(pprint.pformat(unwrappable, width=80), repr(unwrappable))
944 self.assertEqual(pprint.pformat(''), "''")
949 self.assertEqual(eval(formatted), special)
951 self.assertEqual(eval(formatted), [special] * 2)
953 def test_compact(self):
963 self.assertEqual(pprint.pformat(o, width=47, compact=True), expected)
965 def test_compact_width(self):
974 self.assertLessEqual(maxwidth, w)
975 self.assertGreater(maxwidth, w - 3)
977 def test_bytes_wrap(self):
978 self.assertEqual(pprint.pformat(b'', width=1), "b''")
979 self.assertEqual(pprint.pformat(b'abcd', width=1), "b'abcd'")
981 self.assertEqual(pprint.pformat(letters, width=29), repr(letters))
982 self.assertEqual(pprint.pformat(letters, width=19), """\
985 self.assertEqual(pprint.pformat(letters, width=18), """\
989 self.assertEqual(pprint.pformat(letters, width=16), """\
994 self.assertEqual(pprint.pformat(special, width=61), repr(special))
995 self.assertEqual(pprint.pformat(special, width=48), """\
998 self.assertEqual(pprint.pformat(special, width=32), """\
1002 self.assertEqual(pprint.pformat(special, width=1), """\
1007 self.assertEqual(pprint.pformat({'a': 1, 'b': letters, 'c': 2},
1014 self.assertEqual(pprint.pformat({'a': 1, 'b': letters, 'c': 2},
1021 self.assertEqual(pprint.pformat([[[[[[letters]]]]]], width=25), """\
1024 self.assertEqual(pprint.pformat([[[[[[special]]]]]], width=41), """\
1030 self.assertEqual(eval(formatted), special)
1032 self.assertEqual(eval(formatted), [special] * 2)
1034 def test_bytearray_wrap(self):
1035 self.assertEqual(pprint.pformat(bytearray(), width=1), "bytearray(b'')")
1037 self.assertEqual(pprint.pformat(letters, width=40), repr(letters))
1038 self.assertEqual(pprint.pformat(letters, width=28), """\
1041 self.assertEqual(pprint.pformat(letters, width=27), """\
1045 self.assertEqual(pprint.pformat(letters, width=25), """\
1050 self.assertEqual(pprint.pformat(special, width=72), repr(special))
1051 self.assertEqual(pprint.pformat(special, width=57), """\
1054 self.assertEqual(pprint.pformat(special, width=41), """\
1058 self.assertEqual(pprint.pformat(special, width=1), """\
1063 self.assertEqual(pprint.pformat({'a': 1, 'b': letters, 'c': 2},
1070 self.assertEqual(pprint.pformat([[[[[letters]]]]], width=37), """\
1073 self.assertEqual(pprint.pformat([[[[[special]]]]], width=50), """\
1077 def test_default_dict(self):
1079 self.assertEqual(pprint.pformat(d, width=1), "defaultdict(<class 'int'>, {})")
1082 self.assertEqual(pprint.pformat(d),
1095 def test_counter(self):
1097 self.assertEqual(pprint.pformat(d, width=1), "Counter()")
1099 self.assertEqual(pprint.pformat(d, width=40),
1106 def test_chainmap(self):
1108 self.assertEqual(pprint.pformat(d, width=1), "ChainMap({})")
1112 self.assertEqual(pprint.pformat(d),
1124 self.assertEqual(pprint.pformat(d),
1145 def test_deque(self):
1147 self.assertEqual(pprint.pformat(d, width=1), "deque([])")
1149 self.assertEqual(pprint.pformat(d, width=1), "deque([], maxlen=7)")
1152 self.assertEqual(pprint.pformat(d),
1164 self.assertEqual(pprint.pformat(d),
1175 def test_user_dict(self):
1177 self.assertEqual(pprint.pformat(d, width=1), "{}")
1180 self.assertEqual(pprint.pformat(d),
1192 def test_user_list(self):
1194 self.assertEqual(pprint.pformat(d, width=1), "[]")
1197 self.assertEqual(pprint.pformat(d),
1209 def test_user_string(self):
1211 self.assertEqual(pprint.pformat(d, width=1), "''")
1213 self.assertEqual(pprint.pformat(d, width=20),
1218 self.assertEqual(pprint.pformat({1: d}, width=20),
1228 def format(self, object, context, maxlevels, level):
1236 self, object, context, maxlevels, level)