Skip to content

Commit

Permalink
Fix #173 with item_sort_key and add auto-discovery to test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
etrepum committed Jun 19, 2017
1 parent 52550b0 commit 59e9bbf
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 42 deletions.
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
22 changes: 11 additions & 11 deletions simplejson/_speedups.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 7 additions & 31 deletions simplejson/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import unittest
import doctest
import sys
import os


class NoExtensionTestSuite(unittest.TestSuite):
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions simplejson/tests/test_item_sort_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ def test_case(self):
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]))

0 comments on commit 59e9bbf

Please sign in to comment.