changeset: 104090:1aae9b7ff321 branch: 2.7 parent: 104056:94a26aa1b1e0 user: Serhiy Storchaka date: Tue Sep 27 00:27:15 2016 +0300 files: Lib/sqlite3/test/hooks.py description: Issue #27897: Backported tests. diff -r 94a26aa1b1e0 -r 1aae9b7ff321 Lib/sqlite3/test/hooks.py --- a/Lib/sqlite3/test/hooks.py Sun Sep 25 16:44:32 2016 +0300 +++ b/Lib/sqlite3/test/hooks.py Tue Sep 27 00:27:15 2016 +0300 @@ -31,6 +31,11 @@ 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 @@ 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