[py-svn] py-trunk commit 0320df9af115: make terminal tests pass on win32/python2.4 and update tox.ini
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Jun 9 11:56:41 CEST 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 1276077673 -7200
# Node ID 0320df9af11576cd0eec9f871cda355563d558ee
# Parent 23b6bb2419bdb865d9534b8c069edb61a08e552c
make terminal tests pass on win32/python2.4 and update tox.ini
--- a/tox.ini
+++ b/tox.ini
@@ -1,6 +1,10 @@
[test]
changedir=testing
-command=py.test -n3 --basetemp=%(envtmpdir)s --confcutdir=.. --junitxml=junit-%(envname)s.xml
+cmdargs=py.test
+ -n3
+ --basetemp=%(envtmpdir)s
+ --confcutdir=..
+ --junitxml=junit-%(envname)s.xml
deps=pytest-xdist
[testenv:py24]
python=python2.4
@@ -8,8 +12,8 @@ python=python2.4
python=python2.5
[testenv:py26]
python=python2.6
-[testenv:jython]
-python=jython
-command=py.test-jython -n3 --basetemp=%(envtmpdir)s --confcutdir=.. --junitxml=junit-%(envname)s.xml
+#[testenv:jython]
+#python=jython
+#command=py.test-jython -n3 --basetemp=%(envtmpdir)s --confcutdir=.. --junitxml=junit-%(envname)s.xml
[testenv:py31]
python=python3.1
--- a/py/_io/terminalwriter.py
+++ b/py/_io/terminalwriter.py
@@ -8,64 +8,20 @@ Helper functions for writing to terminal
import sys, os
import py
+win32_and_ctypes = False
+if sys.platform == "win32":
+ try:
+ import ctypes
+ win32_and_ctypes = True
+ except ImportError:
+ pass
+
def _getdimensions():
import termios,fcntl,struct
call = fcntl.ioctl(0,termios.TIOCGWINSZ,"\000"*8)
height,width = struct.unpack( "hhhh", call ) [:2]
return height, width
-if sys.platform == 'win32':
- # ctypes access to the Windows console
-
- STD_OUTPUT_HANDLE = -11
- STD_ERROR_HANDLE = -12
- FOREGROUND_BLUE = 0x0001 # text color contains blue.
- FOREGROUND_GREEN = 0x0002 # text color contains green.
- FOREGROUND_RED = 0x0004 # text color contains red.
- FOREGROUND_WHITE = 0x0007
- FOREGROUND_INTENSITY = 0x0008 # text color is intensified.
- BACKGROUND_BLUE = 0x0010 # background color contains blue.
- BACKGROUND_GREEN = 0x0020 # background color contains green.
- BACKGROUND_RED = 0x0040 # background color contains red.
- BACKGROUND_WHITE = 0x0070
- BACKGROUND_INTENSITY = 0x0080 # background color is intensified.
-
- def GetStdHandle(kind):
- import ctypes
- return ctypes.windll.kernel32.GetStdHandle(kind)
-
- def SetConsoleTextAttribute(handle, attr):
- import ctypes
- ctypes.windll.kernel32.SetConsoleTextAttribute(
- handle, attr)
-
- def _getdimensions():
- import ctypes
- from ctypes import wintypes
-
- SHORT = ctypes.c_short
- class COORD(ctypes.Structure):
- _fields_ = [('X', SHORT),
- ('Y', SHORT)]
- class SMALL_RECT(ctypes.Structure):
- _fields_ = [('Left', SHORT),
- ('Top', SHORT),
- ('Right', SHORT),
- ('Bottom', SHORT)]
- class CONSOLE_SCREEN_BUFFER_INFO(ctypes.Structure):
- _fields_ = [('dwSize', COORD),
- ('dwCursorPosition', COORD),
- ('wAttributes', wintypes.WORD),
- ('srWindow', SMALL_RECT),
- ('dwMaximumWindowSize', COORD)]
- STD_OUTPUT_HANDLE = -11
- handle = GetStdHandle(STD_OUTPUT_HANDLE)
- info = CONSOLE_SCREEN_BUFFER_INFO()
- ctypes.windll.kernel32.GetConsoleScreenBufferInfo(
- handle, ctypes.byref(info))
- # Substract one from the width, otherwise the cursor wraps
- # and the ending \n causes an empty line to display.
- return info.dwSize.Y, info.dwSize.X - 1
def get_terminal_width():
try:
@@ -97,7 +53,7 @@ def ansi_print(text, esc, file=None, new
if newline:
text += '\n'
- if esc and sys.platform == "win32" and file.isatty():
+ if esc and win32_and_ctypes and file.isatty():
if 1 in esc:
bold = True
esc = tuple([x for x in esc if x != 1])
@@ -254,9 +210,6 @@ class Win32ConsoleWriter(TerminalWriter)
def line(self, s="", **kw):
self.write(s+"\n", **kw)
-if sys.platform == 'win32':
- TerminalWriter = Win32ConsoleWriter
-
class WriteFile(object):
def __init__(self, writemethod, encoding=None):
self.encoding = encoding
@@ -271,3 +224,57 @@ class WriteFile(object):
return
+if win32_and_ctypes:
+ TerminalWriter = Win32ConsoleWriter
+
+ # ctypes access to the Windows console
+ STD_OUTPUT_HANDLE = -11
+ STD_ERROR_HANDLE = -12
+ FOREGROUND_BLUE = 0x0001 # text color contains blue.
+ FOREGROUND_GREEN = 0x0002 # text color contains green.
+ FOREGROUND_RED = 0x0004 # text color contains red.
+ FOREGROUND_WHITE = 0x0007
+ FOREGROUND_INTENSITY = 0x0008 # text color is intensified.
+ BACKGROUND_BLUE = 0x0010 # background color contains blue.
+ BACKGROUND_GREEN = 0x0020 # background color contains green.
+ BACKGROUND_RED = 0x0040 # background color contains red.
+ BACKGROUND_WHITE = 0x0070
+ BACKGROUND_INTENSITY = 0x0080 # background color is intensified.
+
+ def GetStdHandle(kind):
+ import ctypes
+ return ctypes.windll.kernel32.GetStdHandle(kind)
+
+ def SetConsoleTextAttribute(handle, attr):
+ import ctypes
+ ctypes.windll.kernel32.SetConsoleTextAttribute(
+ handle, attr)
+
+ def _getdimensions():
+ import ctypes
+ from ctypes import wintypes
+
+ SHORT = ctypes.c_short
+ class COORD(ctypes.Structure):
+ _fields_ = [('X', SHORT),
+ ('Y', SHORT)]
+ class SMALL_RECT(ctypes.Structure):
+ _fields_ = [('Left', SHORT),
+ ('Top', SHORT),
+ ('Right', SHORT),
+ ('Bottom', SHORT)]
+ class CONSOLE_SCREEN_BUFFER_INFO(ctypes.Structure):
+ _fields_ = [('dwSize', COORD),
+ ('dwCursorPosition', COORD),
+ ('wAttributes', wintypes.WORD),
+ ('srWindow', SMALL_RECT),
+ ('dwMaximumWindowSize', COORD)]
+ STD_OUTPUT_HANDLE = -11
+ handle = GetStdHandle(STD_OUTPUT_HANDLE)
+ info = CONSOLE_SCREEN_BUFFER_INFO()
+ ctypes.windll.kernel32.GetConsoleScreenBufferInfo(
+ handle, ctypes.byref(info))
+ # Substract one from the width, otherwise the cursor wraps
+ # and the ending \n causes an empty line to display.
+ return info.dwSize.Y, info.dwSize.X - 1
+
More information about the pytest-commit
mailing list