MCPcopy Create free account
hub / github.com/microsoft/debugpy / ContainerBase

Class ContainerBase

src/debugpy/_vendored/pydevd/tests_python/test_safe_repr.py:217–315  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

215
216
217class ContainerBase(object):
218 CLASS = None
219 LEFT = None
220 RIGHT = None
221
222 @property
223 def info(self):
224 try:
225 return self._info
226 except AttributeError:
227 for info in SafeRepr.collection_types:
228 ctype, _, _, _ = info
229 if self.CLASS is ctype:
230 type(self)._info = info
231 return info
232 else:
233 raise TypeError("unsupported")
234
235 def _combine(self, items, prefix, suffix, large):
236 contents = ", ".join(str(item) for item in items)
237 if large:
238 contents += ", ..."
239 return prefix + contents + suffix
240
241 def combine(self, items, large=False):
242 if self.LEFT is None:
243 pytest.skip("unsupported")
244 return self._combine(items, self.LEFT, self.RIGHT, large=large)
245
246 def combine_nested(self, depth, items, large=False):
247 _, _prefix, _suffix, comma = self.info
248 prefix = _prefix * (depth + 1)
249 if comma:
250 suffix = _suffix + ("," + _suffix) * depth
251 else:
252 suffix = _suffix * (depth + 1)
253 # print("ctype = " + ctype.__name__ + ", maxcollection[" +
254 # str(i) + "] == " + str(SafeRepr.maxcollection[i]))
255 return self._combine(items, prefix, suffix, large=large)
256
257 def test_large_flat(self):
258 c1 = self.CLASS(range(SafeRepr.maxcollection[0] * 2))
259 items = range(SafeRepr.maxcollection[0] - 1)
260 c1_expect = self.combine(items, large=True)
261
262 self.assert_shortened(c1, c1_expect)
263
264 def test_large_nested(self):
265 c1 = self.CLASS(range(SafeRepr.maxcollection[0] * 2))
266 c1_items = range(SafeRepr.maxcollection[1] - 1)
267 c1_expect = self.combine(c1_items, large=True)
268
269 c2 = self.CLASS(c1 for _ in range(SafeRepr.maxcollection[0] * 2))
270 items = (c1_expect for _ in range(SafeRepr.maxcollection[0] - 1))
271 c2_expect = self.combine(items, large=True)
272
273 self.assert_shortened(c2, c2_expect)
274

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…