-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-40784: Fix sqlite3 deterministic test #20448
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
40542ba
Fix sqlite3 deterministic test
f7f9ef1
Update Lib/sqlite3/test/userfunctions.py
4664279
Revert non-ascii change in header
b969ae5
Use old test for sqlite < 3.15.0
96d52a8
Remove NEWS entry
f570658
Update userfunctions.py
berkerpeksag 44fa9e4
Convert userfunctions.py to UTF-8
ad7206e
Update userfunctions.py
berkerpeksag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
#-*- coding: iso-8859-1 -*- | ||
# pysqlite2/test/userfunctions.py: tests for user-defined functions and | ||
# aggregates. | ||
# | ||
# Copyright (C) 2005-2007 Gerhard H�ring <[email protected]> | ||
# Copyright (C) 2005-2007 Gerhard Häring <[email protected]> | ||
erlend-aasland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# | ||
# This file is part of pysqlite. | ||
# | ||
|
@@ -158,6 +157,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() | ||
|
@@ -276,18 +276,36 @@ def CheckAnyArguments(self): | |
val = cur.fetchone()[0] | ||
self.assertEqual(val, 2) | ||
|
||
# Regarding deterministic functions: | ||
# | ||
# Between 3.8.3 and 3.15.0, deterministic functions were only used to | ||
# optimize inner loops, so for those versions we can only test if the | ||
# sqlite machinery has factored out a call or not. From 3.15.0 and onward, | ||
# deterministic functions were permitted in WHERE clauses of partial | ||
# indices, which allows testing based on syntax, iso. the query optimizer. | ||
@unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), "Requires SQLite 3.8.3 or higher") | ||
def CheckFuncNonDeterministic(self): | ||
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) | ||
|
||
@unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), "deterministic parameter not supported") | ||
self.con.create_function("nondeterministic", 0, mock, deterministic=False) | ||
if sqlite.sqlite_version_info < (3, 15, 0): | ||
self.con.execute("select nondeterministic() = nondeterministic()") | ||
self.assertEqual(mock.call_count, 2) | ||
else: | ||
with self.assertRaises(sqlite.OperationalError): | ||
self.con.execute("create index t on test(t) where nondeterministic() is not null") | ||
|
||
@unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), "Requires SQLite 3.8.3 or higher") | ||
def CheckFuncDeterministic(self): | ||
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) | ||
if sqlite.sqlite_version_info < (3, 15, 0): | ||
self.con.execute("select deterministic() = deterministic()") | ||
self.assertEqual(mock.call_count, 1) | ||
else: | ||
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): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.