Skip to content

Commit 296a44d

Browse files
authored
PYTHON-4179 Verify document_class type in json_util.loads test (#1509)
1 parent 051ff77 commit 296a44d

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

test/test_json_util.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import re
2121
import sys
2222
import uuid
23+
from collections import OrderedDict
2324
from typing import Any, List, MutableMapping, Tuple, Type
2425

2526
from bson.codec_options import CodecOptions, DatetimeConversion
@@ -557,15 +558,13 @@ def test_numberlong(self):
557558
)
558559

559560
def test_loads_document_class(self):
560-
# document_class dict should always work
561-
self.assertEqual(
562-
{"foo": "bar"},
563-
json_util.loads('{"foo": "bar"}', json_options=JSONOptions(document_class=dict)),
564-
)
565-
self.assertEqual(
566-
SON([("foo", "bar"), ("b", 1)]),
567-
json_util.loads('{"foo": "bar", "b": 1}', json_options=JSONOptions(document_class=SON)),
568-
)
561+
json_doc = '{"foo": "bar", "b": 1, "d": {"a": 1}}'
562+
expected_doc = {"foo": "bar", "b": 1, "d": {"a": 1}}
563+
for cls in (dict, SON, OrderedDict):
564+
doc = json_util.loads(json_doc, json_options=JSONOptions(document_class=cls))
565+
self.assertEqual(doc, expected_doc)
566+
self.assertIsInstance(doc, cls)
567+
self.assertIsInstance(doc["d"], cls)
569568

570569
def test_encode_subclass(self):
571570
cases: list[Tuple[Type, Any]] = [

0 commit comments

Comments
 (0)