first tests

This commit is contained in:
Gabriel Falcão 2010-08-04 03:32:52 -03:00
parent d2c0a7c8cb
commit 218fed53ab
4 changed files with 35 additions and 18 deletions

View File

@ -20,6 +20,20 @@ import uuid
__version__ = '0.2'
from StringIO import StringIO
def minify(string):
regex = re.compile('(\\b\033\[(\d+)m\\b)')
found = ";".join(x[1] for x in regex.findall(string))
existent = "".join([x[0] for x in regex.findall(string)])
replaced = string
if found and existent:
replaced = string.replace(existent, '\033[%sm' % found)
if string == '\033[1m\033[32m\033[47mHello\033[0m\n':
import sys
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
import ipdb; ipdb.set_trace()
return replaced
def translate_colors(string):
for attr in re.findall("[#][{]on[:](\w+)[}]", string):
string = string.replace(
@ -37,7 +51,7 @@ def translate_colors(string):
)
string = string.replace("\n", "%s\n" % modifiers.reset)
return string
return minify(string)
class StdOutMocker(StringIO):
original = sys.__stdout__

View File

@ -20,7 +20,7 @@ from nose.tools import assert_equals
import couleur
def test_output_black_foreground():
"Test stderr filter output: black foreground"
"file-like filter output: black foreground"
io = StringIO()
couleur.proxy(io).enable()
@ -33,7 +33,7 @@ def test_output_black_foreground():
assert_equals('#{black}should not be translated\n', io.getvalue())
def test_output_black_on_white_foreground():
"Test stderr filter output: black foreground on white background"
"file-like filter output: black foreground on white background"
io = StringIO()
couleur.proxy(io).enable()
@ -46,7 +46,7 @@ def test_output_black_on_white_foreground():
assert_equals('#{black}should not be translated\n', io.getvalue())
def test_output_green_foreground():
"Test stderr filter output: green foreground"
"file-like filter output: green foreground"
io = StringIO()
couleur.proxy(io).enable()
@ -59,7 +59,7 @@ def test_output_green_foreground():
assert_equals('#{black}should not be translated\n', io.getvalue())
def test_output_green_and_red_on_white_foreground():
"Test stderr filter output: green foreground and white on red background"
"file-like filter output: green foreground and white on red background"
io = StringIO()
couleur.proxy(io).enable()
@ -72,15 +72,18 @@ def test_output_green_and_red_on_white_foreground():
assert_equals('#{black}should not be translated\n', io.getvalue())
def test_output_bold_green_on_bold_white():
"Test stderr filter output: bold green on white"
"file-like filter output: bold green on white"
io = StringIO()
couleur.proxy(io).enable()
io.write("#{bold}#{green}#{on:white}Hello\n")
assert_equals('\033[1m\033[32m\033[47mHello\033[0m\n', io.getvalue())
assert_equals('\033[1;32;47mHello\033[0m\n', io.getvalue())
couleur.proxy(io).disable()
io.seek(0)
io.truncate()
io.write("#{black}should not be translated\n")
assert_equals('#{black}should not be translated\n', io.getvalue())
def test_minify():
assert_equals("\033[1;32;41mHello\n", couleur.minify("\033[1m\033[32m\033[41mHello\n"))
assert_equals("\033[1;32;41mHello\n", couleur.minify("\033[1;32;41mHello\n"))

View File

@ -35,7 +35,7 @@ def assert_stderr(expected):
@with_setup(prepare_stderr)
def test_output_black_foreground():
"Test stderr filter output: black foreground"
"STDERR filter output: black foreground"
couleur.proxy(sys.stderr).enable()
sys.stderr.write("#{black}Hello Black!\n")
@ -46,7 +46,7 @@ def test_output_black_foreground():
@with_setup(prepare_stderr)
def test_output_black_on_white_foreground():
"Test stderr filter output: black foreground on white background"
"STDERR filter output: black foreground on white background"
couleur.proxy(sys.stderr).enable()
sys.stderr.write("#{black}#{on:white}Hello Black!\n")
@ -57,7 +57,7 @@ def test_output_black_on_white_foreground():
@with_setup(prepare_stderr)
def test_output_green_foreground():
"Test stderr filter output: green foreground"
"STDERR filter output: green foreground"
couleur.proxy(sys.stderr).enable()
sys.stderr.write("#{green}Hello Green!\n")
@ -68,7 +68,7 @@ def test_output_green_foreground():
@with_setup(prepare_stderr)
def test_output_green_and_red_on_white_foreground():
"Test stderr filter output: green foreground and white on red background"
"STDERR filter output: green foreground and white on red background"
couleur.proxy(sys.stderr).enable()
sys.stderr.write("#{green}Hello #{white}#{on:red}Italy!\n")
@ -78,7 +78,7 @@ def test_output_green_and_red_on_white_foreground():
assert_stderr('#{black}should not be translated\n')
def test_integration_with_stderr():
"Test stderr filter integration"
"STDERR filter integration"
sys.stderr = sys.__stderr__
couleur.proxy(sys.stderr).enable()

View File

@ -35,7 +35,7 @@ def assert_stdout(expected):
@with_setup(prepare_stdout)
def test_output_black_foreground():
"Test stdout filter output: black foreground"
"STDOUT filter output: black foreground"
couleur.proxy(sys.stdout).enable()
print "#{black}Hello Black!"
@ -46,18 +46,18 @@ def test_output_black_foreground():
@with_setup(prepare_stdout)
def test_output_black_on_white_foreground():
"Test stdout filter output: black foreground on white background"
"STDOUT filter output: black foreground on white background"
couleur.proxy(sys.stdout).enable()
print "#{black}#{on:white}Hello Black!"
assert_stdout('\033[30m\033[47mHello Black!\033[0m\n')
assert_stdout('\033[30;47mHello Black!\033[0m\n')
couleur.proxy(sys.stdout).disable()
print "#{black}should not be translated"
assert_stdout('#{black}should not be translated\n')
@with_setup(prepare_stdout)
def test_output_green_foreground():
"Test stdout filter output: green foreground"
"STDOUT filter output: green foreground"
couleur.proxy(sys.stdout).enable()
print "#{green}Hello Green!"
@ -68,7 +68,7 @@ def test_output_green_foreground():
@with_setup(prepare_stdout)
def test_output_green_and_red_on_white_foreground():
"Test stdout filter output: green foreground and white on red background"
"STDOUT filter output: green foreground and white on red background"
couleur.proxy(sys.stdout).enable()
print "#{green}Hello #{white}#{on:red}Italy!"
@ -78,7 +78,7 @@ def test_output_green_and_red_on_white_foreground():
assert_stdout('#{black}should not be translated\n')
def test_integration_with_stdout():
"Test stdout filter integration"
"STDOUT filter integration"
sys.stdout = sys.__stdout__
couleur.proxy(sys.stdout).enable()