test_str_subclass.py 551 B

12345678910111213141516
  1. from unittest import TestCase
  2. import simplejson
  3. from simplejson.compat import text_type, u
  4. # Tests for issue demonstrated in https://github.com/simplejson/simplejson/issues/144
  5. class WonkyTextSubclass(text_type):
  6. def __getslice__(self, start, end):
  7. return self.__class__('not what you wanted!')
  8. class TestStrSubclass(TestCase):
  9. def test_dump_load(self):
  10. for s in ['', '"hello"', 'text', u('\u005c')]:
  11. self.assertEqual(
  12. s,
  13. simplejson.loads(simplejson.dumps(WonkyTextSubclass(s))))