Skip to content

Commit b9da2ed

Browse files
Merge pull request #204 from asottile/at_least_one_sep
Have at least one separator in sep()
2 parents 0b562ce + a499409 commit b9da2ed

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

py/_io/terminalwriter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def sep(self, sepchar, title=None, fullwidth=None, **kw):
227227
# i.e. 2 + 2*len(sepchar)*N + len(title) <= fullwidth
228228
# 2*len(sepchar)*N <= fullwidth - len(title) - 2
229229
# N <= (fullwidth - len(title) - 2) // (2*len(sepchar))
230-
N = (fullwidth - len(title) - 2) // (2*len(sepchar))
230+
N = max((fullwidth - len(title) - 2) // (2*len(sepchar)), 1)
231231
fill = sepchar * N
232232
line = "%s %s %s" % (fill, title, fill)
233233
else:

testing/io_/test_terminalwriter.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ def test_sep_with_title(self, tw):
165165
assert len(l) == 1
166166
assert l[0] == "-" * 26 + " hello " + "-" * (27-win32) + "\n"
167167

168+
def test_sep_longer_than_width(self, tw):
169+
tw.sep('-', 'a' * 10, fullwidth=5)
170+
line, = tw.getlines()
171+
# even though the string is wider than the line, still have a separator
172+
assert line == '- aaaaaaaaaa -\n'
173+
168174
@py.test.mark.skipif("sys.platform == 'win32'")
169175
def test__escaped(self, tw):
170176
text2 = tw._escaped("hello", (31))

0 commit comments

Comments
 (0)