From c8120092ddf9df6d9feb925876f8f807e36234a0 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 27 Sep 2016 00:27:15 +0300 Subject: Issue #27897: Backported tests. --- Lib/sqlite3/test/hooks.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Lib/sqlite3/test/hooks.py b/Lib/sqlite3/test/hooks.py index 16f217d..a5b1632 100644 --- a/Lib/sqlite3/test/hooks.py +++ b/Lib/sqlite3/test/hooks.py @@ -31,6 +31,11 @@ class CollationTests(unittest.TestCase): def tearDown(self): pass + def CheckCreateCollationNotString(self): + con = sqlite.connect(":memory:") + with self.assertRaises(TypeError): + con.create_collation(None, lambda x, y: (x > y) - (x < y)) + def CheckCreateCollationNotCallable(self): con = sqlite.connect(":memory:") try: @@ -47,6 +52,23 @@ class CollationTests(unittest.TestCase): except sqlite.ProgrammingError, e: pass + def CheckCreateCollationBadUpper(self): + class BadUpperStr(str): + def upper(self): + return None + con = sqlite.connect(":memory:") + mycoll = lambda x, y: -((x > y) - (x < y)) + con.create_collation(BadUpperStr("mycoll"), mycoll) + result = con.execute(""" + select x from ( + select 'a' as x + union + select 'b' as x + ) order by x collate mycoll + """).fetchall() + self.assertEqual(result[0][0], 'b') + self.assertEqual(result[1][0], 'a') + def CheckCollationIsUsed(self): if sqlite.version_info < (3, 2, 1): # old SQLite versions crash on this test return -- cgit v0.12