2 new revisions:
Revision: 2c2f6ff8552c
Author: Pekka Klärck
Date: Thu Jan 5 02:20:54 2012
Log: JSON dumping: Cannot generally dump strings not starting with '*'
as-i...
http://code.google.com/p/robotframework/source/detail?r=2c2f6ff8552c
Revision: 22a8b81fe980
Author: Pekka Klärck
Date: Thu Jan 5 02:22:20 2012
Log: Renamed test module to match tested module and test class to
match tes...
http://code.google.com/p/robotframework/source/detail?r=22a8b81fe980
==============================================================================
Revision: 2c2f6ff8552c
Author: Pekka Klärck
Date: Thu Jan 5 02:20:54 2012
Log: JSON dumping: Cannot generally dump strings not starting with '*'
as-is.
This performance enhancement fully broke reports/logs if there were
non-ASCII characters outside dumped string database, for example in
statistics. The speed boost can be added back but must be explicitly
configured.
http://code.google.com/p/robotframework/source/detail?r=2c2f6ff8552c
Modified:
/src/robot/reporting/jsonwriter.py
/utest/reporting/test_jsondump.py
=======================================
--- /src/robot/reporting/jsonwriter.py Sat Dec 17 13:11:32 2011
+++ /src/robot/reporting/jsonwriter.py Thu Jan 5 02:20:54 2012
@@ -44,8 +44,7 @@
self._dumpers = (MappingDumper(self),
IntegerDumper(self),
TupleListDumper(self),
- RawStringDumper(self),
- Base64StringDumper(self),
+ StringDumper(self),
NoneDumper(self),
DictDumper(self))
@@ -74,11 +73,9 @@
raise NotImplementedError
-class RawStringDumper(_Dumper):
+class StringDumper(_Dumper):
+ _handled_types = basestring
_replace =
{'\\': '\\\\', '"': '\\"', '\t': '\\t', '\n': '\\n', '\r': '\\r'}
-
- def handles(self, data, mapping):
- return isinstance(data, basestring) and data.startswith('*')
def dump(self, data, mapping):
self._write('"%s"' % ''.join(self._encode_chars(data)))
@@ -94,13 +91,6 @@
yield char if 31 < val < 127 else '\\u%04x' % val
-class Base64StringDumper(_Dumper):
- _handled_types = basestring
-
- def dump(self, data, mapping):
- self._write('"%s"' % data)
-
-
class IntegerDumper(_Dumper):
_handled_types = (int, long)
=======================================
--- /utest/reporting/test_jsondump.py Thu Dec 8 23:59:03 2011
+++ /utest/reporting/test_jsondump.py Thu Jan 5 02:20:54 2012
@@ -22,20 +22,16 @@
def _test(self, data, expected):
assert_equals(self._dump(data), expected)
- def test_dump_raw_string(self):
- self._test('*', '"*"')
- self._test('*xxx', '"*xxx"')
- self._test('*123', '"*123"')
-
- def test_dump_base64_string(self):
+ def test_dump_string(self):
self._test('', '""')
- self._test('cm9ib3Q=', '"cm9ib3Q="')
+ self._test('hello world', '"hello world"')
+ self._test('123', '"123"')
def test_dump_non_ascii_string(self):
- self._test(u'*hyv\xe4', '"*hyv\\u00e4"')
+ self._test(u'hyv\xe4', '"hyv\\u00e4"')
def test_escape_string(self):
- self._test('*"-\\-\n-\t-\r', '"*\\"-\\\\-\\n-\\t-\\r"')
+ self._test('"-\\-\n-\t-\r', '"\\"-\\\\-\\n-\\t-\\r"')
def test_dump_integer(self):
self._test(12, '12')
==============================================================================
Revision: 22a8b81fe980
Author: Pekka Klärck
Date: Thu Jan 5 02:22:20 2012
Log: Renamed test module to match tested module and test class to
match tested class.
http://code.google.com/p/robotframework/source/detail?r=22a8b81fe980
Added:
/utest/reporting/test_jsonwriter.py
Deleted:
/utest/reporting/test_jsondump.py
=======================================
--- /dev/null
+++ /utest/reporting/test_jsonwriter.py Thu Jan 5 02:22:20 2012
@@ -0,0 +1,85 @@
+from StringIO import StringIO
+try:
+ import json
+except ImportError:
+ try:
+ import simplejson as json
+ except ImportError:
+ json = None
+import unittest
+
+from robot.utils.asserts import assert_equals, assert_raises
+from robot.reporting.jsonwriter import JsonDumper
+
+
+class TestJsonDumper(unittest.TestCase):
+
+ def _dump(self, data):
+ output = StringIO()
+ JsonDumper(output).dump(data)
+ return output.getvalue()
+
+ def _test(self, data, expected):
+ assert_equals(self._dump(data), expected)
+
+ def test_dump_string(self):
+ self._test('', '""')
+ self._test('hello world', '"hello world"')
+ self._test('123', '"123"')
+
+ def test_dump_non_ascii_string(self):
+ self._test(u'hyv\xe4', '"hyv\\u00e4"')
+
+ def test_escape_string(self):
+ self._test('"-\\-\n-\t-\r', '"\\"-\\\\-\\n-\\t-\\r"')
+
+ def test_dump_integer(self):
+ self._test(12, '12')
+ self._test(-12312, '-12312')
+ self._test(0, '0')
+
+ def test_dump_long(self):
+ self._test(12345678901234567890L, '12345678901234567890')
+ self._test(0L, '0')
+
+ def test_dump_list(self):
+ self._test([1,2,3, 'hello', 'world'], '[1,2,3,"hello","world"]')
+ self._test(['*nes"ted', [1,2,[4]]], '["*nes\\"ted",[1,2,[4]]]')
+
+ def test_dump_tuple(self):
+ self._test(('hello', '*world'), '["hello","*world"]')
+ self._test((1,2,(3,4)), '[1,2,[3,4]]')
+
+ def test_dump_dictionary(self):
+ self._test({'key': 1}, '{"key":1}')
+ self._test({'nested': [-1L, {42:
None}]}, '{"nested":[-1,{42:null}]}')
+
+ def test_dictionaries_are_sorted(self):
+ self._test({'key':1, 'hello':['wor','ld'], 'z': 'a', 'a': 'z'},
+ '{"a":"z","hello":["wor","ld"],"key":1,"z":"a"}')
+
+ def test_dump_none(self):
+ self._test(None, 'null')
+
+ def test_json_dump_mapping(self):
+ output = StringIO()
+ dumper = JsonDumper(output)
+ mapped1 = object()
+ mapped2 = 'string'
+ dumper.dump([mapped1, [mapped2, {mapped2: mapped1}]],
+ mapping={mapped1:'1', mapped2:'a'})
+ assert_equals(output.getvalue(), '[1,[a,{a:1}]]')
+ assert_raises(ValueError, dumper.dump, [mapped1])
+
+ if json:
+ def test_agains_standard_json(self):
+ string = u'*string\u00A9\v\\\'\"\r\t\njee' \
+ + u''.join(unichr(i) for i in xrange(32, 1024))
+ data = [string, {'A': 1}, None]
+ expected = StringIO()
+ json.dump(data, expected, separators=(',', ':'))
+ self._test(data, expected.getvalue())
+
+
+if __name__ == '__main__':
+ unittest.main()
=======================================
--- /utest/reporting/test_jsondump.py Thu Jan 5 02:20:54 2012
+++ /dev/null
@@ -1,85 +0,0 @@
-from StringIO import StringIO
-try:
- import json
-except ImportError:
- try:
- import simplejson as json
- except ImportError:
- json = None
-import unittest
-
-from robot.utils.asserts import assert_equals, assert_raises
-from robot.reporting.jsonwriter import JsonDumper
-
-
-class JsonTestCase(unittest.TestCase):
-
- def _dump(self, data):
- output = StringIO()
- JsonDumper(output).dump(data)
- return output.getvalue()
-
- def _test(self, data, expected):
- assert_equals(self._dump(data), expected)
-
- def test_dump_string(self):
- self._test('', '""')
- self._test('hello world', '"hello world"')
- self._test('123', '"123"')
-
- def test_dump_non_ascii_string(self):
- self._test(u'hyv\xe4', '"hyv\\u00e4"')
-
- def test_escape_string(self):
- self._test('"-\\-\n-\t-\r', '"\\"-\\\\-\\n-\\t-\\r"')
-
- def test_dump_integer(self):
- self._test(12, '12')
- self._test(-12312, '-12312')
- self._test(0, '0')
-
- def test_dump_long(self):
- self._test(12345678901234567890L, '12345678901234567890')
- self._test(0L, '0')
-
- def test_dump_list(self):
- self._test([1,2,3, 'hello', 'world'], '[1,2,3,"hello","world"]')
- self._test(['*nes"ted', [1,2,[4]]], '["*nes\\"ted",[1,2,[4]]]')
-
- def test_dump_tuple(self):
- self._test(('hello', '*world'), '["hello","*world"]')
- self._test((1,2,(3,4)), '[1,2,[3,4]]')
-
- def test_dump_dictionary(self):
- self._test({'key': 1}, '{"key":1}')
- self._test({'nested': [-1L, {42:
None}]}, '{"nested":[-1,{42:null}]}')
-
- def test_dictionaries_are_sorted(self):
- self._test({'key':1, 'hello':['wor','ld'], 'z': 'a', 'a': 'z'},
- '{"a":"z","hello":["wor","ld"],"key":1,"z":"a"}')
-
- def test_dump_none(self):
- self._test(None, 'null')
-
- def test_json_dump_mapping(self):
- output = StringIO()
- dumper = JsonDumper(output)
- mapped1 = object()
- mapped2 = 'string'
- dumper.dump([mapped1, [mapped2, {mapped2: mapped1}]],
- mapping={mapped1:'1', mapped2:'a'})
- assert_equals(output.getvalue(), '[1,[a,{a:1}]]')
- assert_raises(ValueError, dumper.dump, [mapped1])
-
- if json:
- def test_agains_standard_json(self):
- string = u'*string\u00A9\v\\\'\"\r\t\njee' \
- + u''.join(unichr(i) for i in xrange(32, 1024))
- data = [string, {'A': 1}, None]
- expected = StringIO()
- json.dump(data, expected, separators=(',', ':'))
- self._test(data, expected.getvalue())
-
-
-if __name__ == '__main__':
- unittest.main()