From 2595e25258315f79c4eb82785770767716f247db Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 3 Feb 2021 10:16:34 -0500 Subject: [PATCH] Improve coverage, specifically of values that are bytes. --- src/allmydata/test/test_util.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/allmydata/test/test_util.py b/src/allmydata/test/test_util.py index 58de96d1c..5f5db82bd 100644 --- a/src/allmydata/test/test_util.py +++ b/src/allmydata/test/test_util.py @@ -491,12 +491,16 @@ class JSONBytes(unittest.TestCase): """Tests for BytesJSONEncoder.""" def test_encode_bytes(self): - """BytesJSONEncoder can encode bytes.""" + """BytesJSONEncoder can encode bytes. + + Bytes are presumed to be UTF-8 encoded. + """ + snowman = u"def\N{SNOWMAN}\uFF00" data = { - b"hello": [1, b"cd", {b"abc": 123}], + b"hello": [1, b"cd", {b"abc": [123, snowman.encode("utf-8")]}], } expected = { - u"hello": [1, u"cd", {u"abc": 123}], + u"hello": [1, u"cd", {u"abc": [123, snowman]}], } # Bytes get passed through as if they were UTF-8 Unicode: encoded = jsonbytes.dumps(data)