@@ -739,7 +739,7 @@ def test_vector(self):
739
739
"""Tests of subtype 9"""
740
740
# We start with valid cases, across the 3 dtypes implemented.
741
741
# Work with a simple vector that can be interpreted as int8, float32, or ubyte
742
- list_vector = [127 , 7 ]
742
+ list_vector = [127 , 8 ]
743
743
# As INT8, vector has length 2
744
744
binary_vector = Binary .from_vector (list_vector , BinaryVectorDtype .INT8 )
745
745
vector = binary_vector .as_vector ()
@@ -764,18 +764,18 @@ def test_vector(self):
764
764
uncompressed = ""
765
765
for val in list_vector :
766
766
uncompressed += format (val , "08b" )
767
- assert uncompressed [:- padding ] == "0111111100000 "
767
+ assert uncompressed [:- padding ] == "0111111100001 "
768
768
769
769
# It is worthwhile explicitly showing the values encoded to BSON
770
770
padded_doc = {"padded_vec" : padded_vec }
771
771
assert (
772
772
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 "
774
774
)
775
775
# and dumped to json
776
776
assert (
777
777
json_util .dumps (padded_doc )
778
- == '{"padded_vec": {"$binary": {"base64": "EAN/Bw ==", "subType": "09"}}}'
778
+ == '{"padded_vec": {"$binary": {"base64": "EAN/CA ==", "subType": "09"}}}'
779
779
)
780
780
781
781
# FLOAT32 is also implemented
@@ -784,15 +784,19 @@ def test_vector(self):
784
784
785
785
# Now some invalid cases
786
786
for x in [- 1 , 257 ]:
787
- try :
787
+ with self . assertRaises ( struct . error ) :
788
788
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." )
793
789
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 )
795
793
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)
796
800
assert padded_vec == Binary .from_vector (
797
801
BinaryVector (list_vector , BinaryVectorDtype .PACKED_BIT , padding )
798
802
)
0 commit comments