1
- from xmlrpc.client import Binary
2
-
3
1
# Testing Binary subtype 9: Vector
4
2
5
3
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.
70
68
71
69
#### 1. Encoding
72
70
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.
74
74
75
75
``` python
76
76
with pytest.raises(ValueError ):
@@ -79,20 +79,17 @@ with pytest.raises(ValueError):
79
79
80
80
### 2. Decoding
81
81
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
84
82
- Test the behaviour of your driver when one attempts to decode from binary to vector.
85
83
- e.g. As of pymongo 4.14, a warning is raised. From 5.0, it will be an exception.
86
84
87
85
``` 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 )
92
87
with pytest.warns():
93
- Binary.as_vector(found )
88
+ Binary.as_vector(b )
94
89
```
95
90
91
+ Drivers MAY skip this test if they choose not to implement a ` Vector ` type.
92
+
96
93
### 3. Comparison
97
94
98
95
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
116
113
assert v2 != v1 # Also chosen to be unequal at BinaryVector level as [255] != [128]
117
114
```
118
115
116
+ Drivers MAY skip this test if they choose not to implement a ` Vector ` type.
117
+
119
118
## FAQ
120
119
121
120
- What MongoDB Server version does this apply to?
0 commit comments