MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_same_as_repr

Method test_same_as_repr

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

Source from the content-addressed store, hash-verified

222 "expected not isreadable for %r" % (unreadable,))
223
224 def test_same_as_repr(self):
225 # Simple objects, small containers and classes that override __repr__
226 # to directly call super's __repr__.
227 # For those the result should be the same as repr().
228 # Ahem. The docs don't say anything about that -- this appears to
229 # be testing an implementation quirk. Starting in Python 2.5, it's
230 # not true for dicts: pprint always sorts dicts by key now; before,
231 # it sorted a dict display if and only if the display required
232 # multiple lines. For that reason, dicts with more than one element
233 # aren't tested here.
234 for simple in (0, 0, 0+0j, 0.0, "", b"", bytearray(),
235 (), tuple2(), tuple3(),
236 [], list2(), list3(),
237 set(), set2(), set3(),
238 frozenset(), frozenset2(), frozenset3(),
239 {}, dict2(), dict3(),
240 self.assertTrue, pprint,
241 -6, -6, -6-6j, -1.5, "x", b"x", bytearray(b"x"),
242 (3,), [3], {3: 6},
243 (1,2), [3,4], {5: 6},
244 tuple2((1,2)), tuple3((1,2)), tuple3(range(100)),
245 [3,4], list2([3,4]), list3([3,4]), list3(range(100)),
246 set({7}), set2({7}), set3({7}),
247 frozenset({8}), frozenset2({8}), frozenset3({8}),
248 dict2({5: 6}), dict3({5: 6}),
249 range(10, -11, -1),
250 True, False, None, ...,
251 ):
252 native = repr(simple)
253 self.assertEqual(pprint.pformat(simple), native)
254 self.assertEqual(pprint.pformat(simple, width=1, indent=0)
255 .replace('\n', ' '), native)
256 self.assertEqual(pprint.pformat(simple, underscore_numbers=True), native)
257 self.assertEqual(pprint.saferepr(simple), native)
258
259 def test_container_repr_override_called(self):
260 N = 1000

Callers

nothing calls this directly

Calls 15

tuple2Class · 0.85
tuple3Class · 0.85
list2Class · 0.85
list3Class · 0.85
setFunction · 0.85
set2Class · 0.85
set3Class · 0.85
frozenset2Class · 0.85
frozenset3Class · 0.85
dict2Class · 0.85
dict3Class · 0.85
reprFunction · 0.85

Tested by

no test coverage detected