home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_2936 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  5.8 KB  |  153 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import datetime
  5. import unittest
  6. import sqlite3 as sqlite
  7.  
  8. class RegressionTests(unittest.TestCase):
  9.     
  10.     def setUp(self):
  11.         self.con = sqlite.connect(':memory:')
  12.  
  13.     
  14.     def tearDown(self):
  15.         self.con.close()
  16.  
  17.     
  18.     def CheckPragmaUserVersion(self):
  19.         cur = self.con.cursor()
  20.         cur.execute('pragma user_version')
  21.  
  22.     
  23.     def CheckPragmaSchemaVersion(self):
  24.         con = sqlite.connect(':memory:', detect_types = sqlite.PARSE_COLNAMES)
  25.         
  26.         try:
  27.             cur = self.con.cursor()
  28.             cur.execute('pragma schema_version')
  29.         finally:
  30.             cur.close()
  31.             con.close()
  32.  
  33.  
  34.     
  35.     def CheckStatementReset(self):
  36.         con = sqlite.connect(':memory:', cached_statements = 5)
  37.         cursors = [ con.cursor() for x in xrange(5) ]
  38.         cursors[0].execute('create table test(x)')
  39.         for i in range(10):
  40.             []([], [ (x,) for x in xrange(10) ])
  41.         
  42.         for i in range(5):
  43.             cursors[i].execute(' ' * i + 'select x from test')
  44.         
  45.         con.rollback()
  46.  
  47.     
  48.     def CheckColumnNameWithSpaces(self):
  49.         cur = self.con.cursor()
  50.         cur.execute('select 1 as "foo bar [datetime]"')
  51.         self.failUnlessEqual(cur.description[0][0], 'foo bar')
  52.         cur.execute('select 1 as "foo baz"')
  53.         self.failUnlessEqual(cur.description[0][0], 'foo baz')
  54.  
  55.     
  56.     def CheckStatementAvailable(self):
  57.         con = sqlite.connect(':memory:', detect_types = sqlite.PARSE_DECLTYPES)
  58.         cur = con.cursor()
  59.         cur.execute('select 4 union select 5')
  60.         cur.close()
  61.         cur.fetchone()
  62.         cur.fetchone()
  63.  
  64.     
  65.     def CheckStatementFinalizationOnCloseDb(self):
  66.         con = sqlite.connect(':memory:')
  67.         cursors = []
  68.         for i in range(105):
  69.             cur = con.cursor()
  70.             cursors.append(cur)
  71.             cur.execute('select 1 x union select ' + str(i))
  72.         
  73.         con.close()
  74.  
  75.     
  76.     def CheckOnConflictRollback(self):
  77.         if sqlite.sqlite_version_info < (3, 2, 2):
  78.             return None
  79.         con = sqlite.connect(':memory:')
  80.         con.execute('create table foo(x, unique(x) on conflict rollback)')
  81.         con.execute('insert into foo(x) values (1)')
  82.         
  83.         try:
  84.             con.execute('insert into foo(x) values (1)')
  85.         except sqlite.DatabaseError:
  86.             sqlite.sqlite_version_info < (3, 2, 2)
  87.             sqlite.sqlite_version_info < (3, 2, 2)
  88.         except:
  89.             sqlite.sqlite_version_info < (3, 2, 2)
  90.  
  91.         con.execute('insert into foo(x) values (2)')
  92.         
  93.         try:
  94.             con.commit()
  95.         except sqlite.OperationalError:
  96.             sqlite.sqlite_version_info < (3, 2, 2)
  97.             sqlite.sqlite_version_info < (3, 2, 2)
  98.             self.fail('pysqlite knew nothing about the implicit ROLLBACK')
  99.         except:
  100.             sqlite.sqlite_version_info < (3, 2, 2)
  101.  
  102.  
  103.     
  104.     def CheckWorkaroundForBuggySqliteTransferBindings(self):
  105.         self.con.execute('create table foo(bar)')
  106.         self.con.execute('drop table foo')
  107.         self.con.execute('create table foo(bar)')
  108.  
  109.     
  110.     def CheckEmptyStatement(self):
  111.         self.con.execute('')
  112.  
  113.     
  114.     def CheckUnicodeConnect(self):
  115.         con = sqlite.connect(u':memory:')
  116.         con.close()
  117.  
  118.     
  119.     def CheckTypeMapUsage(self):
  120.         SELECT = 'select * from foo'
  121.         con = sqlite.connect(':memory:', detect_types = sqlite.PARSE_DECLTYPES)
  122.         con.execute('create table foo(bar timestamp)')
  123.         con.execute('insert into foo(bar) values (?)', (datetime.datetime.now(),))
  124.         con.execute(SELECT)
  125.         con.execute('drop table foo')
  126.         con.execute('create table foo(bar integer)')
  127.         con.execute('insert into foo(bar) values (5)')
  128.         con.execute(SELECT)
  129.  
  130.     
  131.     def CheckRegisterAdapter(self):
  132.         self.assertRaises(TypeError, sqlite.register_adapter, { }, None)
  133.  
  134.     
  135.     def CheckSetIsolationLevel(self):
  136.         con = sqlite.connect(':memory:')
  137.         self.assertRaises(UnicodeEncodeError, setattr, con, 'isolation_level', u'├⌐')
  138.  
  139.  
  140.  
  141. def suite():
  142.     regression_suite = unittest.makeSuite(RegressionTests, 'Check')
  143.     return unittest.TestSuite((regression_suite,))
  144.  
  145.  
  146. def test():
  147.     runner = unittest.TextTestRunner()
  148.     runner.run(suite())
  149.  
  150. if __name__ == '__main__':
  151.     test()
  152.  
  153.