MCPcopy
hub / github.com/pytest-dev/pytest / sep

Method sep

src/_pytest/_io/terminalwriter.py:117–152  ·  view source on GitHub ↗
(
        self,
        sepchar: str,
        title: str | None = None,
        fullwidth: int | None = None,
        **markup: bool,
    )

Source from the content-addressed store, hash-verified

115 return text
116
117 def sep(
118 self,
119 sepchar: str,
120 title: str | None = None,
121 fullwidth: int | None = None,
122 **markup: bool,
123 ) -> None:
124 if fullwidth is None:
125 fullwidth = self.fullwidth
126 # The goal is to have the line be as long as possible
127 # under the condition that len(line) <= fullwidth.
128 if sys.platform == "win32":
129 # If we print in the last column on windows we are on a
130 # new line but there is no way to verify/neutralize this
131 # (we may not know the exact line width).
132 # So let's be defensive to avoid empty lines in the output.
133 fullwidth -= 1
134 if title is not None:
135 # we want 2 + 2*len(fill) + len(title) <= fullwidth
136 # i.e. 2 + 2*len(sepchar)*N + len(title) <= fullwidth
137 # 2*len(sepchar)*N <= fullwidth - len(title) - 2
138 # N <= (fullwidth - len(title) - 2) // (2*len(sepchar))
139 N = max((fullwidth - len(title) - 2) // (2 * len(sepchar)), 1)
140 fill = sepchar * N
141 line = f"{fill} {title} {fill}"
142 else:
143 # we want len(sepchar)*N <= fullwidth
144 # i.e. N <= fullwidth // len(sepchar)
145 line = sepchar * (fullwidth // len(sepchar))
146 # In some situations there is room for an extra sepchar at the right,
147 # in particular if we consider that with a sepchar like "_ " the
148 # trailing space is not important at the end of the line.
149 if len(line) + len(sepchar.rstrip()) <= fullwidth:
150 line += sepchar.rstrip()
151
152 self.line(line, **markup)
153
154 def write(self, msg: str, *, flush: bool = False, **markup: bool) -> None:
155 if msg:

Callers 13

cacheshowFunction · 0.95
write_sepMethod · 0.45
sectionMethod · 0.45
_outrep_summaryMethod · 0.45
write_itemFunction · 0.45
_showfixtures_mainFunction · 0.45
do_continueMethod · 0.45
_init_pdbMethod · 0.45
_enter_pdbFunction · 0.45
toterminalMethod · 0.45

Calls 1

lineMethod · 0.95

Tested by

no test coverage detected