|
62 | 62 | from bson.son import SON
|
63 | 63 | from bson.timestamp import Timestamp
|
64 | 64 | from bson.tz_util import FixedOffset, utc
|
| 65 | +from bson.vector import DTYPES, BinaryVector |
65 | 66 |
|
66 | 67 |
|
67 | 68 | class NotADict(abc.MutableMapping):
|
@@ -147,6 +148,11 @@ def helper(doc):
|
147 | 148 | helper({"a binary": Binary(b"test", 128)})
|
148 | 149 | helper({"a binary": Binary(b"test", 254)})
|
149 | 150 | 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)}) |
150 | 156 | helper(SON([("test dst", datetime.datetime(1993, 4, 4, 2))]))
|
151 | 157 | helper(SON([("test negative dst", datetime.datetime(1, 1, 1, 1, 1, 1))]))
|
152 | 158 | helper({"big float": float(10000000000)})
|
@@ -446,6 +452,18 @@ def test_basic_encode(self):
|
446 | 452 | encode({"test": Binary(b"test", 128)}),
|
447 | 453 | b"\x14\x00\x00\x00\x05\x74\x65\x73\x74\x00\x04\x00\x00\x00\x80\x74\x65\x73\x74\x00",
|
448 | 454 | )
|
| 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 | + ) |
449 | 467 | self.assertEqual(encode({"test": None}), b"\x0B\x00\x00\x00\x0A\x74\x65\x73\x74\x00\x00")
|
450 | 468 | self.assertEqual(
|
451 | 469 | encode({"date": datetime.datetime(2007, 1, 8, 0, 30, 11)}),
|
|
0 commit comments