Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More tests for canonicaljson encoding #3

Merged
merged 1 commit into from
Mar 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions test_canonicaljson.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright 2015 OpenMarket Ltd
# Copyright 2018 New Vector Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,12 +30,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ée": u"💩",
}), b'{"la merde amus\xc3\xa9e":"\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