From f7c562e49293b6b55643933357d52977cbbcfa51 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 19 Jan 2010 10:34:41 +0100 Subject: [PATCH] better default for bogus terminal getdimensions() call, fixes issue63 --HG-- branch : trunk --- CHANGELOG | 7 ++++++- py/_io/terminalwriter.py | 8 +++++--- testing/io_/test_terminalwriter.py | 10 ++++++++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 6633f05de..008f8cec2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 diff --git a/py/_io/terminalwriter.py b/py/_io/terminalwriter.py index af83e04ba..538975cd8 100644 --- a/py/_io/terminalwriter.py +++ b/py/_io/terminalwriter.py @@ -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() diff --git a/testing/io_/test_terminalwriter.py b/testing/io_/test_terminalwriter.py index f5d4b0a8d..7a5f6c4bb 100644 --- a/testing/io_/test_terminalwriter.py +++ b/testing/io_/test_terminalwriter.py @@ -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)