8000 gh-69093: Add mapping protocol support to sqlite3.Blob by erlend-aasland · Pull Request #91599 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-69093: Add mapping protocol support to sqlite3.Blob #91599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Prev Previous commit
Next Next commit
Address review: verify writes
  • Loading branch information
Erlend E. Aasland committed Apr 19, 2022
commit 7df4b9d394de8febbe3c5056baee4eccd623900a
21 changes: 16 additions & 5 deletions Lib/test/test_sqlite3/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,9 +1141,9 @@ def test_blob_write_error_length(self):
self.blob.seek(0, SEEK_SET)
n = len(self.blob)
self.blob.write(b"a" * (n-1))
self.blob.write(b"a" * 1)
self.blob.write(b"a")
with self.assertRaisesRegex(ValueError, "data longer than blob"):
self.blob.write(b"a" * 1)
self.blob.write(b"a")

def test_blob_write_error_row_changed(self):
self.cx.execute("update test set b='aaaa' where rowid=1")
Expand Down Expand Up @@ -1197,11 +1197,22 @@ def test_blob_set_item_with_offset(self):
def test_blob_set_buffer_object(self):
from array import array
self.blob[0] = memoryview(b"1")
self.blob[0] = bytearray(b"1")
self.blob[0] = array("b", [1])
self.assertEqual(self.blob[0], b"1")

self.blob[1] = bytearray(b"2")
self.assertEqual(self.blob[1], b"2")

self.blob[2] = array("b", [4])
self.assertEqual(self.blob[2], b"\x04")

self.blob[0:5] = memoryview(b"12345")
self.blob[0:5] = bytearray(b"12345")
self.assertEqual(self.blob[0:5], b"12345")

self.blob[0:5] = bytearray(b"23456")
self.assertEqual(self.blob[0:5], b"23456")

self.blob[0:5] = array("b", [1, 2, 3, 4, 5])
self.assertEqual(self.blob[0:5], b"\x01\x02\x03\x04\x05")

def test_blob_set_item_negative_index(self):
self.blob[-1] = b"z"
Expand Down
0