MCPcopy Create free account
hub / github.com/comaps/comaps / formatted_string

Method formatted_string

tools/python/maps_generator/checks/check.py:225–264  ·  view source on GitHub ↗
(self, silent_if_no_results=False, filt=None, _offset=0)

Source from the content-addressed store, hash-verified

223 return [c.get_result() for c in self._with_result()]
224
225 def formatted_string(self, silent_if_no_results=False, filt=None, _offset=0) -> str:
226 sets = filter(lambda c: isinstance(c, CompareCheckSet), self._with_result())
227 checks = filter(lambda c: isinstance(c, CompareCheck), self._with_result())
228 checks = sorted(checks, key=lambda c: norm(c.get_result().diff), reverse=True)
229
230 if filt is None:
231 filt = self.filt
232
233 checks = filter(lambda c: filt(c.get_result()), checks)
234
235 sets = list(sets)
236 checks = list(checks)
237
238 no_results = not checks and not sets
239 if silent_if_no_results and no_results:
240 return ""
241
242 head = [
243 f"{' ' * _offset}Check set[{self.name}]:",
244 ]
245
246 lines = []
247 if no_results:
248 lines.append(f"{' ' * (_offset + 2)}No results.")
249
250 for c in checks:
251 s = c.formatted_string(silent_if_no_results, filt, _offset + 2)
252 if s:
253 lines.append(f"{' ' * (_offset + 2)}{s}")
254
255 for s in sets:
256 s = s.formatted_string(silent_if_no_results, filt, _offset + 2)
257 if s:
258 lines.append(s)
259
260 if not lines:
261 return ""
262
263 head += lines
264 return "\n".join(head) + "\n"
265
266 def _with_result(self):
267 return (c for c in self.checks if c.get_result() is not None)

Callers

nothing calls this directly

Calls 6

_with_resultMethod · 0.95
normFunction · 0.85
get_resultMethod · 0.45
appendMethod · 0.45
formatted_stringMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected