diff options
author | Sergey Fedoseev <fedoseev.sergey@gmail.com> | 2018-07-08 12:09:20 +0500 |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2018-07-08 10:09:20 +0300 |
commit | 0830858aeedecc9ece60349f8c31c2690d1a99f8 (patch) | |
tree | 8cd32ec3cb898edd3631df2378662aa13e8b761a /Lib | |
parent | bpo-33888: Use CPython instead of Python in the FAQ (GH-7767) (diff) | |
download | cpython-0830858aeedecc9ece60349f8c31c2690d1a99f8.tar.gz cpython-0830858aeedecc9ece60349f8c31c2690d1a99f8.tar.bz2 cpython-0830858aeedecc9ece60349f8c31c2690d1a99f8.zip |
bpo-34041: Allow creating deterministic functions in Connection.create_function() (GH-8086)
Diffstat (limited to 'Lib')
-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 4075045b727..9501f535c49 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): |