[py-svn] py-trunk commit f67a76b4d53c: make py.io.ansi_print and py.io.get_terminal_width() directly available.
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Thu Apr 29 10:55:02 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 1272530990 -7200
# Node ID f67a76b4d53c91ff8490ab3610f908c5f789e3ce
# Parent ab65e0695c3941c364d642b51ba59b247c8fa5c2
make py.io.ansi_print and py.io.get_terminal_width() directly available.
--- a/testing/io_/test_terminalwriter.py
+++ b/testing/io_/test_terminalwriter.py
@@ -2,6 +2,10 @@ import py
import os, sys
from py._io import terminalwriter
+def test_get_terminal_width():
+ x = py.io.get_terminal_width
+ assert x == terminalwriter.get_terminal_width
+
def test_terminal_width_COLUMNS(monkeypatch):
""" Dummy test for get_terminal_width
"""
@@ -147,3 +151,13 @@ def test_attr_hasmarkup():
tw.line("hello", bold=True)
s = tw.stringio.getvalue()
assert len(s) > len("hello")
+
+def test_ansi_print():
+ # we have no easy way to construct a file that
+ # represents a terminal
+ f = py.io.TextIO()
+ f.isatty = lambda: True
+ py.io.ansi_print("hello", 0x32, file=f)
+ text2 = f.getvalue()
+ assert text2.find("hello") != -1
+ assert len(text2) >= len("hello")
--- a/py/_cmdline/pylookup.py
+++ b/py/_cmdline/pylookup.py
@@ -9,7 +9,7 @@ prepended."""
import sys, os
import py
-from py._io.terminalwriter import ansi_print, terminal_width
+from py.io import ansi_print, get_terminal_width
import re
def rec(p):
@@ -21,6 +21,8 @@ parser.add_option("-i", "--ignore-case",
parser.add_option("-C", "--context", action="store", type="int", dest="context",
default=0, help="How many lines of output to show")
+terminal_width = get_terminal_width()
+
def find_indexes(search_line, string):
indexes = []
before = 0
--- a/py/__init__.py
+++ b/py/__init__.py
@@ -138,6 +138,8 @@ py.apipkg.initpkg(__name__, dict(
'StdCapture' : '._io.capture:StdCapture',
'StdCaptureFD' : '._io.capture:StdCaptureFD',
'TerminalWriter' : '._io.terminalwriter:TerminalWriter',
+ 'ansi_print' : '._io.terminalwriter:ansi_print',
+ 'get_terminal_width' : '._io.terminalwriter:get_terminal_width',
},
# small and mean xml/html generation
More information about the pytest-commit
mailing list