@@ -48,11 +48,11 @@ def create_test(case_spec):
4848 def run_test (self ):
4949 for test_case in case_spec .get ("tests" , []):
5050 description = test_case ["description" ]
51- vector_exp = test_case .get ("vector" , [] )
51+ vector_exp = test_case .get ("vector" , None )
5252 dtype_hex_exp = test_case ["dtype_hex" ]
5353 dtype_alias_exp = test_case .get ("dtype_alias" )
5454 padding_exp = test_case .get ("padding" , 0 )
55- canonical_bson_exp = test_case .get ("canonical_bson" )
55+ canonical_bson_exp = test_case .get ("canonical_bson" , None )
5656 # Convert dtype hex string into bytes
5757 dtype_exp = BinaryVectorDtype (int (dtype_hex_exp , 16 ).to_bytes (1 , byteorder = "little" ))
5858
@@ -85,14 +85,25 @@ def run_test(self):
8585 self .assertEqual (cB_obs , canonical_bson_exp , description )
8686
8787 else :
88- with self .assertRaises ((struct .error , ValueError ), msg = description ):
89- # Tests Binary.from_vector
90- Binary .from_vector (vector_exp , dtype_exp , padding_exp )
91- # Tests Binary.as_vector
92- cB_exp = binascii .unhexlify (canonical_bson_exp .encode ("utf8" ))
93- decoded_doc = decode (cB_exp )
94- binary_obs = decoded_doc [test_key ]
95- binary_obs .as_vector ()
88+ """
89+ #### To prove correct in an invalid case (`valid:false`), one MUST
90+ - if the vector field is present, raise an exception when attempting to encode a document from the numeric values,
91+ dtype, and padding.
92+ - if the canonical_bson field is present, raise an exception when attempting to deserialize it into the corresponding
93+ numeric values, as the field contains corrupted data.
94+ """
95+ # Tests Binary.from_vector()
96+ if vector_exp is not None :
97+ with self .assertRaises ((struct .error , ValueError ), msg = description ):
98+ Binary .from_vector (vector_exp , dtype_exp , padding_exp )
99+
100+ # Tests Binary.as_vector()
101+ if canonical_bson_exp is not None :
102+ with self .assertRaises ((struct .error , ValueError ), msg = description ):
103+ cB_exp = binascii .unhexlify (canonical_bson_exp .encode ("utf8" ))
104+ decoded_doc = decode (cB_exp )
105+ binary_obs = decoded_doc [test_key ]
106+ binary_obs .as_vector ()
96107
97108 return run_test
98109
0 commit comments