Skip to content

Commit 296046c

Browse files
authored
PYTHON-5121 - Use canonical Extended JSON for BSON binary vector spec… (#2215)
1 parent df30eff commit 296046c

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

test/bson_binary_vector/float32.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
{
3333
"description": "Infinity Vector FLOAT32",
3434
"valid": true,
35-
"vector": ["-inf", 0.0, "inf"],
35+
"vector": [{"$numberDouble": "-Infinity"}, 0.0, {"$numberDouble": "Infinity"} ],
3636
"dtype_hex": "0x27",
3737
"dtype_alias": "FLOAT32",
3838
"padding": 0,

test/test_bson_binary_vector.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616

1717
import binascii
1818
import codecs
19-
import json
2019
import struct
2120
from pathlib import Path
2221
from test import unittest
2322

24-
from bson import decode, encode
23+
from bson import decode, encode, json_util
2524
from bson.binary import Binary, BinaryVectorDtype
2625

2726
_TEST_PATH = Path(__file__).parent / "bson_binary_vector"
@@ -62,9 +61,6 @@ def run_test(self):
6261
cB_exp = binascii.unhexlify(canonical_bson_exp.encode("utf8"))
6362
decoded_doc = decode(cB_exp)
6463
binary_obs = decoded_doc[test_key]
65-
# Handle special float cases like '-inf'
66-
if dtype_exp in [BinaryVectorDtype.FLOAT32]:
67-
vector_exp = [float(x) for x in vector_exp]
6864

6965
# Test round-tripping canonical bson.
7066
self.assertEqual(encode(decoded_doc), cB_exp, description)
@@ -104,7 +100,7 @@ def run_test(self):
104100
def create_tests():
105101
for filename in _TEST_PATH.glob("*.json"):
106102
with codecs.open(str(filename), encoding="utf-8") as test_file:
107-
test_method = create_test(json.load(test_file))
103+
test_method = create_test(json_util.loads(test_file.read()))
108104
setattr(TestBSONBinaryVector, "test_" + filename.stem, test_method)
109105

110106

0 commit comments

Comments
 (0)