summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2017-06-19 11:18:13 -0700
committerBob Ippolito <bob@redivi.com>2017-06-19 11:18:13 -0700
commit59e9bbf023cff1684786d7fb0ae3d0501f96ecb6 (patch)
tree3fd0f1c0cd9fa2271e5952ebb1f49981493c184d
parent52550b07f2e39d53d55ec13aedc5421959168ecd (diff)
downloadsimplejson-59e9bbf023cff1684786d7fb0ae3d0501f96ecb6.tar.gz
Fix #173 with item_sort_key and add auto-discovery to test suite
-rw-r--r--CHANGES.txt6
-rw-r--r--simplejson/_speedups.c22
-rw-r--r--simplejson/tests/__init__.py38
-rw-r--r--simplejson/tests/test_item_sort_key.py7
4 files changed, 31 insertions, 42 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index ae8b7e3..eecb59e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,9 @@
+Version 3.11.1 released 2017-06-19
+
+* Fix issue with item_sort_key when speedups are available, and add
+ auto-discovery to test suites to prevent similar regressions
+ https://github.com/simplejson/simplejson/issues/173
+
Version 3.11.0 released 2017-06-18
* docstring fix in JSONEncoder
diff --git a/simplejson/_speedups.c b/simplejson/_speedups.c
index 7d74ffc..36dcf91 100644
--- a/simplejson/_speedups.c
+++ b/simplejson/_speedups.c
@@ -2678,17 +2678,17 @@ encoder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (!item_sort_key)
goto bail;
}
- if (item_sort_key == Py_None) {
- Py_INCREF(Py_None);
- s->item_sort_kw = Py_None;
- }
- else {
- s->item_sort_kw = PyDict_New();
- if (s->item_sort_kw == NULL)
- goto bail;
- if (PyDict_SetItemString(s->item_sort_kw, "key", item_sort_key))
- goto bail;
- }
+ }
+ if (item_sort_key == Py_None) {
+ Py_INCREF(Py_None);
+ s->item_sort_kw = Py_None;
+ }
+ else {
+ s->item_sort_kw = PyDict_New();
+ if (s->item_sort_kw == NULL)
+ goto bail;
+ if (PyDict_SetItemString(s->item_sort_kw, "key", item_sort_key))
+ goto bail;
}
Py_INCREF(sort_keys);
s->sort_keys = sort_keys;
diff --git a/simplejson/tests/__init__.py b/simplejson/tests/__init__.py
index 95e98e5..8d2642f 100644
--- a/simplejson/tests/__init__.py
+++ b/simplejson/tests/__init__.py
@@ -2,6 +2,7 @@ from __future__ import absolute_import
import unittest
import doctest
import sys
+import os
class NoExtensionTestSuite(unittest.TestSuite):
@@ -35,38 +36,13 @@ def additional_tests(suite=None):
def all_tests_suite():
def get_suite():
+ suite_names = [
+ 'simplejson.tests.%s' % (os.path.splitext(f)[0],)
+ for f in os.listdir(os.path.dirname(__file__))
+ if f.startswith('test_') and f.endswith('.py')
+ ]
return additional_tests(
- unittest.TestLoader().loadTestsFromNames([
- 'simplejson.tests.test_bitsize_int_as_string',
- 'simplejson.tests.test_bigint_as_string',
- 'simplejson.tests.test_check_circular',
- 'simplejson.tests.test_decode',
- 'simplejson.tests.test_default',
- 'simplejson.tests.test_dump',
- 'simplejson.tests.test_encode_basestring_ascii',
- 'simplejson.tests.test_encode_for_html',
- 'simplejson.tests.test_errors',
- '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',
- 'simplejson.tests.test_recursion',
- 'simplejson.tests.test_scanstring',
- 'simplejson.tests.test_separators',
- 'simplejson.tests.test_speedups',
- 'simplejson.tests.test_str_subclass',
- 'simplejson.tests.test_unicode',
- 'simplejson.tests.test_decimal',
- 'simplejson.tests.test_tuple',
- 'simplejson.tests.test_namedtuple',
- 'simplejson.tests.test_tool',
- 'simplejson.tests.test_for_json',
- 'simplejson.tests.test_subclass',
- 'simplejson.tests.test_raw_json',
- ]))
+ unittest.TestLoader().loadTestsFromNames(suite_names))
suite = get_suite()
import simplejson
if simplejson._import_c_make_encoder() is None:
diff --git a/simplejson/tests/test_item_sort_key.py b/simplejson/tests/test_item_sort_key.py
index b05bfc8..98971b8 100644
--- a/simplejson/tests/test_item_sort_key.py
+++ b/simplejson/tests/test_item_sort_key.py
@@ -18,3 +18,10 @@ class TestItemSortKey(TestCase):
self.assertEqual(
'{"a": 1, "Array": [1, 5, 6, 9], "c": 5, "crate": "dog", "Jack": "jill", "pick": "axe", "tuple": [83, 12, 3], "zeak": "oh"}',
json.dumps(a, item_sort_key=lambda kv: kv[0].lower()))
+
+ def test_item_sort_key_value(self):
+ # https://github.com/simplejson/simplejson/issues/173
+ a = {'a': 1, 'b': 0}
+ self.assertEqual(
+ '{"b": 0, "a": 1}',
+ json.dumps(a, item_sort_key=lambda kv: kv[1]))