diff options
author | Sergey Fedoseev <fedoseev.sergey@gmail.com> | 2018-07-08 07:09:20 (GMT) |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2018-07-08 07:09:20 (GMT) |
commit | 0830858aeedecc9ece60349f8c31c2690d1a99f8 (patch) | |
tree | 8cd32ec3cb898edd3631df2378662aa13e8b761a /Lib/sqlite3 | |
parent | 8d41278045ee4e8bf1cadb58a7db58d70ad55237 (diff) | |
download | cpython-0830858aeedecc9ece60349f8c31c2690d1a99f8.zip cpython-0830858aeedecc9ece60349f8c31c2690d1a99f8.tar.gz cpython-0830858aeedecc9ece60349f8c31c2690d1a99f8.tar.bz2 |
bpo-34041: Allow creating deterministic functions in Connection.create_function() (GH-8086)
Diffstat (limited to 'Lib/sqlite3')
-rw-r--r-- | Lib/sqlite3/test/userfunctions.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/sqlite3/test/userfunctions.py b/Lib/sqlite3/test/userfunctions.py index 4075045..9501f53 100644 --- a/Lib/sqlite3/test/userfunctions.py +++ b/Lib/sqlite3/test/userfunctions.py @@ -23,6 +23,7 @@ # 3. This notice may not be removed or altered from any source distribution. import unittest +import unittest.mock import sqlite3 as sqlite def func_returntext(): @@ -275,6 +276,28 @@ class FunctionTests(unittest.TestCase): val = cur.fetchone()[0] self.assertEqual(val, 2) + 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") + 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) + + @unittest.skipIf(sqlite.sqlite_version_info >= (3, 8, 3), "SQLite < 3.8.3 needed") + def CheckFuncDeterministicNotSupported(self): + with self.assertRaises(sqlite.NotSupportedError): + self.con.create_function("deterministic", 0, int, deterministic=True) + + def CheckFuncDeterministicKeywordOnly(self): + with self.assertRaises(TypeError): + self.con.create_function("deterministic", 0, int, True) + class AggregateTests(unittest.TestCase): def setUp(self): |