Commit 04d5e5d9 by Gabriel Falcao

fixing a lot of unicode issues

parent ffb42dfc
......@@ -37,7 +37,6 @@ class ReasonToFail(object):
"""
def __init__(self, exc):
self.exception = exc
#self.cause = unicode(exc)
if isinstance(exc.message, unicode):
self.cause = unicode(exc)
elif isinstance(exc.message, str):
......
......@@ -27,7 +27,6 @@ from lettuce.terrain import before
def wrt(what):
#sys.stdout.write(what.encode('utf-8'))
if isinstance(what, unicode):
what = what.encode('utf-8')
sys.stdout.write(what)
......
......@@ -24,8 +24,10 @@ failed_scenarios = []
scenarios_and_its_fails = {}
def wrt(string):
sys.stdout.write(string)
def wrt(what):
if isinstance(what, unicode):
what = what.encode('utf-8')
sys.stdout.write(what)
@after.each_step
......
......@@ -25,8 +25,10 @@ failed_scenarios = []
scenarios_and_its_fails = {}
def wrt(string):
sys.stdout.write(string.encode('utf-8'))
def wrt(what):
if isinstance(what, unicode):
what = what.encode('utf-8')
sys.stdout.write(what)
@before.each_scenario
......
......@@ -24,7 +24,9 @@ from lettuce.terrain import before
def wrt(what):
sys.stdout.write(what.encode('utf-8'))
if isinstance(what, unicode):
what = what.encode('utf-8')
sys.stdout.write(what)
@after.each_step
......
......@@ -23,7 +23,10 @@ from xml.dom import minidom
def wrt_output(filename, content):
f = open(filename, "w")
f.write(content.encode('utf-8'))
if isinstance(content, unicode):
content = content.encode('utf-8')
f.write(content)
f.close()
......@@ -48,13 +51,13 @@ def enable(filename=None):
def create_test_case_step(step):
if step.scenario.outlines:
return
classname = "%s : %s" % (step.scenario.feature.name, step.scenario.name)
tc = doc.createElement("testcase")
tc.setAttribute("classname", classname)
tc.setAttribute("name", step.sentence)
tc.setAttribute("time", str(total_seconds((datetime.now() - step.started))))
if not step.ran:
skip=doc.createElement("skipped")
tc.appendChild(skip)
......@@ -68,12 +71,12 @@ def enable(filename=None):
tc.appendChild(failure)
root.appendChild(tc)
@before.outline
def time_outline(scenario, order, outline, reasons_to_fail):
scenario.outline_started = datetime.now()
pass
@after.outline
def create_test_case_outline(scenario, order, outline, reasons_to_fail):
classname = "%s : %s" % (scenario.feature.name, scenario.name)
......
......@@ -14,7 +14,6 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import os
import threading
import traceback
......@@ -84,6 +83,7 @@ def call_hook(situation, kind, *args, **kw):
try:
callback(*args, **kw)
except Exception, e:
print "=" * 1000
traceback.print_exc(e)
print
raise SystemExit(2)
......
......@@ -35,15 +35,37 @@ def prepare_stderr():
std = StringIO()
sys.stderr = std
def assert_lines(original, expected):
original = original.decode('utf-8') if isinstance(original, basestring) else original
assert_lines_unicode(original, expected)
def assert_lines_unicode(original, expected):
if isinstance(expected, unicode):
expected = expected.encode('utf-8')
if isinstance(original, unicode):
original = original.encode('utf-8')
expected_lines = expected.splitlines(1)
original_lines = original.splitlines(1)
if original != expected:
diff = ''.join(list(Differ().compare(expected.splitlines(1), original.splitlines(1))))
raise AssertionError, 'Output differed as follows:\n' + diff + "\nOutput was:\n" + original +"\nExpected was:\n"+expected
assert_equals(len(expected), len(original), 'Output appears equal, but of different lengths.')
comparison = Differ().compare(expected_lines, original_lines)
if isinstance(comparison, unicode):
expected = expected.encode('utf-8')
diff = u''.encode('utf-8').join(comparison)
msg = (u'Output differed as follows:\n{0}\n'
'Output was:\n{1}\nExpected was:\n{2}'.encode('utf-8'))
raise AssertionError(msg.format(diff, original, expected))
assert_equals(
len(expected), len(original),
u'Output appears equal, but of different lengths.')
def assert_lines_with_traceback(one, other):
lines_one = one.splitlines()
......@@ -64,6 +86,7 @@ def assert_lines_with_traceback(one, other):
assert_unicode_equals(len(lines_one), len(lines_other))
def assert_unicode_equals(original, expected):
if isinstance(original, basestring):
original = original.decode('utf-8')
......@@ -89,4 +112,3 @@ def assert_stdout_lines_with_traceback(other):
def assert_stderr_lines_with_traceback(other):
assert_lines_with_traceback(sys.stderr.getvalue(), other)
Feature: Failful Scenario Outline
As lettuce author
In order to finish the first release
I want to make scenario outlines work :)
I want to make scenario outlines work
Scenario Outline: fill a web form
Given I open browser at "http://www.my-website.com/"
......
Feature: Table Fail
Scenario: See it fail
Given I have a dumb step that passes
Given I have a dumb step that passes
And this one fails
......
Feature: Successful Scenario Outline
As lettuce author
In order to finish the first release
I want to make scenario outlines work :)
I want to make scenario outlines work
Scenario Outline: fill a web form
Given I open browser at "http://www.my-website.com/"
......
Feature: Table Success
Scenario: Add two numbers
Scenario: Add two numbers
Given I have 0 bucks
And that I have these items:
......
......@@ -366,7 +366,7 @@ def test_output_with_success_colorless_with_table():
'\n'
'Feature: Table Success # tests/functional/output_features/success_table/success_table.feature:1\n'
'\n'
' Scenario: Add two numbers # tests/functional/output_features/success_table/success_table.feature:2\n'
' Scenario: Add two numbers # tests/functional/output_features/success_table/success_table.feature:2\n'
' Given I have 0 bucks # tests/functional/output_features/success_table/success_table_steps.py:28\n'
' And that I have these items: # tests/functional/output_features/success_table/success_table_steps.py:32\n'
' | name | price |\n'
......@@ -394,7 +394,7 @@ def test_output_with_success_colorful_with_table():
'\n'
'\033[1;37mFeature: Table Success \033[1;30m# tests/functional/output_features/success_table/success_table.feature:1\033[0m\n'
'\n'
'\033[1;37m Scenario: Add two numbers \033[1;30m# tests/functional/output_features/success_table/success_table.feature:2\033[0m\n'
'\033[1;37m Scenario: Add two numbers \033[1;30m# tests/functional/output_features/success_table/success_table.feature:2\033[0m\n'
'\033[1;30m Given I have 0 bucks \033[1;30m# tests/functional/output_features/success_table/success_table_steps.py:28\033[0m\n'
'\033[A\033[1;32m Given I have 0 bucks \033[1;30m# tests/functional/output_features/success_table/success_table_steps.py:28\033[0m\n'
'\033[1;30m And that I have these items: \033[1;30m# tests/functional/output_features/success_table/success_table_steps.py:32\033[0m\n'
......@@ -429,11 +429,11 @@ def test_output_with_failed_colorless_with_table():
runner.run()
assert_stdout_lines_with_traceback(
"\n"
("\n"
"Feature: Table Fail # tests/functional/output_features/failed_table/failed_table.feature:1\n"
"\n"
" Scenario: See it fail # tests/functional/output_features/failed_table/failed_table.feature:2\n"
" Given I have a dumb step that passes # tests/functional/output_features/failed_table/failed_table_steps.py:20\n"
u" Given I have a dumb step that passes ♥ # tests/functional/output_features/failed_table/failed_table_steps.py:20\n"
" And this one fails # tests/functional/output_features/failed_table/failed_table_steps.py:24\n"
" Traceback (most recent call last):\n"
' File "%(lettuce_core_file)s", line %(call_line)d, in __call__\n'
......@@ -456,7 +456,7 @@ def test_output_with_failed_colorless_with_table():
"\n"
"@step(u'And this one does not even has definition')\n"
"def and_this_one_does_not_even_has_definition(step):\n"
" assert False, 'This step must be implemented'\n" % {
" assert False, 'This step must be implemented'\n") % {
'lettuce_core_file': lettuce_path('core.py'),
'step_file': abspath(lettuce_path('..', 'tests', 'functional', 'output_features', 'failed_table', 'failed_table_steps.py')),
'call_line':call_line,
......@@ -475,8 +475,8 @@ def test_output_with_failed_colorful_with_table():
"\033[1;37mFeature: Table Fail \033[1;30m# tests/functional/output_features/failed_table/failed_table.feature:1\033[0m\n"
"\n"
"\033[1;37m Scenario: See it fail \033[1;30m# tests/functional/output_features/failed_table/failed_table.feature:2\033[0m\n"
"\033[1;30m Given I have a dumb step that passes \033[1;30m# tests/functional/output_features/failed_table/failed_table_steps.py:20\033[0m\n"
"\033[A\033[1;32m Given I have a dumb step that passes \033[1;30m# tests/functional/output_features/failed_table/failed_table_steps.py:20\033[0m\n"
u"\033[1;30m Given I have a dumb step that passes ♥ \033[1;30m# tests/functional/output_features/failed_table/failed_table_steps.py:20\033[0m\n"
u"\033[A\033[1;32m Given I have a dumb step that passes ♥ \033[1;30m# tests/functional/output_features/failed_table/failed_table_steps.py:20\033[0m\n"
"\033[1;30m And this one fails \033[1;30m# tests/functional/output_features/failed_table/failed_table_steps.py:24\033[0m\n"
"\033[A\033[0;31m And this one fails \033[1;41;33m# tests/functional/output_features/failed_table/failed_table_steps.py:24\033[0m\n"
"\033[1;31m Traceback (most recent call last):\n"
......@@ -522,7 +522,7 @@ def test_output_with_successful_outline_colorless():
'Feature: Successful Scenario Outline # tests/functional/output_features/success_outline/success_outline.feature:1\n'
' As lettuce author # tests/functional/output_features/success_outline/success_outline.feature:2\n'
' In order to finish the first release # tests/functional/output_features/success_outline/success_outline.feature:3\n'
' I want to make scenario outlines work :) # tests/functional/output_features/success_outline/success_outline.feature:4\n'
u' I want to make scenario outlines work ♥ # tests/functional/output_features/success_outline/success_outline.feature:4\n'
'\n'
' Scenario Outline: fill a web form # tests/functional/output_features/success_outline/success_outline.feature:6\n'
' Given I open browser at "http://www.my-website.com/" # tests/functional/output_features/success_outline/success_outline_steps.py:21\n'
......@@ -557,7 +557,7 @@ def test_output_with_successful_outline_colorful():
'\033[1;37mFeature: Successful Scenario Outline \033[1;30m# tests/functional/output_features/success_outline/success_outline.feature:1\033[0m\n'
'\033[1;37m As lettuce author \033[1;30m# tests/functional/output_features/success_outline/success_outline.feature:2\033[0m\n'
'\033[1;37m In order to finish the first release \033[1;30m# tests/functional/output_features/success_outline/success_outline.feature:3\033[0m\n'
'\033[1;37m I want to make scenario outlines work :) \033[1;30m# tests/functional/output_features/success_outline/success_outline.feature:4\033[0m\n'
u'\033[1;37m I want to make scenario outlines work ♥ \033[1;30m# tests/functional/output_features/success_outline/success_outline.feature:4\033[0m\n'
'\n'
'\033[1;37m Scenario Outline: fill a web form \033[1;30m# tests/functional/output_features/success_outline/success_outline.feature:6\033[0m\n'
'\033[0;36m Given I open browser at "http://www.my-website.com/" \033[1;30m# tests/functional/output_features/success_outline/success_outline_steps.py:21\033[0m\n'
......@@ -592,7 +592,7 @@ def test_output_with_failful_outline_colorless():
'Feature: Failful Scenario Outline # tests/functional/output_features/fail_outline/fail_outline.feature:1\n'
' As lettuce author # tests/functional/output_features/fail_outline/fail_outline.feature:2\n'
' In order to finish the first release # tests/functional/output_features/fail_outline/fail_outline.feature:3\n'
' I want to make scenario outlines work :) # tests/functional/output_features/fail_outline/fail_outline.feature:4\n'
u' I want to make scenario outlines work ♥ # tests/functional/output_features/fail_outline/fail_outline.feature:4\n'
'\n'
' Scenario Outline: fill a web form # tests/functional/output_features/fail_outline/fail_outline.feature:6\n'
' Given I open browser at "http://www.my-website.com/" # tests/functional/output_features/fail_outline/fail_outline_steps.py:21\n'
......@@ -637,7 +637,7 @@ def test_output_with_failful_outline_colorful():
'\033[1;37mFeature: Failful Scenario Outline \033[1;30m# tests/functional/output_features/fail_outline/fail_outline.feature:1\033[0m\n'
'\033[1;37m As lettuce author \033[1;30m# tests/functional/output_features/fail_outline/fail_outline.feature:2\033[0m\n'
'\033[1;37m In order to finish the first release \033[1;30m# tests/functional/output_features/fail_outline/fail_outline.feature:3\033[0m\n'
'\033[1;37m I want to make scenario outlines work :) \033[1;30m# tests/functional/output_features/fail_outline/fail_outline.feature:4\033[0m\n'
u'\033[1;37m I want to make scenario outlines work ♥ \033[1;30m# tests/functional/output_features/fail_outline/fail_outline.feature:4\033[0m\n'
'\n'
'\033[1;37m Scenario Outline: fill a web form \033[1;30m# tests/functional/output_features/fail_outline/fail_outline.feature:6\033[0m\n'
'\033[0;36m Given I open browser at "http://www.my-website.com/" \033[1;30m# tests/functional/output_features/fail_outline/fail_outline_steps.py:21\033[0m\n'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment