diff options
author | Bob Ippolito <bob@redivi.com> | 2015-10-27 08:31:48 -0700 |
---|---|---|
committer | Bob Ippolito <bob@redivi.com> | 2015-10-27 08:31:48 -0700 |
commit | b979a80722bfbcecc6cde366449e1e0b605c51b6 (patch) | |
tree | 1d977c0ea878cc2ad27aeb14e51cdf0ec5dc9857 /simplejson/tests | |
parent | 82fdecb6a892579bde16f43b4b983b9dce6c3643 (diff) | |
download | simplejson-b979a80722bfbcecc6cde366449e1e0b605c51b6.tar.gz |
Fix issue with iterable_as_array and indent option, closes #128v3.8.1
Diffstat (limited to 'simplejson/tests')
-rw-r--r-- | simplejson/tests/__init__.py | 1 | ||||
-rw-r--r-- | simplejson/tests/test_iterable.py | 34 |
2 files changed, 18 insertions, 17 deletions
diff --git a/simplejson/tests/__init__.py b/simplejson/tests/__init__.py index 8c1a4f1..88249d1 100644 --- a/simplejson/tests/__init__.py +++ b/simplejson/tests/__init__.py @@ -49,6 +49,7 @@ def all_tests_suite(): 'simplejson.tests.test_fail', 'simplejson.tests.test_float', 'simplejson.tests.test_indent', + 'simplejson.tests.test_iterable', 'simplejson.tests.test_pass1', 'simplejson.tests.test_pass2', 'simplejson.tests.test_pass3', diff --git a/simplejson/tests/test_iterable.py b/simplejson/tests/test_iterable.py index 4b37d00..35d3e75 100644 --- a/simplejson/tests/test_iterable.py +++ b/simplejson/tests/test_iterable.py @@ -1,5 +1,5 @@ import unittest -from StringIO import StringIO +from simplejson.compat import StringIO import simplejson as json @@ -13,19 +13,19 @@ def sio_dump(obj, **kw): class TestIterable(unittest.TestCase): def test_iterable(self): - l = [1, 2, 3] - for dumps in (json.dumps, iter_dumps, sio_dump): - expect = dumps(l) - default_expect = dumps(sum(l)) - # Default is False - self.assertRaises(TypeError, dumps, iter(l)) - self.assertRaises(TypeError, dumps, iter(l), iterable_as_array=False) - self.assertEqual(expect, dumps(iter(l), iterable_as_array=True)) - # Ensure that the "default" gets called - self.assertEqual(default_expect, dumps(iter(l), default=sum)) - self.assertEqual(default_expect, dumps(iter(l), iterable_as_array=False, default=sum)) - # Ensure that the "default" does not get called - self.assertEqual( - default_expect, - dumps(iter(l), iterable_as_array=True, default=sum)) -
\ No newline at end of file + for l in ([], [1], [1, 2], [1, 2, 3]): + for opts in [{}, {'indent': 2}]: + for dumps in (json.dumps, iter_dumps, sio_dump): + expect = dumps(l, **opts) + default_expect = dumps(sum(l), **opts) + # Default is False + self.assertRaises(TypeError, dumps, iter(l), **opts) + self.assertRaises(TypeError, dumps, iter(l), iterable_as_array=False, **opts) + self.assertEqual(expect, dumps(iter(l), iterable_as_array=True, **opts)) + # Ensure that the "default" gets called + self.assertEqual(default_expect, dumps(iter(l), default=sum, **opts)) + self.assertEqual(default_expect, dumps(iter(l), iterable_as_array=False, default=sum, **opts)) + # Ensure that the "default" does not get called + self.assertEqual( + expect, + dumps(iter(l), iterable_as_array=True, default=sum, **opts)) |