Permalink
Browse files

Merging fixes from @mike-grayhat closes #337

  • Loading branch information...
1 parent 1a6c70a commit b359418d89d4177fa0b51a41dc4cb662080f57c3 @gabrielfalcao committed Mar 27, 2013
@@ -31,6 +31,10 @@ def wrt_output(filename, content):
f.close()
+def write_xml_doc(filename, doc):
+ wrt_output(filename, doc.toxml())
+
+
def total_seconds(td):
return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 1e6) / 1e6
@@ -55,10 +59,10 @@ def create_test_case_step(step):
return
name = getattr(parent, 'name', 'Background') # Background sections are nameless
- classname = utf8_string(u"%s : %s" % (parent.feature.name, name))
+ classname = u"%s : %s" % (parent.feature.name, name)
tc = doc.createElement("testcase")
tc.setAttribute("classname", classname)
- tc.setAttribute("name", step.sentence.encode('utf-8'))
+ tc.setAttribute("name", step.sentence)
try:
tc.setAttribute("time", str(total_seconds((datetime.now() - step.started))))
except AttributeError:
@@ -70,11 +74,11 @@ def create_test_case_step(step):
tc.appendChild(skip)
if step.failed:
- cdata = doc.createCDATASection(step.why.traceback.encode('utf-8'))
+ cdata = doc.createCDATASection(step.why.traceback)
failure = doc.createElement("failure")
if hasattr(step.why, 'cause'):
- failure.setAttribute("message", step.why.cause.encode('utf-8'))
- failure.setAttribute("type", step.why.exception.__class__.__name__.encode('utf-8'))
+ failure.setAttribute("message", step.why.cause)
+ failure.setAttribute("type", step.why.exception.__class__.__name__)
failure.appendChild(cdata)
tc.appendChild(failure)
@@ -109,4 +113,4 @@ def output_xml(total):
root.setAttribute("errors", '0')
root.setAttribute("time", '0')
doc.appendChild(root)
- wrt_output(output_filename, doc.toxml())
+ write_xml_doc(output_filename, doc)
@@ -0,0 +1,9 @@
+Feature: Mixing of Unicode & bytestrings in xunit xml output
+ Scenario Outline: It should pass
+ Given non ascii characters "<value>" in outline
+ Examples:
+ | value |
+ | Значение |
+
+Scenario Outline: It should pass too
+ Given non ascii characters "Тест" in step
@@ -0,0 +1,11 @@
+# -*- coding: utf-8 -*-
+from lettuce import step
+
+@step(u'Non ascii characters "(.*)" in outline')
+def non_ascii_characters_in_outline(step, first):
+ assert True
+
+
+@step(u'Non ascii characters "(.*)" in step')
+def define_nonascii_chars(step, word):
+ assert True
@@ -22,6 +22,7 @@
from StringIO import StringIO
from nose.tools import assert_equals, assert_true, with_setup
+from sure import expect
from lettuce import registry
from lettuce import Runner
from lettuce import xunit_output
@@ -194,3 +195,22 @@ def just_pass(step, *args):
assert_equals(1, len(called), "Function not called")
xunit_output.wrt_output = old
+
+
+@with_setup(prepare_stdout, registry.clear)
+def test_xunit_xml_output_with_no_errors():
+ 'Test xunit doc xml output'
+
+ called = []
+
+ def assert_correct_xml_output(filename, doc):
+ called.append(True)
+ expect(doc.toxml).when.called.doesnt.throw(UnicodeDecodeError)
+
+ old = xunit_output.write_xml_doc
+ xunit_output.write_xml_doc = assert_correct_xml_output
+ runner = Runner(feature_name('xunit_unicode_and_bytestring_mixing'), enable_xunit=True)
+ try:
+ runner.run()
+ finally:
+ xunit_output.write_xml_doc = old

0 comments on commit b359418

Please sign in to comment.