summaryrefslogtreecommitdiff
path: root/simplejson/tests
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2016-10-21 14:54:32 +0700
committerBob Ippolito <bob@redivi.com>2016-10-21 14:54:32 +0700
commitd78256146d2831e3a7080b7212d7edb90bc2d611 (patch)
treeece8b9d9c5a6be0242c3ec1083c08297f6c75811 /simplejson/tests
parent9902c546bcf2133b4961502d71bac908d55da40c (diff)
downloadsimplejson-d78256146d2831e3a7080b7212d7edb90bc2d611.tar.gz
Fixes #144. Workaround for bad behavior in string subclasses.
Diffstat (limited to 'simplejson/tests')
-rw-r--r--simplejson/tests/__init__.py1
-rw-r--r--simplejson/tests/test_str_subclass.py16
2 files changed, 17 insertions, 0 deletions
diff --git a/simplejson/tests/__init__.py b/simplejson/tests/__init__.py
index 88249d1..3a00b08 100644
--- a/simplejson/tests/__init__.py
+++ b/simplejson/tests/__init__.py
@@ -57,6 +57,7 @@ def all_tests_suite():
'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',
diff --git a/simplejson/tests/test_str_subclass.py b/simplejson/tests/test_str_subclass.py
new file mode 100644
index 0000000..771eb67
--- /dev/null
+++ b/simplejson/tests/test_str_subclass.py
@@ -0,0 +1,16 @@
+from unittest import TestCase
+
+import simplejson
+from simplejson.compat import text_type, u
+
+# Tests for issue demonstrated in https://github.com/simplejson/simplejson/issues/144
+class WonkyTextSubclass(text_type):
+ def __getslice__(self, start, end):
+ return self.__class__('not what you wanted!')
+
+class TestStrSubclass(TestCase):
+ def test_dump_load(self):
+ for s in ['', '"hello"', 'text', u('\u005c')]:
+ self.assertEqual(
+ s,
+ simplejson.loads(simplejson.dumps(WonkyTextSubclass(s))))