]> granicus.if.org Git - python/commitdiff
Issue #27897: Backported tests.
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 26 Sep 2016 21:27:15 +0000 (00:27 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 26 Sep 2016 21:27:15 +0000 (00:27 +0300)
Lib/sqlite3/test/hooks.py

index 16f217d8fc0d728ed4ea58b009a36db38aae8cd5..a5b1632a1815d897cc63f4876c9089ddf689849a 100644 (file)
@@ -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