commit 2cb052d072d9a14d82ac6a8806213fcb69e06c61
Author: Vitezslav Humpa <vhumpa@redhat.com>
Date: Tue Sep 20 17:18:09 2016 +0200
Fix several python2 unicode issues + python3 unicode() function compat
diff --git a/behave/formatter/html.py b/behave/formatter/html.py
index 437ef98..75cf881 100644
--- a/behave/formatter/html.py
+++ b/behave/formatter/html.py
@@ -334,7 +334,9 @@ class HTMLFormatter(Formatter):
for argument in self.arguments:
step_part = ET.SubElement(step_text, 'span')
step_part.text = result.name[text_start:argument.start]
- ET.SubElement(step_text, 'b').text = str(argument.value)
+ if type(argument.value) is int:
+ argument.value = str(argument.value)
+ ET.SubElement(step_text, 'b').text = argument.value
text_start = argument.end
step_part = ET.SubElement(step_text, 'span')
step_part.text = result.name[self.arguments[-1].end:]
@@ -397,6 +399,13 @@ class HTMLFormatter(Formatter):
def _doEmbed(self, span, mime_type, data, caption):
self.embed_id += 1
+ # make a 'unicode' compat function for execution on python3
+ try:
+ unicode('')
+ except NameError:
+ def unicode(string):
+ return str(string)
+
link = ET.SubElement(span, 'a')
link.set("onclick", "Collapsible_toggle('embed_%s')" % self.embed_id)
@@ -439,7 +448,10 @@ class HTMLFormatter(Formatter):
embed = ET.SubElement(span, 'pre',
{'id': "embed_%s" % self.embed_id,
'style': 'display: none'})
- embed.text = cleaned_data
+ try:
+ embed.text = cleaned_data.decode('utf-8', 'replace')
+ except AttributeError: # this is python3
+ embed.text = cleaned_data
embed.tail = u' '
def embedding(self, mime_type, data, caption=None):