SHA256
1
0
forked from pool/python-py
python-py/separators.patch

52 lines
2.0 KiB
Diff

From a499409ee0f1234d45a80bf918cca18259fa9e1c Mon Sep 17 00:00:00 2001
From: Anthony Sottile <asottile@umich.edu>
Date: Thu, 22 Nov 2018 14:24:11 -0800
Subject: [PATCH] Have at least one separator in sep()
Before:
```
1 failed, 1 passed, 1 skipped, 1 deselected, 1 xfailed, 1 xpassed, 1 error in 0.04 seconds
```
After:
```
= 1 failed, 1 passed, 1 skipped, 1 deselected, 1 xfailed, 1 xpassed, 1 error in 0.04 seconds =
```
---
py/_io/terminalwriter.py | 2 +-
testing/io_/test_terminalwriter.py | 6 ++++++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/py/_io/terminalwriter.py b/py/_io/terminalwriter.py
index 817bf2d8..be559867 100644
--- a/py/_io/terminalwriter.py
+++ b/py/_io/terminalwriter.py
@@ -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:
diff --git a/testing/io_/test_terminalwriter.py b/testing/io_/test_terminalwriter.py
index 64b07568..1eef7f7d 100644
--- a/testing/io_/test_terminalwriter.py
+++ b/testing/io_/test_terminalwriter.py
@@ -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))