Revision: 2de043e21e53
Branch: default
Author: Robot Framework Developers ([email protected])
Date: Thu Jan 23 15:01:51 2014 UTC
Log: Fixed logging when keyword prints both Unicode and non-ASCII
bytes.
Also changed unic() to return immediately when given unicode input. This
allows using unic(item, encoding) both when item is str and unicode. As a
result it is possible to use decode_output(item) both with str and unicode.
Update issue 1626
Status: Done
Fixed with tests.
http://code.google.com/p/robotframework/source/detail?r=2de043e21e53
Modified:
/atest/robot/test_libraries/print_logging.txt
/atest/testdata/test_libraries/print_logging.txt
/src/robot/running/outputcapture.py
/src/robot/utils/unic.py
/utest/utils/test_unic.py
=======================================
--- /atest/robot/test_libraries/print_logging.txt Mon Nov 18 07:13:52 2013
UTC
+++ /atest/robot/test_libraries/print_logging.txt Thu Jan 23 15:01:51 2014
UTC
@@ -26,6 +26,11 @@
Check Log Message ${tc.kws[3].msgs[0]} Hyvää päivää!
Check Stderr Contains Hyvää päivää!
+Logging Mixed Non-ASCII Unicode And Bytes
+ [Tags] x-fails-on-ipy
+ ${tc} = Check Test Case ${TEST NAME}
+ Check Log Message ${tc.kws[2].msgs[0]} Hyvä byte! Hyvä Unicode!
+
Logging HTML
${tc} = Check Test Case ${TEST NAME}
Check Log Message ${tc.kws[0].msgs[0]} <a
href="http://www.google.com">Google</a> HTML
=======================================
--- /atest/testdata/test_libraries/print_logging.txt Mon Nov 18 07:13:52
2013 UTC
+++ /atest/testdata/test_libraries/print_logging.txt Thu Jan 23 15:01:51
2014 UTC
@@ -20,6 +20,11 @@
Print ${bytes}
Print ${bytes} stderr
+Logging Mixed Non-ASCII Unicode And Bytes
+ ${encoding} = Evaluate robot.utils.encoding.OUTPUT_ENCODING
robot
+ ${bytes} = Encode String To Bytes Hyvä byte! ${encoding}
+ Print Many ${bytes} Hyvä Unicode!
+
Logging HTML
Print One HTML Line
Print Many HTML Lines
=======================================
--- /src/robot/running/outputcapture.py Thu Jan 23 14:00:53 2014 UTC
+++ /src/robot/running/outputcapture.py Thu Jan 23 15:01:51 2014 UTC
@@ -74,10 +74,18 @@
def release(self):
# Original stream must be restored before closing the current
self._set_stream(self._original)
- self._stream.flush()
- output = self._stream.getvalue()
- self._stream.close()
- return output if isinstance(output, unicode) else
decode_output(output)
+ try:
+ return self._get_value(self._stream)
+ finally:
+ self._stream.close()
+
+ def _get_value(self, stream):
+ try:
+ return decode_output(stream.getvalue())
+ except UnicodeError:
+ stream.buf = decode_output(stream.buf)
+ stream.buflist = [decode_output(item) for item in
stream.buflist]
+ return stream.getvalue()
if not sys.platform.startswith('java'):
=======================================
--- /src/robot/utils/unic.py Thu Jan 23 14:00:53 2014 UTC
+++ /src/robot/utils/unic.py Thu Jan 23 15:01:51 2014 UTC
@@ -50,6 +50,8 @@
def _unic(item, *args):
# Based on a recipe from http://code.activestate.com/recipes/466341
try:
+ if isinstance(item, unicode):
+ return item
return unicode(item, *args)
except UnicodeError:
try:
=======================================
--- /utest/utils/test_unic.py Sun Nov 17 08:54:21 2013 UTC
+++ /utest/utils/test_unic.py Thu Jan 23 15:01:51 2014 UTC
@@ -53,6 +53,16 @@
# This is to check that unic normalizes all strings to NFC
assert_equals(unic(unicodedata.normalize('NFD', text)), text)
+ def test_encoding(self):
+ good = u'hyv\xe4'
+ assert_equals(unic(good.encode('UTF-8'), 'UTF-8'), good)
+ assert_equals(unic(good.encode('UTF-8'), 'ASCII', 'ignore'), 'hyv')
+
+ def test_encoding_when_already_unicode(self):
+ good = u'hyv\xe4'
+ assert_equals(unic(good, 'UTF-8'), good)
+ assert_equals(unic(good, 'UTF-8', 'ignore'), good)
+
def test_object_containing_unicode_repr(self):
assert_equals(unic(UnicodeRepr()), u'Hyv\xe4')
--
---
You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.