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

Method test_knotted

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

Source from the content-addressed store, hash-verified

191 pprint.PrettyPrinter().pprint(value)
192
193 def test_knotted(self):
194 # Verify .isrecursive() and .isreadable() w/ recursion
195 # Tie a knot.
196 self.b[67] = self.a
197 # Messy dict.
198 self.d = {}
199 self.d[0] = self.d[1] = self.d[2] = self.d
200 self.e = {}
201 self.v = ValuesView(self.e)
202 self.m = MappingView(self.e)
203 self.dv = self.e.values()
204 self.e["v"] = self.v
205 self.e["m"] = self.m
206 self.e["dv"] = self.dv
207
208 pp = pprint.PrettyPrinter()
209
210 for icky in self.a, self.b, self.d, (self.d, self.d), self.e, self.v, self.m, self.dv:
211 self.assertTrue(pprint.isrecursive(icky), "expected isrecursive")
212 self.assertFalse(pprint.isreadable(icky), "expected not isreadable")
213 self.assertTrue(pp.isrecursive(icky), "expected isrecursive")
214 self.assertFalse(pp.isreadable(icky), "expected not isreadable")
215
216 # Break the cycles.
217 self.d.clear()
218 self.e.clear()
219 del self.a[:]
220 del self.b[:]
221
222 for safe in self.a, self.b, self.d, (self.d, self.d), self.e, self.v, self.m, self.dv:
223 # module-level convenience functions
224 self.assertFalse(pprint.isrecursive(safe),
225 "expected not isrecursive for %r" % (safe,))
226 self.assertTrue(pprint.isreadable(safe),
227 "expected isreadable for %r" % (safe,))
228 # PrettyPrinter methods
229 self.assertFalse(pp.isrecursive(safe),
230 "expected not isrecursive for %r" % (safe,))
231 self.assertTrue(pp.isreadable(safe),
232 "expected isreadable for %r" % (safe,))
233
234 def test_unreadable(self):
235 # Not recursive but not readable anyway

Callers

nothing calls this directly

Calls 8

isrecursiveMethod · 0.95
isreadableMethod · 0.95
ValuesViewClass · 0.90
MappingViewClass · 0.90
assertTrueMethod · 0.80
assertFalseMethod · 0.80
valuesMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected