8000 bpo-43853: Expand test suite for SQLite UDF's by erlend-aasland · Pull Request #27642 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-43853: Expand test suite for SQLite UDF's #27642

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
merged 16 commits into from
Jan 26, 2022
Merged
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
Address review: add more tests
  • Loading branch information
Erlend E. Aasland committed Aug 8, 2021
commit 3ed9af66ae74f0085b95e50874574f9225c14e71
23 changes: 18 additions & 5 deletions Lib/sqlite3/test/userfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,14 @@ def setUp(self):
self.con.create_function("returnnull", 0, func_returnnull)
self.con.create_function("returnblob", 0, func_returnblob)
self.con.create_function("returnlonglong", 0, func_returnlonglong)
self.con.create_function("returnnan", 0, lambda: float("nan"))
self.con.create_function("returntoolargeint", 0, lambda: 1 << 65)
self.con.create_function("raiseexception", 0, func_raiseexception)
self.con.create_function("memoryerror", 0, func_memoryerror)
self.con.create_function("overflowerror", 0, func_overflowerror)

self.con.create_function("isblob", 1,
lambda x: isinstance(x, (bytes, memoryview)))
self.con.create_function("isblob", 1, lambda x: isinstance(x, bytes))
self.con.create_function("isnone", 1, lambda x: x is None)
self.con.create_function("spam", -1, lambda *x: len(x))
self.con.create_function("boomerang", 1, lambda x: x)
self.con.execute("create table test(t text)")
Expand Down Expand Up @@ -262,6 +264,16 @@ def test_func_return_long_long(self):
val = cur.fetchone()[0]
self.assertEqual(val, 1<<31)

def test_func_return_nan(self):
cur = self.con.cursor()
cur.execute("select returnnan()")
self.assertIsNone(cur.fetchone()[0])

def test_func_return_too_large_int(self):
cur = self.con.cursor()
self.assertRaisesRegex(sqlite.DataError, "string or blob too big",
self.con.execute, "select returntoolargeint()")

@with_tracebacks(['func_raiseexception', '5/0', 'ZeroDivisionError'])
def test_func_exception(self):
cur = self.con.cursor()
Expand Down Expand Up @@ -295,14 +307,14 @@ def test_empty_blob(self):
self.assertTrue(cur.fetchone()[0])

def test_nan_float(self):
cur = self.con.execute("select boomerang(?)", (float('nan'),))
cur = self.con.execute("select isnone(?)", (float("nan"),))
# SQLite has no concept of nan; it is converted to NULL
self.assertIsNone(cur.fetchone()[0])
self.assertTrue(cur.fetchone()[0])

def test_too_large_int(self):
err = "Python int too large to convert to SQLite INTEGER"
self.assertRaisesRegex(OverflowError, err, self.con.execute,
"select boomerang(?)", (1 << 65,))
"select spam(?)", (1 << 65,))

def test_non_contiguous_blob(self):
err = "could not convert BLOB to buffer"
Expand All @@ -321,6 +333,7 @@ def test_func_params(self):
("1\x002", str),
(b"blob", bytes),
(bytearray(range(2)), bytes),
(memoryview(b"blob"), bytes),
(None, type(None)),
)
for val, tp in dataset:
Expand Down
0