better default for bogus terminal getdimensions() call, fixes issue63

--HG--
branch : trunk
This commit is contained in:
holger krekel 2010-01-19 10:34:41 +01:00
parent 53fc3204fb
commit f7c562e492
3 changed files with 19 additions and 6 deletions

View File

@ -1,4 +1,9 @@
Changes between 1.X and 1.1.1
Changes between 1.2.1 and 1.2.0
=====================================
- fix issue63: assume <40 columns to be a bogus terminal width, default to 80
Changes between 1.2 and 1.1.1
=====================================
- moved dist/looponfailing from py.test core into a new

View File

@ -74,9 +74,11 @@ def get_terminal_width():
raise
except:
# FALLBACK
width = int(os.environ.get('COLUMNS', 80))-1
# XXX the windows getdimensions may be bogus, let's sanify a bit
width = max(width, 40) # we alaways need 40 chars
width = int(os.environ.get('COLUMNS', 80))
else:
# XXX the windows getdimensions may be bogus, let's sanify a bit
if width < 40:
width = 80
return width
terminal_width = get_terminal_width()

View File

@ -8,14 +8,20 @@ def test_terminal_width_COLUMNS(monkeypatch):
fcntl = py.test.importorskip("fcntl")
monkeypatch.setattr(fcntl, 'ioctl', lambda *args: int('x'))
monkeypatch.setenv('COLUMNS', '42')
assert terminalwriter.get_terminal_width() == 41
assert terminalwriter.get_terminal_width() == 42
monkeypatch.delenv('COLUMNS', raising=False)
def test_terminalwriter_defaultwidth_80(monkeypatch):
monkeypatch.setattr(terminalwriter, '_getdimensions', lambda: 0/0)
monkeypatch.delenv('COLUMNS', raising=False)
tw = py.io.TerminalWriter()
assert tw.fullwidth == 80-1
assert tw.fullwidth == 80
def test_terminalwriter_getdimensions_bogus(monkeypatch):
monkeypatch.setattr(terminalwriter, '_getdimensions', lambda: (10,10))
monkeypatch.delenv('COLUMNS', raising=False)
tw = py.io.TerminalWriter()
assert tw.fullwidth == 80
def test_terminalwriter_computes_width(monkeypatch):
monkeypatch.setattr(terminalwriter, 'get_terminal_width', lambda: 42)