PYTHON-5121 - Use canonical Extended JSON for BSON binary vector spec… (#2215)
This commit is contained in:
parent
df30eff390
commit
296046cc38
@ -32,7 +32,7 @@
|
||||
{
|
||||
"description": "Infinity Vector FLOAT32",
|
||||
"valid": true,
|
||||
"vector": ["-inf", 0.0, "inf"],
|
||||
"vector": [{"$numberDouble": "-Infinity"}, 0.0, {"$numberDouble": "Infinity"} ],
|
||||
"dtype_hex": "0x27",
|
||||
"dtype_alias": "FLOAT32",
|
||||
"padding": 0,
|
||||
|
||||
@ -16,12 +16,11 @@ from __future__ import annotations
|
||||
|
||||
import binascii
|
||||
import codecs
|
||||
import json
|
||||
import struct
|
||||
from pathlib import Path
|
||||
from test import unittest
|
||||
|
||||
from bson import decode, encode
|
||||
from bson import decode, encode, json_util
|
||||
from bson.binary import Binary, BinaryVectorDtype
|
||||
|
||||
_TEST_PATH = Path(__file__).parent / "bson_binary_vector"
|
||||
@ -62,9 +61,6 @@ def create_test(case_spec):
|
||||
cB_exp = binascii.unhexlify(canonical_bson_exp.encode("utf8"))
|
||||
decoded_doc = decode(cB_exp)
|
||||
binary_obs = decoded_doc[test_key]
|
||||
# Handle special float cases like '-inf'
|
||||
if dtype_exp in [BinaryVectorDtype.FLOAT32]:
|
||||
vector_exp = [float(x) for x in vector_exp]
|
||||
|
||||
# Test round-tripping canonical bson.
|
||||
self.assertEqual(encode(decoded_doc), cB_exp, description)
|
||||
@ -104,7 +100,7 @@ def create_test(case_spec):
|
||||
def create_tests():
|
||||
for filename in _TEST_PATH.glob("*.json"):
|
||||
with codecs.open(str(filename), encoding="utf-8") as test_file:
|
||||
test_method = create_test(json.load(test_file))
|
||||
test_method = create_test(json_util.loads(test_file.read()))
|
||||
setattr(TestBSONBinaryVector, "test_" + filename.stem, test_method)
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user