From ed8e24312c22e0716750698335544df4d0e0be12 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 26 Jul 2010 13:13:10 +0200 Subject: [PATCH] fix terminal dimension detection to work with stdout --HG-- branch : trunk --- CHANGELOG | 6 ++++++ py/__init__.py | 2 +- py/_io/terminalwriter.py | 2 +- setup.py | 2 +- testing/io_/test_terminalwriter.py | 12 ++++++++++++ 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 95023a6f6..10a553ac1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +Changes between 1.3.2 and 1.3.3a1 +================================================== + +- fix weirdness: make terminal width detection work on stdout instead of stdin + (thanks Armin Ronacher for reporting) + Changes between 1.3.1 and 1.3.2 ================================================== diff --git a/py/__init__.py b/py/__init__.py index c01552d95..3116b8660 100644 --- a/py/__init__.py +++ b/py/__init__.py @@ -8,7 +8,7 @@ dictionary or an import path. (c) Holger Krekel and others, 2004-2010 """ -__version__ = version = "1.3.2" +__version__ = version = "1.3.3a1" import py.apipkg diff --git a/py/_io/terminalwriter.py b/py/_io/terminalwriter.py index dc2ccf511..4feb3d66d 100644 --- a/py/_io/terminalwriter.py +++ b/py/_io/terminalwriter.py @@ -18,7 +18,7 @@ if sys.platform == "win32": def _getdimensions(): import termios,fcntl,struct - call = fcntl.ioctl(0,termios.TIOCGWINSZ,"\000"*8) + call = fcntl.ioctl(1,termios.TIOCGWINSZ,"\000"*8) height,width = struct.unpack( "hhhh", call ) [:2] return height, width diff --git a/setup.py b/setup.py index 1a96d822e..4564c8946 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ def main(): name='py', description='py.test and pylib: rapid testing and development utils.', long_description = long_description, - version= '1.3.2', + version= '1.3.3a1', url='http://pylib.org', license='MIT license', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], diff --git a/testing/io_/test_terminalwriter.py b/testing/io_/test_terminalwriter.py index b1c057da8..7273de2c7 100644 --- a/testing/io_/test_terminalwriter.py +++ b/testing/io_/test_terminalwriter.py @@ -6,6 +6,18 @@ def test_get_terminal_width(): x = py.io.get_terminal_width assert x == terminalwriter.get_terminal_width +def test_getdimensions(monkeypatch): + fcntl = py.test.importorskip("fcntl") + import struct + l = [] + monkeypatch.setattr(fcntl, 'ioctl', lambda *args: l.append(args)) + try: + terminalwriter._getdimensions() + except struct.error: + pass + assert len(l) == 1 + assert l[0][0] == 1 + def test_terminal_width_COLUMNS(monkeypatch): """ Dummy test for get_terminal_width """