|
21 | 21 | from pathlib import Path
|
22 | 22 | from test import unittest
|
23 | 23 |
|
24 |
| -from bson import decode, encode |
| 24 | +from bson import decode, encode, json_util |
25 | 25 | from bson.binary import Binary, BinaryVectorDtype
|
26 | 26 |
|
27 | 27 | _TEST_PATH = Path(__file__).parent / "bson_binary_vector"
|
28 | 28 |
|
29 | 29 |
|
30 |
| -def convert_extended_json(vector) -> float: |
31 |
| - if isinstance(vector, dict) and "$numberDouble" in vector: |
32 |
| - if vector["$numberDouble"] == "Infinity": |
33 |
| - return float("inf") |
34 |
| - elif vector["$numberDouble"] == "-Infinity": |
35 |
| - return float("-inf") |
36 |
| - return float(vector) |
37 |
| - |
38 |
| - |
39 | 30 | class TestBSONBinaryVector(unittest.TestCase):
|
40 | 31 | """Runs Binary Vector subtype tests.
|
41 | 32 |
|
@@ -71,9 +62,6 @@ def run_test(self):
|
71 | 62 | cB_exp = binascii.unhexlify(canonical_bson_exp.encode("utf8"))
|
72 | 63 | decoded_doc = decode(cB_exp)
|
73 | 64 | binary_obs = decoded_doc[test_key]
|
74 |
| - # Handle special extended JSON cases like 'Infinity' |
75 |
| - if dtype_exp in [BinaryVectorDtype.FLOAT32]: |
76 |
| - vector_exp = [convert_extended_json(x) for x in vector_exp] |
77 | 65 |
|
78 | 66 | # Test round-tripping canonical bson.
|
79 | 67 | self.assertEqual(encode(decoded_doc), cB_exp, description)
|
@@ -113,7 +101,7 @@ def run_test(self):
|
113 | 101 | def create_tests():
|
114 | 102 | for filename in _TEST_PATH.glob("*.json"):
|
115 | 103 | with codecs.open(str(filename), encoding="utf-8") as test_file:
|
116 |
| - test_method = create_test(json.load(test_file)) |
| 104 | + test_method = create_test(json_util.load(test_file)) |
117 | 105 | setattr(TestBSONBinaryVector, "test_" + filename.stem, test_method)
|
118 | 106 |
|
119 | 107 |
|
|
0 commit comments