Skip to content

Commit d8db3e1

Browse files
committed
Additional updates based on comments, primarily in prose tests.
1 parent 8d01080 commit d8db3e1

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

source/bson-binary-vector/bson-binary-vector.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ End Function
180180

181181
#### Validation
182182

183-
Drivers MUST validate vector metadata and raise an error if any invariant is violated:
183+
Drivers MUST validate vector metadata and raise an exception if any invariant is violated:
184184

185185
- When unpacking binary data into a FLOAT32 Vector structure, the length of the binary data following the dtype and
186186
padding MUST be a multiple of 4 bytes.
@@ -189,8 +189,8 @@ Drivers MUST validate vector metadata and raise an error if any invariant is vio
189189
- For a PACKED_BIT vector with non-zero padding, ignored bits SHOULD be zero.
190190
- When encoding, if ignored bits aren't zero, drivers SHOULD raise an exception, but drivers MAY leave them as-is if
191191
backwards-compatibility is a concern.
192-
- When decoding, drivers SHOULD raise an error if decoding non-zero ignored bits, but drivers MAY choose not to for
193-
backwards compatibility.
192+
- When decoding, drivers SHOULD raise an exception if decoding non-zero ignored bits, but drivers MAY choose not to
193+
for backwards compatibility.
194194
- Drivers SHOULD use the next major release to conform to ignored bits being zero.
195195

196196
Drivers MUST perform this validation when a numeric vector and padding are provided through the API, and when unpacking

source/bson-binary-vector/tests/README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from xmlrpc.client import Binary
2-
31
# Testing Binary subtype 9: Vector
42

53
The JSON files in this directory tree are platform-independent tests that drivers can use to prove their conformance to
@@ -70,7 +68,9 @@ as all of its bits are ones.
7068

7169
#### 1. Encoding
7270

73-
- Test that an exception is raised when one attempts to encode a vector with non-zero ignored bits.
71+
- Test encoding with non-zero ignored bits. Use the driver API that validates vector metadata.
72+
- If the driver validates ignored bits are zero (preferred), expect an error. Otherwise expect the ignored bits are
73+
preserved.
7474

7575
```python
7676
with pytest.raises(ValueError):
@@ -79,20 +79,17 @@ with pytest.raises(ValueError):
7979

8080
### 2. Decoding
8181

82-
- Test that one can manually create a BSON Binary object following the vector structure (dtype + padding + data).
83-
- Test that this can be inserted and found
8482
- Test the behaviour of your driver when one attempts to decode from binary to vector.
8583
- e.g. As of pymongo 4.14, a warning is raised. From 5.0, it will be an exception.
8684

8785
```python
88-
v = Binary(b'\x10\x07\xff', subtype=9)
89-
clxn.insert_one({"v": v})
90-
found = clxn.find_one({"v": v})["v"]
91-
assert isinstance(found, Binary)
86+
b = Binary(b'\x10\x07\xff', subtype=9)
9287
with pytest.warns():
93-
Binary.as_vector(found)
88+
Binary.as_vector(b)
9489
```
9590

91+
Drivers MAY skip this test if they choose not to implement a `Vector` type.
92+
9693
### 3. Comparison
9794

9895
Once we can guarantee that all ignored bits are non-zero, then equality can be tested on the binary subtype. Until then,
@@ -116,6 +113,8 @@ assert b1 != b2 # Unequal at naive Binary level
116113
assert v2 !=v1 # Also chosen to be unequal at BinaryVector level as [255] != [128]
117114
```
118115

116+
Drivers MAY skip this test if they choose not to implement a `Vector` type.
117+
119118
## FAQ
120119

121120
- What MongoDB Server version does this apply to?

0 commit comments

Comments
 (0)