Blame SOURCES/00350-sqlite-fix-deterministic-test.patch

1a5cfa
commit 00a240bf7f95bbd220f1cfbf9eb58484a5f9681a
1a5cfa
Author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
1a5cfa
Date:   Fri May 29 05:46:34 2020 -0700
1a5cfa
1a5cfa
    bpo-40784: Fix sqlite3 deterministic test (GH-20448)
1a5cfa
    
1a5cfa
    (cherry picked from commit c610d970f5373b143bf5f5900d4645e6a90fb460)
1a5cfa
    
1a5cfa
    Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
1a5cfa
1a5cfa
diff --git a/Lib/sqlite3/test/userfunctions.py b/Lib/sqlite3/test/userfunctions.py
1a5cfa
index 9501f53..c11c82e 100644
1a5cfa
--- a/Lib/sqlite3/test/userfunctions.py
1a5cfa
+++ b/Lib/sqlite3/test/userfunctions.py
1a5cfa
@@ -1,8 +1,7 @@
1a5cfa
-#-*- coding: iso-8859-1 -*-
1a5cfa
 # pysqlite2/test/userfunctions.py: tests for user-defined functions and
1a5cfa
 #                                  aggregates.
1a5cfa
 #
1a5cfa
-# Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de>
1a5cfa
+# Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de>
1a5cfa
 #
1a5cfa
 # This file is part of pysqlite.
1a5cfa
 #
1a5cfa
@@ -158,6 +157,7 @@ class FunctionTests(unittest.TestCase):
1a5cfa
         self.con.create_function("isblob", 1, func_isblob)
1a5cfa
         self.con.create_function("islonglong", 1, func_islonglong)
1a5cfa
         self.con.create_function("spam", -1, func)
1a5cfa
+        self.con.execute("create table test(t text)")
1a5cfa
 
1a5cfa
     def tearDown(self):
1a5cfa
         self.con.close()
1a5cfa
@@ -276,18 +276,36 @@ class FunctionTests(unittest.TestCase):
1a5cfa
         val = cur.fetchone()[0]
1a5cfa
         self.assertEqual(val, 2)
1a5cfa
 
1a5cfa
+    # Regarding deterministic functions:
1a5cfa
+    #
1a5cfa
+    # Between 3.8.3 and 3.15.0, deterministic functions were only used to
1a5cfa
+    # optimize inner loops, so for those versions we can only test if the
1a5cfa
+    # sqlite machinery has factored out a call or not. From 3.15.0 and onward,
1a5cfa
+    # deterministic functions were permitted in WHERE clauses of partial
1a5cfa
+    # indices, which allows testing based on syntax, iso. the query optimizer.
1a5cfa
+    @unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), "Requires SQLite 3.8.3 or higher")
1a5cfa
     def CheckFuncNonDeterministic(self):
1a5cfa
         mock = unittest.mock.Mock(return_value=None)
1a5cfa
-        self.con.create_function("deterministic", 0, mock, deterministic=False)
1a5cfa
-        self.con.execute("select deterministic() = deterministic()")
1a5cfa
-        self.assertEqual(mock.call_count, 2)
1a5cfa
-
1a5cfa
-    @unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), "deterministic parameter not supported")
1a5cfa
+        self.con.create_function("nondeterministic", 0, mock, deterministic=False)
1a5cfa
+        if sqlite.sqlite_version_info < (3, 15, 0):
1a5cfa
+            self.con.execute("select nondeterministic() = nondeterministic()")
1a5cfa
+            self.assertEqual(mock.call_count, 2)
1a5cfa
+        else:
1a5cfa
+            with self.assertRaises(sqlite.OperationalError):
1a5cfa
+                self.con.execute("create index t on test(t) where nondeterministic() is not null")
1a5cfa
+
1a5cfa
+    @unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), "Requires SQLite 3.8.3 or higher")
1a5cfa
     def CheckFuncDeterministic(self):
1a5cfa
         mock = unittest.mock.Mock(return_value=None)
1a5cfa
         self.con.create_function("deterministic", 0, mock, deterministic=True)
1a5cfa
-        self.con.execute("select deterministic() = deterministic()")
1a5cfa
-        self.assertEqual(mock.call_count, 1)
1a5cfa
+        if sqlite.sqlite_version_info < (3, 15, 0):
1a5cfa
+            self.con.execute("select deterministic() = deterministic()")
1a5cfa
+            self.assertEqual(mock.call_count, 1)
1a5cfa
+        else:
1a5cfa
+            try:
1a5cfa
+                self.con.execute("create index t on test(t) where deterministic() is not null")
1a5cfa
+            except sqlite.OperationalError:
1a5cfa
+                self.fail("Unexpected failure while creating partial index")
1a5cfa
 
1a5cfa
     @unittest.skipIf(sqlite.sqlite_version_info >= (3, 8, 3), "SQLite < 3.8.3 needed")
1a5cfa
     def CheckFuncDeterministicNotSupported(self):