@@ -739,7 +739,7 @@ def test_vector(self):
739739 """Tests of subtype 9"""
740740 # We start with valid cases, across the 3 dtypes implemented.
741741 # Work with a simple vector that can be interpreted as int8, float32, or ubyte
742- list_vector = [127 , 7 ]
742+ list_vector = [127 , 8 ]
743743 # As INT8, vector has length 2
744744 binary_vector = Binary .from_vector (list_vector , BinaryVectorDtype .INT8 )
745745 vector = binary_vector .as_vector ()
@@ -764,18 +764,18 @@ def test_vector(self):
764764 uncompressed = ""
765765 for val in list_vector :
766766 uncompressed += format (val , "08b" )
767- assert uncompressed [:- padding ] == "0111111100000 "
767+ assert uncompressed [:- padding ] == "0111111100001 "
768768
769769 # It is worthwhile explicitly showing the values encoded to BSON
770770 padded_doc = {"padded_vec" : padded_vec }
771771 assert (
772772 encode (padded_doc )
773- == b"\x1a \x00 \x00 \x00 \x05 padded_vec\x00 \x04 \x00 \x00 \x00 \t \x10 \x03 \x7f \x07 \x00 "
773+ == b"\x1a \x00 \x00 \x00 \x05 padded_vec\x00 \x04 \x00 \x00 \x00 \t \x10 \x03 \x7f \x08 \x00 "
774774 )
775775 # and dumped to json
776776 assert (
777777 json_util .dumps (padded_doc )
778- == '{"padded_vec": {"$binary": {"base64": "EAN/Bw ==", "subType": "09"}}}'
778+ == '{"padded_vec": {"$binary": {"base64": "EAN/CA ==", "subType": "09"}}}'
779779 )
780780
781781 # FLOAT32 is also implemented
@@ -784,15 +784,19 @@ def test_vector(self):
784784
785785 # Now some invalid cases
786786 for x in [- 1 , 257 ]:
787- try :
787+ with self . assertRaises ( struct . error ) :
788788 Binary .from_vector ([x ], BinaryVectorDtype .PACKED_BIT )
789- except Exception as exc :
790- self .assertIsInstance (exc , struct .error )
791- else :
792- self .fail ("Failed to raise an exception." )
793789
794- # Test form of Binary.from_vector(BinaryVector)
790+ # Test one must pass zeros for all ignored bits
791+ with self .assertRaises (ValueError ):
792+ Binary .from_vector ([255 ], BinaryVectorDtype .PACKED_BIT , padding = 7 )
795793
794+ with self .assertWarns (DeprecationWarning ):
795+ meta = struct .pack ("<sB" , BinaryVectorDtype .PACKED_BIT .value , 7 )
796+ data = struct .pack ("1B" , 255 )
797+ Binary (meta + data , subtype = 9 ).as_vector ()
798+
799+ # Test form of Binary.from_vector(BinaryVector)
796800 assert padded_vec == Binary .from_vector (
797801 BinaryVector (list_vector , BinaryVectorDtype .PACKED_BIT , padding )
798802 )
0 commit comments