|
| 1 | +From 00a240bf7f95bbd220f1cfbf9eb58484a5f9681a Mon Sep 17 00:00:00 2001 |
| 2 | +From: "Miss Islington (bot)" |
| 3 | + <31488909+miss-islington@users.noreply.github.com> |
| 4 | +Date: Fri, 29 May 2020 05:46:34 -0700 |
| 5 | +Subject: [PATCH] bpo-40784: Fix sqlite3 deterministic test (GH-20448) |
| 6 | + |
| 7 | +(cherry picked from commit c610d970f5373b143bf5f5900d4645e6a90fb460) |
| 8 | + |
| 9 | +Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no> |
| 10 | +--- |
| 11 | + Lib/sqlite3/test/userfunctions.py | 36 +++++++++++++++++++++++-------- |
| 12 | + 1 file changed, 27 insertions(+), 9 deletions(-) |
| 13 | + |
| 14 | +diff --git a/Lib/sqlite3/test/userfunctions.py b/Lib/sqlite3/test/userfunctions.py |
| 15 | +index 9501f535c4999..c11c82e127577 100644 |
| 16 | +--- a/Lib/sqlite3/test/userfunctions.py |
| 17 | ++++ b/Lib/sqlite3/test/userfunctions.py |
| 18 | +@@ -1,8 +1,7 @@ |
| 19 | +-#-*- coding: iso-8859-1 -*- |
| 20 | + # pysqlite2/test/userfunctions.py: tests for user-defined functions and |
| 21 | + # aggregates. |
| 22 | + # |
| 23 | +-# Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de> |
| 24 | ++# Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de> |
| 25 | + # |
| 26 | + # This file is part of pysqlite. |
| 27 | + # |
| 28 | +@@ -158,6 +157,7 @@ def setUp(self): |
| 29 | + self.con.create_function("isblob", 1, func_isblob) |
| 30 | + self.con.create_function("islonglong", 1, func_islonglong) |
| 31 | + self.con.create_function("spam", -1, func) |
| 32 | ++ self.con.execute("create table test(t text)") |
| 33 | + |
| 34 | + def tearDown(self): |
| 35 | + self.con.close() |
| 36 | +@@ -276,18 +276,36 @@ def CheckAnyArguments(self): |
| 37 | + val = cur.fetchone()[0] |
| 38 | + self.assertEqual(val, 2) |
| 39 | + |
| 40 | ++ # Regarding deterministic functions: |
| 41 | ++ # |
| 42 | ++ # Between 3.8.3 and 3.15.0, deterministic functions were only used to |
| 43 | ++ # optimize inner loops, so for those versions we can only test if the |
| 44 | ++ # sqlite machinery has factored out a call or not. From 3.15.0 and onward, |
| 45 | ++ # deterministic functions were permitted in WHERE clauses of partial |
| 46 | ++ # indices, which allows testing based on syntax, iso. the query optimizer. |
| 47 | ++ @unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), "Requires SQLite 3.8.3 or higher") |
| 48 | + def CheckFuncNonDeterministic(self): |
| 49 | + mock = unittest.mock.Mock(return_value=None) |
| 50 | +- self.con.create_function("deterministic", 0, mock, deterministic=False) |
| 51 | +- self.con.execute("select deterministic() = deterministic()") |
| 52 | +- self.assertEqual(mock.call_count, 2) |
| 53 | +- |
| 54 | +- @unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), "deterministic parameter not supported") |
| 55 | ++ self.con.create_function("nondeterministic", 0, mock, deterministic=False) |
| 56 | ++ if sqlite.sqlite_version_info < (3, 15, 0): |
| 57 | ++ self.con.execute("select nondeterministic() = nondeterministic()") |
| 58 | ++ self.assertEqual(mock.call_count, 2) |
| 59 | ++ else: |
| 60 | ++ with self.assertRaises(sqlite.OperationalError): |
| 61 | ++ self.con.execute("create index t on test(t) where nondeterministic() is not null") |
| 62 | ++ |
| 63 | ++ @unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), "Requires SQLite 3.8.3 or higher") |
| 64 | + def CheckFuncDeterministic(self): |
| 65 | + mock = unittest.mock.Mock(return_value=None) |
| 66 | + self.con.create_function("deterministic", 0, mock, deterministic=True) |
| 67 | +- self.con.execute("select deterministic() = deterministic()") |
| 68 | +- self.assertEqual(mock.call_count, 1) |
| 69 | ++ if sqlite.sqlite_version_info < (3, 15, 0): |
| 70 | ++ self.con.execute("select deterministic() = deterministic()") |
| 71 | ++ self.assertEqual(mock.call_count, 1) |
| 72 | ++ else: |
| 73 | ++ try: |
| 74 | ++ self.con.execute("create index t on test(t) where deterministic() is not null") |
| 75 | ++ except sqlite.OperationalError: |
| 76 | ++ self.fail("Unexpected failure while creating partial index") |
| 77 | + |
| 78 | + @unittest.skipIf(sqlite.sqlite_version_info >= (3, 8, 3), "SQLite < 3.8.3 needed") |
| 79 | + def CheckFuncDeterministicNotSupported(self): |
0 commit comments