8000 bpo-24905: Support BLOB incremental I/O in sqlite module by palaviv · Pull Request #271 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-24905: Support BLOB incremental I/O in sqlite module #271

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

Closed
wants to merge 18 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use assertRaises in tests
  • Loading branch information
palaviv committed Jul 29, 2020
commit 865c1c84be443770f489138dd718f9087a080ac4
119 changes: 17 additions & 102 deletions Lib/sqlite3/test/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,22 +546,12 @@ def CheckSeekFromBlobEnd(self):
self.assertEqual(self.blob.tell(), 90)

def CheckBlobSeekOverBlobSize(self):
try:
with self.assertRaises(ValueError):
self.blob.seek(1000)
self.fail("should have raised a ValueError")
except ValueError:
pass
except Exception:
self.fail("should have raised a ValueError")

def CheckBlobSeekUnderBlobSize(self):
try:
with self.assertRaises(ValueError):
self.blob.seek(-10)
self.fail("should have raised a ValueError")
except ValueError:
pass
except Exception:
self.fail("should have raised a ValueError")

def CheckBlobRead(self):
self.assertEqual(self.blob.read(), self.blob_data)
Expand Down Expand Up @@ -594,81 +584,41 @@ def CheckBlobWriteAdvanceOffset(self):
self.assertEqual(self.blob.tell(), 50)

def CheckBlobWriteMoreThenBlobSize(self):
try:
with self.assertRaises(sqlite.OperationalError):
self.blob.write(b"a" * 1000)
self.fail("should have raised a sqlite.OperationalError")
except sqlite.OperationalError:
pass
except Exception:
self.fail("should have raised a sqlite.OperationalError")

def CheckBlobReadAfterRowChange(self):
self.cx.execute("UPDATE test SET blob_col='aaaa' where id=1")
try:
with self.assertRaises(sqlite.OperationalError):
self.blob.read()
self.fail("should have raised a sqlite.OperationalError")
except sqlite.OperationalError:
pass
except Exception:
self.fail("should have raised a sqlite.OperationalError")

def CheckBlobWriteAfterRowChange(self):
self.cx.execute("UPDATE test SET blob_col='aaaa' where id=1")
try:
with self.assertRaises(sqlite.OperationalError):
self.blob.write(b"aaa")
self.fail("should have raised a sqlite.OperationalError")
except sqlite.OperationalError:
pass
except Exception:
self.fail("should have raised a sqlite.OperationalError")

def CheckBlobWriteWhenReadOnly(self):
read_only_blob = \
self.cx.open_blob("test", "blob_col", 1, readonly=True)
try:
with self.assertRaises(sqlite.OperationalError):
read_only_blob.write(b"aaa")
self.fail("should have raised a sqlite.OperationalError")
except sqlite.OperationalError:
pass
except Exception:
self.fail("should have raised a sqlite.OperationalError")
read_only_blob.close()

def CheckBlobOpenWithBadDb(self):
try:
with self.assertRaises(sqlite.OperationalError):
self.cx.open_blob("test", "blob_col", 1, dbname="notexisintg")
self.fail("should have raised a sqlite.OperationalError")
except sqlite.OperationalError:
pass
except Exception:
self.fail("should have raised a sqlite.OperationalError")

def CheckBlobOpenWithBadTable(self):
try:
with self.assertRaises(sqlite.OperationalError):
self.cx.open_blob("notexisintg", "blob_col", 1)
self.fail("should have raised a sqlite.OperationalError")
except sqlite.OperationalError:
pass
except Exception:
self.fail("should have raised a sqlite.OperationalError")

def CheckBlobOpenWithBadColumn(self):
try:
with self.assertRaises(sqlite.OperationalError):
self.cx.open_blob("test", "notexisting", 1)
self.fail("should have raised a sqlite.OperationalError")
except sqlite.OperationalError:
pass
except Exception:
self.fail("should have raised a sqlite.OperationalError")

def CheckBlobOpenWithBadRow(self):
try:
with self.assertRaises(sqlite.OperationalError):
self.cx.open_blob("test", "blob_col", 2)
self.fail("should have raised a sqlite.OperationalError")
except sqlite.OperationalError:
pass
except Exception:
self.fail("should have raised a sqlite.OperationalError")


@unittest.skipUnless(threading, 'This test requires threading.')
Expand Down Expand Up @@ -935,13 +885,8 @@ def CheckClosedBlobRead(self):
con.execute("insert into test(blob_col) values (zeroblob(100))")
blob = con.open_blob("test", "blob_col", 1)
con.close()
try:
with self.assertRaises(sqlite.ProgrammingError):
blob.read()
self.fail("Should have raised a ProgrammingError")
except sqlite.ProgrammingError:
pass
except:
self.fail("Should have raised a ProgrammingError")

def CheckClosedCreateFunction(self):
con = sqlite.connect(":memory:")
Expand Down Expand Up @@ -1109,57 +1054,32 @@ def tearDown(self):
def CheckClosedRead(self):
self.blob = self.cx.open_blob("test", "blob_col", 1)
self.blob.close()
try:
with self.assertRaises(sqlite.ProgrammingError):
self.blob.read()
self.fail("Should have raised a ProgrammingError")
except sqlite.ProgrammingError:
pass
except Exception:
self.fail("Should have raised a ProgrammingError")

def CheckClosedWrite(self):
self.blob = self.cx.open_blob("test", "blob_col", 1)
self.blob.close()
try:
with self.assertRaises(sqlite.ProgrammingError):
self.blob.write(b"aaaaaaaaa")
self.fail("Should have raised a ProgrammingError")
except sqlite.ProgrammingError:
pass
except Exception:
self.fail("Should have raised a ProgrammingError")

def CheckClosedSeek(self):
self.blob = self.cx.open_blob("test", "blob_col", 1)
self.blob.close()
try:
with self.assertRaises(sqlite.ProgrammingError):
self.blob.seek(10)
self.fail("Should have raised a ProgrammingError")
except sqlite.ProgrammingError:
pass
except Exception:
self.fail("Should have raised a ProgrammingError")

def CheckClosedTell(self):
self.blob = self.cx.open_blob("test", "blob_col", 1)
self.blob.close()
try:
with self.assertRaises(sqlite.ProgrammingError):
self.blob.tell()
self.fail("Should have raised a ProgrammingError")
e 9615 xcept sqlite.ProgrammingError:
pass
except Exception:
self.fail("Should have raised a ProgrammingError")

def CheckClosedClose(self):
self.blob = self.cx.open_blob("test", "blob_col", 1)
self.blob.close()
try:
with self.assertRaises(sqlite.ProgrammingError):
self.blob.close()
self.fail("Should have raised a ProgrammingError")
except sqlite.ProgrammingError:
pass
except Exception:
self.fail("Should have raised a ProgrammingError")


class BlobContextManagerTests(unittest.TestCase):
Expand All @@ -1180,13 +1100,8 @@ def CheckContextExecute(self):
def CheckContextCloseBlob(self):
with self.cx.open_blob("test", "blob_col", 1) as blob:
blob.seek(10)
try:
with self.assertRaises(sqlite.ProgrammingError):
blob.close()
self.fail("Should have raised a ProgrammingError")
except sqlite.ProgrammingError:
pass
except Exception:
self.fail("Should have raised a ProgrammingError")


def suite():
Expand Down
0