Skip to content

Commit

Permalink
PYTHON-4179 Verify document_class type in json_util.loads test
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaneHarvey committed Feb 5, 2024
1 parent 97b9a33 commit 03d1281
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions test/test_json_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import re
import sys
import uuid
from collections import OrderedDict
from typing import Any, List, MutableMapping, Tuple, Type

from bson.codec_options import CodecOptions, DatetimeConversion
Expand Down Expand Up @@ -557,15 +558,13 @@ def test_numberlong(self):
)

def test_loads_document_class(self):
# document_class dict should always work
self.assertEqual(
{"foo": "bar"},
json_util.loads('{"foo": "bar"}', json_options=JSONOptions(document_class=dict)),
)
self.assertEqual(
SON([("foo", "bar"), ("b", 1)]),
json_util.loads('{"foo": "bar", "b": 1}', json_options=JSONOptions(document_class=SON)),
)
json_doc = '{"foo": "bar", "b": 1, "d": {"a": 1}}'
expected_doc = {"foo": "bar", "b": 1, "d": {"a": 1}}
for cls in (dict, SON, OrderedDict):
doc = json_util.loads(json_doc, json_options=JSONOptions(document_class=cls))
self.assertEqual(doc, expected_doc)
self.assertIsInstance(doc, cls)
self.assertIsInstance(doc["d"], cls)

def test_encode_subclass(self):
cases: list[Tuple[Type, Any]] = [
Expand Down

0 comments on commit 03d1281

Please sign in to comment.