Skip to content

Commit

Permalink
More tests for canonicaljson encoding
Browse files Browse the repository at this point in the history
Test that unicode and frozendicts are encoded correctly
  • Loading branch information
richvdh committed Mar 28, 2018
1 parent 5a36a43 commit a328d19
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions test_canonicaljson.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,22 @@ class TestCanonicalJson(unittest.TestCase):
def test_encode_canonical(self):
self.assertEquals(encode_canonical_json({}), b'{}')

# non-ascii should come out utf8-encoded.
self.assertEquals(encode_canonical_json({
u"la merde amus\u00c3e": u"\U0001F4A9",
}), b'{"la merde amus\xc3\x83e":"\xF0\x9F\x92\xA9"}')

def test_encode_pretty_printed(self):
self.assertEquals(encode_pretty_printed_json({}), b'{}')

def test_frozen_dict(self):
self.assertEquals(encode_canonical_json(frozendict({})), b'{}')
self.assertEquals(encode_pretty_printed_json(frozendict({})), b'{}')
self.assertEquals(
encode_canonical_json(frozendict({"a": 1})),
b'{"a":1}',
)
self.assertEquals(
encode_pretty_printed_json(frozendict({"a": 1})),
b'{\n "a": 1\n}')

def test_unknown_type(self):
class Unknown(object):
Expand Down

0 comments on commit a328d19

Please sign in to comment.