test_json.py 926 B

12345678910111213141516171819202122232425262728293031323334
  1. import pprint
  2. from unittest import TestCase
  3. from ..nbjson import reads, writes
  4. from .nbexamples import nb0
  5. class TestJSON(TestCase):
  6. def test_roundtrip(self):
  7. s = writes(nb0)
  8. # print
  9. # print pprint.pformat(nb0,indent=2)
  10. # print
  11. # print pprint.pformat(reads(s),indent=2)
  12. # print
  13. # print s
  14. self.assertEqual(reads(s),nb0)
  15. def test_roundtrip_nosplit(self):
  16. """Ensure that multiline blobs are still readable"""
  17. # ensures that notebooks written prior to splitlines change
  18. # are still readable.
  19. s = writes(nb0, split_lines=False)
  20. self.assertEqual(reads(s),nb0)
  21. def test_roundtrip_split(self):
  22. """Ensure that splitting multiline blocks is safe"""
  23. # This won't differ from test_roundtrip unless the default changes
  24. s = writes(nb0, split_lines=True)
  25. self.assertEqual(reads(s),nb0)