8000 bpo-40784: Fix sqlite3 deterministic test (GH-20448) · python/cpython@c610d97 · GitHub
[go: up one dir, main page]

Skip to content

Commit c610d97

Browse files
author
Erlend Egeberg Aasland
authored
bpo-40784: Fix sqlite3 deterministic test (GH-20448)
1 parent dc4eee9 commit c610d97

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

Lib/sqlite3/test/userfunctions.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
#-*- coding: iso-8859-1 -*-
21
# pysqlite2/test/userfunctions.py: tests for user-defined functions and
32
# aggregates.
43
#
5-
# Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de>
4+
# Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de>
65
#
76
# This file is part of pysqlite.
87
#
@@ -158,6 +157,7 @@ def setUp(self):
158157
self.con.create_function("isblob", 1, func_isblob)
159158
self.con.create_function("islonglong", 1, func_islonglong)
160159
self.con.create_function("spam", -1, func)
160+
self.con.execute("create table test(t text)")
161161

162162
def tearDown(self):
163163
self.con.close()
@@ -276,18 +276,36 @@ def CheckAnyArguments(self):
276276
val = cur.fetchone()[0]
277277
self.assertEqual(val, 2)
278278

279+
# Regarding deterministic functions:
280+
#
281+
# Between 3.8.3 and 3.15.0, deterministic functions were only used to
282+
# optimize inner loops, so for those versions we can only test if the
283+
# sqlite machinery has factored out a call or not. From 3.15.0 and onward,
284+
# deterministic functions were permitted in WHERE clauses of partial
285+
# indices, which allows testing based on syntax, iso. the query optimizer.
286+
@unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), "Requires SQLite 3.8.3 or higher")
279287
def CheckFuncNonDeterministic(self):
280288
mock = unittest.mock.Mock(return_value=None)
281-
self.con.create_function("deterministic", 0, mock, deterministic=False)
282-
self.con.execute("select deterministic() = deterministic()")
283-
self.assertEqual(mock.call_count, 2)
284-
285-
@unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), "deterministic parameter not supported")
289+
self.con.create_function("nondeterministic", 0, mock, deterministic=False)
290+
if sqlite.sqlite_version_info < (3, 15, 0):
291+
self.con.execute("select nondeterministic() = nondeterministic()")
292+
self.assertEqual(mock.call_count, 2)
293+
else:
294+
with self.assertRaises(sqlite.OperationalError):
295+
self.con.execute("create index t on test(t) where nondeterministic() is not null")
296+
297+
@unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), "Requires SQLite 3.8.3 or higher")
286298
def CheckFuncDeterministic(self):
287299
mock = unittest.mock.Mock(return_value=None)
288300
self.con.create_function("deterministic", 0, mock, deterministic=True)
289-
self.con.execute("select deterministic() = deterministic()")
290-
self.assertEqual(mock.call_count, 1)
301+
if sqlite.sqlite_version_info < (3, 15, 0):
302+
self.con.execute("select deterministic() = deterministic()")
303+
self.assertEqual(mock.call_count, 1)
304+
else:
305+
try:
306+
self.con.execute("create index t on test(t) where deterministic() is not null")
307+
except sqlite.OperationalError:
308+
self.fail("Unexpected failure while creating partial index")
291309

292310
@unittest.skipIf(sqlite.sqlite_version_info >= (3, 8, 3), "SQLite < 3.8.3 needed")
293311
def CheckFuncDeterministicNotSupported(self):

0 commit comments

Comments
 (0)
0