home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2790 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  6.5 KB  |  170 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import os
  5. import unittest
  6. import sqlite3 as sqlite
  7.  
  8. class CollationTests(unittest.TestCase):
  9.     
  10.     def setUp(self):
  11.         pass
  12.  
  13.     
  14.     def tearDown(self):
  15.         pass
  16.  
  17.     
  18.     def CheckCreateCollationNotCallable(self):
  19.         con = sqlite.connect(':memory:')
  20.         
  21.         try:
  22.             con.create_collation('X', 42)
  23.             self.fail('should have raised a TypeError')
  24.         except TypeError:
  25.             e = None
  26.             self.failUnlessEqual(e.args[0], 'parameter must be callable')
  27.  
  28.  
  29.     
  30.     def CheckCreateCollationNotAscii(self):
  31.         con = sqlite.connect(':memory:')
  32.         
  33.         try:
  34.             con.create_collation('coll\xe4', cmp)
  35.             self.fail('should have raised a ProgrammingError')
  36.         except sqlite.ProgrammingError:
  37.             e = None
  38.  
  39.  
  40.     
  41.     def CheckCollationIsUsed(self):
  42.         if sqlite.version_info < (3, 2, 1):
  43.             return None
  44.         
  45.         def mycoll(x, y):
  46.             return -cmp(x, y)
  47.  
  48.         con = sqlite.connect(':memory:')
  49.         con.create_collation('mycoll', mycoll)
  50.         sql = "\n            select x from (\n            select 'a' as x\n            union\n            select 'b' as x\n            union\n            select 'c' as x\n            ) order by x collate mycoll\n            "
  51.         result = con.execute(sql).fetchall()
  52.         if result[0][0] != 'c' and result[1][0] != 'b' or result[2][0] != 'a':
  53.             self.fail('the expected order was not returned')
  54.         
  55.         con.create_collation('mycoll', None)
  56.         
  57.         try:
  58.             result = con.execute(sql).fetchall()
  59.             self.fail('should have raised an OperationalError')
  60.         except sqlite.OperationalError:
  61.             e = None
  62.             self.failUnlessEqual(e.args[0].lower(), 'no such collation sequence: mycoll')
  63.  
  64.  
  65.     
  66.     def CheckCollationRegisterTwice(self):
  67.         con = sqlite.connect(':memory:')
  68.         con.create_collation('mycoll', cmp)
  69.         con.create_collation('mycoll', (lambda x, y: -cmp(x, y)))
  70.         result = con.execute("\n            select x from (select 'a' as x union select 'b' as x) order by x collate mycoll\n            ").fetchall()
  71.         if result[0][0] != 'b' or result[1][0] != 'a':
  72.             self.fail('wrong collation function is used')
  73.         
  74.  
  75.     
  76.     def CheckDeregisterCollation(self):
  77.         con = sqlite.connect(':memory:')
  78.         con.create_collation('mycoll', cmp)
  79.         con.create_collation('mycoll', None)
  80.         
  81.         try:
  82.             con.execute("select 'a' as x union select 'b' as x order by x collate mycoll")
  83.             self.fail('should have raised an OperationalError')
  84.         except sqlite.OperationalError:
  85.             e = None
  86.             if not e.args[0].startswith('no such collation sequence'):
  87.                 self.fail('wrong OperationalError raised')
  88.             
  89.         except:
  90.             e.args[0].startswith('no such collation sequence')
  91.  
  92.  
  93.  
  94.  
  95. class ProgressTests(unittest.TestCase):
  96.     
  97.     def CheckProgressHandlerUsed(self):
  98.         con = sqlite.connect(':memory:')
  99.         progress_calls = []
  100.         
  101.         def progress():
  102.             progress_calls.append(None)
  103.             return 0
  104.  
  105.         con.set_progress_handler(progress, 1)
  106.         con.execute('\n            create table foo(a, b)\n            ')
  107.         self.failUnless(progress_calls)
  108.  
  109.     
  110.     def CheckOpcodeCount(self):
  111.         con = sqlite.connect(':memory:')
  112.         progress_calls = []
  113.         
  114.         def progress():
  115.             progress_calls.append(None)
  116.             return 0
  117.  
  118.         con.set_progress_handler(progress, 1)
  119.         curs = con.cursor()
  120.         curs.execute('\n            create table foo (a, b)\n            ')
  121.         first_count = len(progress_calls)
  122.         progress_calls = []
  123.         con.set_progress_handler(progress, 2)
  124.         curs.execute('\n            create table bar (a, b)\n            ')
  125.         second_count = len(progress_calls)
  126.         self.failUnless(first_count > second_count)
  127.  
  128.     
  129.     def CheckCancelOperation(self):
  130.         con = sqlite.connect(':memory:')
  131.         progress_calls = []
  132.         
  133.         def progress():
  134.             progress_calls.append(None)
  135.             return 1
  136.  
  137.         con.set_progress_handler(progress, 1)
  138.         curs = con.cursor()
  139.         self.assertRaises(sqlite.OperationalError, curs.execute, 'create table bar (a, b)')
  140.  
  141.     
  142.     def CheckClearHandler(self):
  143.         con = sqlite.connect(':memory:')
  144.         action = 0
  145.         
  146.         def progress():
  147.             action = 1
  148.             return 0
  149.  
  150.         con.set_progress_handler(progress, 1)
  151.         con.set_progress_handler(None, 1)
  152.         con.execute('select 1 union select 2 union select 3').fetchall()
  153.         self.failUnlessEqual(action, 0, 'progress handler was not cleared')
  154.  
  155.  
  156.  
  157. def suite():
  158.     collation_suite = unittest.makeSuite(CollationTests, 'Check')
  159.     progress_suite = unittest.makeSuite(ProgressTests, 'Check')
  160.     return unittest.TestSuite((collation_suite, progress_suite))
  161.  
  162.  
  163. def test():
  164.     runner = unittest.TextTestRunner()
  165.     runner.run(suite())
  166.  
  167. if __name__ == '__main__':
  168.     test()
  169.  
  170.