Commit ac60d5dc by Gabriel Falcao

Merge branch 'master' of git://github.com/pshomov/lettuce into pshomov-master

Conflicts:
	lettuce/plugins/xunit_output.py

closes #305
parents afbcab57 79e52bf4
......@@ -15,10 +15,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from datetime import datetime, timedelta
from lettuce.terrain import after
from lettuce.terrain import before
from xml.dom import minidom
from lettuce.strings import utf8_bytestring
def wrt_output(filename, content):
......@@ -52,24 +53,26 @@ def enable(filename=None):
if step.scenario.outlines:
return
classname = "%s : %s" % (step.scenario.feature.name, step.scenario.name)
classname = utf8_bytestring(u"%s : %s" % (step.scenario.feature.name, step.scenario.name))
tc = doc.createElement("testcase")
tc.setAttribute("classname", classname)
tc.setAttribute("name", step.sentence)
if step.ran:
tc.setAttribute("name", step.sentence.encode('utf-8'))
try:
tc.setAttribute("time", str(total_seconds((datetime.now() - step.started))))
else:
tc.setAttribute("time", str(0))
skip=doc.createElement("skipped")
except AttributeError:
tc.setAttribute("time", str(total_seconds(timedelta(seconds=0))))
if not step.ran:
skip = doc.createElement("skipped")
skip.setAttribute("type", "UndefinedStep(%s)" % step.sentence)
tc.appendChild(skip)
if step.failed:
cdata = doc.createCDATASection(step.why.traceback)
cdata = doc.createCDATASection(step.why.traceback.encode('utf-8'))
failure = doc.createElement("failure")
if hasattr(step.why, 'cause'):
failure.setAttribute("message", step.why.cause)
failure.setAttribute("type", step.why.exception.__class__.__name__)
failure.setAttribute("message", step.why.cause.encode('utf-8'))
failure.setAttribute("type", step.why.exception.__class__.__name__.encode('utf-8'))
failure.appendChild(cdata)
tc.appendChild(failure)
......
......@@ -20,6 +20,14 @@ import time
import unicodedata
def utf8_bytestring(s):
if isinstance(s, str):
s = s.decode("utf-8")
elif isinstance(s, unicode):
s = s.encode("utf-8")
return s
def escape_if_necessary(what):
what = unicode(what)
if len(what) is 1:
......
Feature: Missing steps do not cause the xunit plugin to throw
Scenario: It should pass
Given my sdfsdf sdfsdf sdfs df sdfsdf
Feature: Unicode characters in the error traceback
Scenario: It should pass
Given my dæmi that passes
Scenario: It should raise an exception different of AssertionError
Given my "dæmi" that blows an exception
# -*- coding: utf-8 -*-
from lettuce import step
@step(u'my dæmi that passes')
def given_my_daemi_that_passes(step, d):
step.given(u'my "INNSKRÁ" that blows a exception')
@step('my "(.*)" that blows an exception')
def given_my_daemi_that_blows_a_exception(step, name):
assert False
......@@ -105,6 +105,35 @@ def test_xunit_output_with_different_filename():
assert_equals(1, len(called), "Function not called")
xunit_output.wrt_output = old
@with_setup(prepare_stdout, registry.clear)
def test_xunit_output_with_unicode_characters_in_error_messages():
called = []
def assert_correct_xml(filename, content):
called.append(True)
assert_xsd_valid(filename, content)
old = xunit_output.wrt_output
xunit_output.wrt_output = assert_correct_xml
runner = Runner(feature_name('unicode_traceback'), enable_xunit=True,
xunit_filename="custom_filename.xml")
runner.run()
assert_equals(1, len(called), "Function not called")
xunit_output.wrt_output = old
@with_setup(prepare_stdout, registry.clear)
def test_xunit_does_not_throw_exception_when_missing_step_definition():
def dummy_write(filename, content):
pass
old = xunit_output.wrt_output
xunit_output.wrt_output = dummy_write
runner = Runner(feature_name('missing_steps'), enable_xunit=True,
xunit_filename="mising_steps.xml")
runner.run()
xunit_output.wrt_output = old
@with_setup(prepare_stdout, registry.clear)
def test_xunit_output_with_no_steps():
......
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