Skip to content
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

bpo-40784: Fix sqlite3 deterministic test #20448

Merged
merged 8 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
20 changes: 14 additions & 6 deletions Lib/sqlite3/test/userfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def setUp(self):
self.con.create_function("isblob", 1, func_isblob)
self.con.create_function("islonglong", 1, func_islonglong)
self.con.create_function("spam", -1, func)
self.con.execute("create table test(t text)")

def tearDown(self):
self.con.close()
Expand Down Expand Up @@ -276,18 +277,25 @@ def CheckAnyArguments(self):
val = cur.fetchone()[0]
self.assertEqual(val, 2)

@unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), "Requires SQLite 3.8.3 or higher")
def CheckFuncNonDeterministic(self):
"""Non-deterministic functions cannot be used with partial indices"""
mock = unittest.mock.Mock(return_value=None)
self.con.create_function("deterministic", 0, mock, deterministic=False)
self.con.execute("select deterministic() = deterministic()")
self.assertEqual(mock.call_count, 2)
self.con.create_function("nondeterministic", 0, mock, deterministic=False)
with self.assertRaises(sqlite.OperationalError) as cm:
self.con.execute("create index t on test(t) where nondeterministic() is not null")
# non-deterministic functions prohibited in partial index WHERE clauses
self.assertIn("non-deterministic functions prohibited", str(cm.exception))

@unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), "deterministic parameter not supported")
@unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), "Requires SQLite 3.8.3 or higher")
def CheckFuncDeterministic(self):
"""Deterministic functions can be used with partial indices"""
mock = unittest.mock.Mock(return_value=None)
self.con.create_function("deterministic", 0, mock, deterministic=True)
self.con.execute("select deterministic() = deterministic()")
self.assertEqual(mock.call_count, 1)
try:
self.con.execute("create index t on test(t) where deterministic() is not null")
except sqlite.OperationalError:
self.fail("Unexpected failure while creating partial index")

@unittest.skipIf(sqlite.sqlite_version_info >= (3, 8, 3), "SQLite < 3.8.3 needed")
def CheckFuncDeterministicNotSupported(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :mod:`sqlite3` unit test for deterministic functions.
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved