Revision: 54f21956051b
Branch:   default
Author:   Pekka Klärck
Date:     Wed Sep 12 06:06:32 2012
Log:      utils.safe_repr: new attempt to add u prefix to list items
http://code.google.com/p/robotframework/source/detail?r=54f21956051b

Modified:
 /src/robot/utils/unic.py
 /utest/utils/test_unic.py

=======================================
--- /src/robot/utils/unic.py    Wed Sep 12 04:38:19 2012
+++ /src/robot/utils/unic.py    Wed Sep 12 06:06:32 2012
@@ -67,9 +67,13 @@
         return _unrepresentable_object(item)

 if sys.platform == 'cli':
- # IronPython omits u prefix from repr(u'foo') but we want to be consistent. + # IronPython omits `u` prefix from `repr(u'foo')`. We add it back to have
+    # consistent and easier to test log messages.
     _safe_repr = safe_repr
+
     def safe_repr(item):
+        if isinstance(item, list):
+            return '[%s]' % ', '.join(safe_repr(i) for i in item)
         ret = _safe_repr(item)
         if isinstance(item, unicode) and not ret.startswith('u'):
             ret = 'u' + ret
=======================================
--- /utest/utils/test_unic.py   Wed Sep 12 04:38:19 2012
+++ /utest/utils/test_unic.py   Wed Sep 12 06:06:32 2012
@@ -84,13 +84,17 @@
         assert_equals(safe_repr(u'foo'), "u'foo'")
         assert_equals(safe_repr(u"f'o'o"), "u\"f'o'o\"")

+    def test_unicode_items_in_list_repr_have_u_prefix(self):
+        assert_equals(safe_repr([]), '[]')
+        assert_equals(safe_repr([u'foo']), "[u'foo']")
+        assert_equals(safe_repr([u'a', 1, u"'"]), "[u'a', 1, u\"'\"]")
+

 class UnicodeRepr:

     def __repr__(self):
         return u'Hyv\xe4'

-
 class UnicodeFails(object):
     def __unicode__(self): raise RuntimeError('Failure in __unicode__')

Reply via email to