MCPcopy Create free account
hub / github.com/pytest-dev/pytest / _format_lines

Function _format_lines

src/_pytest/assertion/util.py:67–99  ·  view source on GitHub ↗

Format the individual lines. This will replace the '{', '}' and '~' characters of our mini formatting language with the proper 'where ...', 'and ...' and ' + ...' text, taking care of indentation along the way. Return a list of formatted lines.

(lines: Sequence[str])

Source from the content-addressed store, hash-verified

65
66
67def _format_lines(lines: Sequence[str]) -> List[str]:
68 """Format the individual lines.
69
70 This will replace the '{', '}' and '~' characters of our mini formatting
71 language with the proper 'where ...', 'and ...' and ' + ...' text, taking
72 care of indentation along the way.
73
74 Return a list of formatted lines.
75 """
76 result = list(lines[:1])
77 stack = [0]
78 stackcnt = [0]
79 for line in lines[1:]:
80 if line.startswith("{"):
81 if stackcnt[-1]:
82 s = "and "
83 else:
84 s = "where "
85 stack.append(len(result))
86 stackcnt[-1] += 1
87 stackcnt.append(0)
88 result.append(" +" + " " * (len(stack) - 1) + s + line[1:])
89 elif line.startswith("}"):
90 stack.pop()
91 stackcnt.pop()
92 result[stack[-1]] += line[1:]
93 else:
94 assert line[0] in ["~", ">"]
95 stack[-1] += 1
96 indent = len(stack) if line.startswith("~") else len(stack) - 1
97 result.append(" " * indent + line[1:])
98 assert len(stack) == 1
99 return result
100
101
102def issequence(x: Any) -> bool:

Callers 1

format_explanationFunction · 0.85

Calls 2

appendMethod · 0.80
popMethod · 0.80

Tested by

no test coverage detected