MCPcopy Index your code
hub / github.com/python/cpython / test_same_as_repr

Method test_same_as_repr

Lib/test/test_pprint.py:249–291  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

247 "expected not isreadable for %r" % (unreadable,))
248
249 def test_same_as_repr(self):
250 # Simple objects, small containers and classes that override __repr__
251 # to directly call super's __repr__.
252 # For those the result should be the same as repr().
253 # Ahem. The docs don't say anything about that -- this appears to
254 # be testing an implementation quirk. Starting in Python 2.5, it's
255 # not true for dicts: pprint always sorts dicts by key now; before,
256 # it sorted a dict display if and only if the display required
257 # multiple lines. For that reason, dicts with more than one element
258 # aren't tested here.
259 for simple in (0, 0, 0+0j, 0.0, "", b"", bytearray(),
260 (), tuple2(), tuple3(),
261 [], list2(), list3(),
262 set(), set2(), set3(),
263 frozenset(), frozenset2(), frozenset3(),
264 {}, dict2(), dict3(),
265 frozendict(), frozendict2(), frozendict3(),
266 {}.keys(), {}.values(), {}.items(),
267 MappingView({}), KeysView({}), ItemsView({}), ValuesView({}),
268 self.assertTrue, pprint,
269 -6, -6, -6-6j, -1.5, "x", b"x", bytearray(b"x"),
270 (3,), [3], {3: 6},
271 (1,2), [3,4],
272 tuple2((1,2)), tuple3((1,2)), tuple3(range(100)),
273 [3,4], list2([3,4]), list3([3,4]), list3(range(100)),
274 set({7}), set2({7}), set3({7}),
275 frozenset({8}), frozenset2({8}), frozenset3({8}),
276 {5: 6}, dict2({5: 6}), dict3({5: 6}),
277 frozendict({5: 6}), frozendict2({5: 6}), frozendict3({5: 6}),
278 {5: 6}.keys(), {5: 6}.values(), {5: 6}.items(),
279 frozendict({5: 6}).keys(), frozendict({5: 6}).values(),
280 frozendict({5: 6}).items(),
281 MappingView({5: 6}), KeysView({5: 6}),
282 ItemsView({5: 6}), ValuesView({5: 6}),
283 range(10, -11, -1),
284 True, False, None, ...,
285 ):
286 native = repr(simple)
287 self.assertEqual(pprint.pformat(simple), native)
288 self.assertEqual(pprint.pformat(simple, width=1, indent=0)
289 .replace('\n', ' '), native)
290 self.assertEqual(pprint.pformat(simple, underscore_numbers=True), native)
291 self.assertEqual(pprint.saferepr(simple), native)
292
293 def test_container_repr_override_called(self):
294 N = 1000

Callers

nothing calls this directly

Calls 15

MappingViewClass · 0.90
KeysViewClass · 0.90
ItemsViewClass · 0.90
ValuesViewClass · 0.90
tuple2Class · 0.85
tuple3Class · 0.85
list2Class · 0.85
list3Class · 0.85
setFunction · 0.85
set2Class · 0.85
set3Class · 0.85
frozenset2Class · 0.85

Tested by

no test coverage detected