summaryrefslogtreecommitdiff
path: root/simplejson/tests
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2017-11-23 13:52:00 -0800
committerBob Ippolito <bob@redivi.com>2017-11-23 13:52:00 -0800
commit47bb9950941aed34aef4fcad3fd20a2585c696f2 (patch)
treedda702219b4e599c445aa74c1074cb237ff9d409 /simplejson/tests
parent0fd73bc8c6ad200754cce837ba8c97715e95ee25 (diff)
downloadsimplejson-47bb9950941aed34aef4fcad3fd20a2585c696f2.tar.gz
Ensure that encoding text subtypes is consistent with or without speedups. Fixes #185
Diffstat (limited to 'simplejson/tests')
-rw-r--r--simplejson/tests/test_dump.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/simplejson/tests/test_dump.py b/simplejson/tests/test_dump.py
index 3661de0..f5f4c1f 100644
--- a/simplejson/tests/test_dump.py
+++ b/simplejson/tests/test_dump.py
@@ -1,7 +1,11 @@
from unittest import TestCase
-from simplejson.compat import StringIO, long_type, b, binary_type, PY3
+from simplejson.compat import StringIO, long_type, b, binary_type, text_type, PY3
import simplejson as json
+class MisbehavingTextSubtype(text_type):
+ def __str__(self):
+ return "FAIL!"
+
def as_text_type(s):
if PY3 and isinstance(s, binary_type):
return s.decode('ascii')
@@ -128,3 +132,11 @@ class TestDump(TestCase):
json.dump(p, sio, sort_keys=True)
self.assertEqual(sio.getvalue(), json.dumps(p, sort_keys=True))
self.assertEqual(json.loads(sio.getvalue()), p)
+
+ def test_misbehaving_text_subtype(self):
+ # https://github.com/simplejson/simplejson/issues/185
+ text = "this is some text"
+ self.assertEqual(
+ json.dumps(MisbehavingTextSubtype(text)),
+ json.dumps(text)
+ )