[py-svn] py-trunk commit 0421cc33ce8f: better default for bogus terminal getdimensions() call, fixes issue63

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Tue Jan 19 10:35:04 CET 2010


# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview/
# User holger krekel <holger at merlinux.eu>
# Date 1263893681 -3600
# Node ID 0421cc33ce8f9ab4c0f3bd2796f4f6b707fb443d
# Parent dc19b0f7b95c13bac189fd8abf3fdd82262e1fd5
better default for bogus terminal getdimensions() call, fixes issue63

--- a/testing/io_/test_terminalwriter.py
+++ b/testing/io_/test_terminalwriter.py
@@ -8,14 +8,20 @@ def test_terminal_width_COLUMNS(monkeypa
     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)

--- 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()

--- 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



More information about the pytest-commit mailing list