Skip to content

Commit

Permalink
Merge pull request #204 from asottile/at_least_one_sep
Browse files Browse the repository at this point in the history
Have at least one separator in sep()
  • Loading branch information
RonnyPfannschmidt committed Nov 23, 2018
2 parents 0b562ce + a499409 commit b9da2ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion py/_io/terminalwriter.py
Expand Up @@ -227,7 +227,7 @@ def sep(self, sepchar, title=None, fullwidth=None, **kw):
# i.e. 2 + 2*len(sepchar)*N + len(title) <= fullwidth
# 2*len(sepchar)*N <= fullwidth - len(title) - 2
# N <= (fullwidth - len(title) - 2) // (2*len(sepchar))
N = (fullwidth - len(title) - 2) // (2*len(sepchar))
N = max((fullwidth - len(title) - 2) // (2*len(sepchar)), 1)
fill = sepchar * N
line = "%s %s %s" % (fill, title, fill)
else:
Expand Down
6 changes: 6 additions & 0 deletions testing/io_/test_terminalwriter.py
Expand Up @@ -165,6 +165,12 @@ def test_sep_with_title(self, tw):
assert len(l) == 1
assert l[0] == "-" * 26 + " hello " + "-" * (27-win32) + "\n"

def test_sep_longer_than_width(self, tw):
tw.sep('-', 'a' * 10, fullwidth=5)
line, = tw.getlines()
# even though the string is wider than the line, still have a separator
assert line == '- aaaaaaaaaa -\n'

@py.test.mark.skipif("sys.platform == 'win32'")
def test__escaped(self, tw):
text2 = tw._escaped("hello", (31))
Expand Down

0 comments on commit b9da2ed

Please sign in to comment.