2525import sqlite3 as sqlite
2626
2727class CollationTests (unittest .TestCase ):
28+ def CheckCreateCollationNotString (self ):
29+ con = sqlite .connect (":memory:" )
30+ with self .assertRaises (TypeError ):
31+ con .create_collation (None , lambda x , y : (x > y ) - (x < y ))
32+
2833 def CheckCreateCollationNotCallable (self ):
2934 con = sqlite .connect (":memory:" )
3035 with self .assertRaises (TypeError ) as cm :
@@ -36,6 +41,23 @@ def CheckCreateCollationNotAscii(self):
3641 with self .assertRaises (sqlite .ProgrammingError ):
3742 con .create_collation ("collä" , lambda x , y : (x > y ) - (x < y ))
3843
44+ def CheckCreateCollationBadUpper (self ):
45+ class BadUpperStr (str ):
46+ def upper (self ):
47+ return None
48+ con = sqlite .connect (":memory:" )
49+ mycoll = lambda x , y : - ((x > y ) - (x < y ))
50+ con .create_collation (BadUpperStr ("mycoll" ), mycoll )
51+ result = con .execute ("""
52+ select x from (
53+ select 'a' as x
54+ union
55+ select 'b' as x
56+ ) order by x collate mycoll
57+ """ ).fetchall ()
58+ self .assertEqual (result [0 ][0 ], 'b' )
59+ self .assertEqual (result [1 ][0 ], 'a' )
60+
3961 @unittest .skipIf (sqlite .sqlite_version_info < (3 , 2 , 1 ),
4062 'old SQLite versions crash on this test' )
4163 def CheckCollationIsUsed (self ):
0 commit comments