Skip to content

Commit 8ce1288

Browse files
committed
Changed order of BinaryVector and Binary in bson._ENCODERS to get test.test_bson.TestBSON.test_encode_type_marker to pass
1 parent aeeac08 commit 8ce1288

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

bson/vector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def __repr__(self) -> str:
117117
def __eq__(self, other: Any) -> bool:
118118
if isinstance(other, BinaryVector):
119119
return (
120-
self.__subtype == other.subtype
120+
self.subtype == other.subtype
121121
and self.dtype == other.dtype
122122
and self.padding == other.padding
123123
and bytes(self) == bytes(other)

test/test_bson.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
from bson.son import SON
6363
from bson.timestamp import Timestamp
6464
from bson.tz_util import FixedOffset, utc
65+
from bson.vector import DTYPES, BinaryVector
6566

6667

6768
class NotADict(abc.MutableMapping):
@@ -147,6 +148,11 @@ def helper(doc):
147148
helper({"a binary": Binary(b"test", 128)})
148149
helper({"a binary": Binary(b"test", 254)})
149150
helper({"another binary": Binary(b"test", 2)})
151+
helper({"a binary vector": BinaryVector(b"\x01\x0f\xff", b"\x10", 3)})
152+
helper({"a binary vector": BinaryVector(b"\x01\x0f\xff", DTYPES.BOOL, 3)})
153+
helper({"a binary vector": BinaryVector(b"\x01\x0f\xff", b"\x03")})
154+
helper({"a binary vector": BinaryVector(b"\x01\x0f\xff", DTYPES.INT8)})
155+
helper({"a binary vector": BinaryVector(b"\xcd\xcc\x8c\xbf\xc7H7P", DTYPES.FLOAT32)})
150156
helper(SON([("test dst", datetime.datetime(1993, 4, 4, 2))]))
151157
helper(SON([("test negative dst", datetime.datetime(1, 1, 1, 1, 1, 1))]))
152158
helper({"big float": float(10000000000)})
@@ -446,6 +452,18 @@ def test_basic_encode(self):
446452
encode({"test": Binary(b"test", 128)}),
447453
b"\x14\x00\x00\x00\x05\x74\x65\x73\x74\x00\x04\x00\x00\x00\x80\x74\x65\x73\x74\x00",
448454
)
455+
self.assertEqual(
456+
encode({"vector_int8": BinaryVector.from_list([-128, -1, 127], DTYPES.INT8)}),
457+
b"\x1c\x00\x00\x00\x05vector_int8\x00\x03\x00\x00\x00\t\x03\x00\x80\xff\x7f\x00",
458+
)
459+
self.assertEqual(
460+
encode({"vector_bool": BinaryVector.from_list([1, 127], DTYPES.BOOL)}),
461+
b"\x1b\x00\x00\x00\x05vector_bool\x00\x02\x00\x00\x00\t\x10\x00\x01\x7f\x00",
462+
)
463+
self.assertEqual(
464+
encode({"vector_float32": BinaryVector.from_list([-1.1, 1.1e10], DTYPES.FLOAT32)}),
465+
b"$\x00\x00\x00\x05vector_float32\x00\x08\x00\x00\x00\t'\x00\xcd\xcc\x8c\xbf\xac\xe9#P\x00",
466+
)
449467
self.assertEqual(encode({"test": None}), b"\x0B\x00\x00\x00\x0A\x74\x65\x73\x74\x00\x00")
450468
self.assertEqual(
451469
encode({"date": datetime.datetime(2007, 1, 8, 0, 30, 11)}),

0 commit comments

Comments
 (0)