@@ -620,6 +620,62 @@ def CheckBlobOpenWithBadRow(self):
620
620
with self .assertRaises (sqlite .OperationalError ):
621
621
self .cx .open_blob ("test" , "blob_col" , 2 )
622
622
623
+ def CheckBlobGetItem (self ):
624
+ self .assertEqual (self .blob [5 ], b"a" )
625
+
626
+ def CheckBlobGetItemIndexOutOfRange (self ):
627
+ with self .assertRaises (IndexError ):
628
+ self .blob [105 ]
629
+ with self .assertRaises (IndexError ):
630
+ self .blob [- 105 ]
631
+
632
+ def CheckBlobGetItemNegativeIndex (self ):
633
+ self .assertEqual (self .blob [- 5 ], b"a" )
634
+
635
+ def CheckBlobGetItemInvalidIndex (self ):
636
+ with self .assertRaises (TypeError ):
637
+ self .blob [b"a" ]
638
+
639
+ def CheckBlobGetSlice (self ):
640
+ self .assertEqual (self .blob [5 :10 ], b"aaaaa" )
641
+
642
+ def CheckBlobGetSliceNegativeIndex (self ):
643
+ self .assertEqual (self .blob [5 :- 5 ], self .blob_data [5 :- 5 ])
644
+
645
+ def CheckBlobGetSliceInvalidIndex (self ):
646
+ with self .assertRaises (TypeError ):
647
+ self .blob [5 :b"a" ]
648
+
649
+ def CheckBlobGetSliceWithSkip (self ):
650
+ self .blob .write (b"abcdefghij" )
651
+ self .assertEqual (self .blob [0 :10 :2 ], b"acegi" )
652
+
653
+ def CheckBlobSetItem (self ):
654
+ self .blob [0 ] = b"b"
655
+ self .assertEqual (self .cx .execute ("select blob_col from test" ).fetchone ()[0 ], b"b" + self .blob_data [1 :])
656
+
657
+ def CheckBlobSetSlice (self ):
658
+ self .blob [0 :5 ] = b"bbbbb"
659
+ self .assertEqual (self .cx .execute ("select blob_col from test" ).fetchone ()[0 ], b"bbbbb" + self .blob_data [5 :])
660
+
661
+ def CheckBlobSetSliceWithSkip (self ):
662
+ self .blob [0 :10 :2 ] = b"bbbbb"
663
+ self .assertEqual (self .cx .execute ("select blob_col from test" ).fetchone ()[0 ], b"bababababa" + self .blob_data [10 :])
664
+
665
+ def CheckBlobGetEmptySlice (self ):
666
+ self .assertEqual (self .blob [5 :5 ], b"" )
667
+
668
+ def CheckBlobSetSliceWrongLength (self ):
669
+ with self .assertRaises (IndexError ):
670
+ self .blob [5 :10 ] = b"a"
671
+
672
+ def CheckBlobConcatNotSupported (self ):
673
+ with self .assertRaises (SystemError ):
674
+ self .blob + self .blob
675
+
676
+ def CheckBlobRepeateNotSupported (self ):
677
+ with self .assertRaises (SystemError ):
678
+ self .blob * 5
623
679
624
680
@unittest .skipUnless (threading , 'This test requires threading.' )
625
681
class ThreadTests (unittest .TestCase ):
0 commit comments