Contact: fumanchu@aminus.org

Log in as guest/geniusql to create tickets

Changeset 14

Show
Ignore:
Timestamp:
02/16/07 23:26:39
Author:
fumanchu
Message:

Added isolation tests. Database kwargs now set child attributes if the key includes a dot.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/geniusql/conns.py

    r13 r14  
    148148class ConnectionManager(object): 
    149149     
     150    poolsize = 10 
    150151    implicit_trans = False 
    151152     
     
    161162                        "REPEATABLE READ", "SERIALIZABLE"] 
    162163     
    163     def __init__(self, db, poolsize=10): 
     164    def __init__(self, db): 
    164165        self.transactions = {} 
    165166        self.db = db 
    166         self.poolsize = poolsize 
    167167        self._set_factory() 
    168168     
  • trunk/geniusql/objects.py

    r13 r14  
    729729     
    730730    def __init__(self, **kwargs): 
     731        self.connections = self.connectionmanager(self) 
     732         
     733        children = [] 
    731734        for k, v in kwargs.iteritems(): 
    732             setattr(self, k, v) 
    733          
    734         poolsize = kwargs.get('poolsize', 10) 
    735         self.connections = self.connectionmanager(self, poolsize) 
     735            if "." in k: 
     736                # Defer subkeys in case the child is replaced wholesale 
     737                children.append((k, v)) 
     738            else: 
     739                setattr(self, k, v) 
     740         
     741        for k, v in children: 
     742            namespace, name = k.split(".", 1) 
     743            childobj = getattr(self, namespace) 
     744            setattr(childobj, name, v) 
    736745     
    737746    def version(self): 
  • trunk/geniusql/providers/ado.py

    r13 r14  
    618618    adapterfromdb = AdapterFromADO() 
    619619     
    620     def __init__(self, **kwargs): 
    621         geniusql.Database.__init__(self, **kwargs) 
    622         self.connections.Connect = self.Connect 
    623      
    624620    def python_type(self, dbtype): 
    625621        """Return a Python type which can store values of the given dbtype.""" 
     
    10761072    isolation_levels = ["READ UNCOMMITTED",] 
    10771073     
    1078     def __init__(self, db, poolsize=0): 
     1074    def __init__(self, db): 
    10791075        self.transactions = {} 
    10801076        self.db = db 
    1081         self.poolsize = 0 
    10821077        # MS Access can't use a pool, because there doesn't seem 
    10831078        # to be a commit timeout. See http://support.microsoft.com/kb/200300 
     
    11941189        # By not providing an Engine Type, it defaults to 5 = Access 2000. 
    11951190        cat = win32com.client.Dispatch(r'ADOX.Catalog') 
    1196         cat.Create(self.db.Connect) 
     1191        cat.Create(self.db.connections.Connect) 
    11971192        cat.ActiveConnection.Close() 
    11981193        self.clear() 
  • trunk/geniusql/providers/postgres.py

    r13 r14  
    330330    def __init__(self, **kwargs): 
    331331        geniusql.Database.__init__(self, **kwargs) 
    332         self.connections.Connect = self.Connect 
    333332     
    334333    def python_type(self, dbtype): 
  • trunk/geniusql/providers/sqlite.py

    r13 r14  
    5151    # If you are using type adapters that support a "standard" 
    5252    # date/datetime format for SQLite, set the following flag to True 
    53     using_perfect_dates = False 
     53    perfect_dates = False 
    5454     
    5555    def coerce_bool_to_any(self, value): 
     
    7878     
    7979    def visit_COMPARE_OP(self, lo, hi): 
    80         if self.adapter.using_perfect_dates: 
     80        if self.adapter.perfect_dates: 
    8181            op2, op1 = self.stack.pop(), self.stack.pop() 
    8282             
     
    182182     
    183183    def dejavu_now(self): 
    184         if self.adapter.using_perfect_dates and _cast_support: 
     184        if self.adapter.perfect_dates and _cast_support: 
    185185            return "julianday('now')" 
    186186        else: 
     
    191191     
    192192    def dejavu_year(self, x): 
    193         if self.adapter.using_perfect_dates and _cast_support: 
     193        if self.adapter.perfect_dates and _cast_support: 
    194194            return "CAST(strftime('%Y', " + x + ") AS NUMERIC)" 
    195195        else: 
     
    198198     
    199199    def dejavu_month(self, x): 
    200         if self.adapter.using_perfect_dates and _cast_support: 
     200        if self.adapter.perfect_dates and _cast_support: 
    201201            return "CAST(strftime('%m', " + x + ") AS NUMERIC)" 
    202202        else: 
     
    205205     
    206206    def dejavu_day(self, x): 
    207         if self.adapter.using_perfect_dates and _cast_support: 
     207        if self.adapter.perfect_dates and _cast_support: 
    208208            return "CAST(strftime('%d', " + x + ") AS NUMERIC)" 
    209209        else: 
     
    479479    isolation_levels = ["SERIALIZABLE"] 
    480480     
    481     def __init__(self, db, poolsize=10): 
     481    def __init__(self, db): 
    482482        self.transactions = {} 
    483483        self.db = db 
    484         self.poolsize = poolsize 
    485484        # Can't set up the factory until we have a schema. 
    486485     
     
    765764        geniusql.Database.__init__(self, **kwargs) 
    766765     
    767     def _get_upd(self): 
    768         return self.adaptertosql.using_perfect_dates 
    769     def _set_upd(self, value): 
    770         self.adaptertosql.using_perfect_dates = value 
    771     using_perfect_dates = property(_get_upd, _set_upd) 
    772      
    773766    def isrelatedtype(self, pytype1, pytype2): 
    774         if (self.using_perfect_dates and 
     767        if (self.adaptertosql.perfect_dates and 
    775768            issubclass(pytype1, (datetime.date, datetime.time, datetime.datetime)) and 
    776769            issubclass(pytype2, self.python_type(self.typeadapter.coerce(None, pytype1)))): 
  • trunk/geniusql/test/test_msaccess.py

    r13 r14  
    3030             
    3131        DB_class = "access" 
    32         opts = {'Connect': "PROVIDER=MICROSOFT.JET.OLEDB.4.0;" 
    33                            "DATA SOURCE=zoo.mdb;", 
     32        opts = {'connections.Connect': 
     33                    "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=zoo.mdb;", 
    3434                } 
    3535         
     
    5555                        obj.assertEqual(len(standard_runs), 0) 
    5656             
    57             # Isolate schema changes from one test to the next. 
    58             reload(zoo_fixture) 
    59              
    6057            # test the standard MS Access setup where Decimal and FixedPoint 
    6158            # objects are stored in the database as INTEGERS, LONGS or NUMERIC 
     59            reload(zoo_fixture) 
    6260            print 
    6361            print "Standard MSAccess test." 
     
    6664            standard_runs.append(True) 
    6765             
    68             # plugin the adapter for testing CURRENCY columns 
    69             ado.MSAccessDatabase.typeadapter = CurrencyAdapter() 
    70              
    71             reload(zoo_fixture) 
    72              
    7366            # test storing and recalling Decimal values to the database using 
    7467            # CURRENCY columns - the (current) default behavior of pythoncom 
    7568            # is to return CURRENCY values as a tuple 
     69            reload(zoo_fixture) 
    7670            print 
    7771            print "MSAccess test - CURRENCY returned as tuple." 
    7872##            zoo_fixture.ZooTests.test_currency = test_currency 
     73            # plugin the adapter for testing CURRENCY columns 
     74            opts['typeadapter'] = CurrencyAdapter() 
    7975            zoo_fixture.run(DB_class, "zoo.mdb", opts) 
     76            del opts['typeadapter'] 
    8077            altered_runs.append(True) 
    81              
    82             # set pythoncom to return CURRENCY values as Decimal objects 
    83             pythoncom.__future_currency__ = True 
    84              
    85             reload(zoo_fixture) 
    8678             
    8779            # test storing and recalling Decimal values to the database using 
    8880            # CURRENCY columns - CURRENCY values are now returned as Decimal 
    89             # objects 
     81            # objects. 
     82            # set pythoncom to return CURRENCY values as Decimal objects 
     83            pythoncom.__future_currency__ = True 
     84            reload(zoo_fixture) 
    9085            print 
    9186            print "MSAccess test - CURRENCY returned as Decimal." 
  • trunk/geniusql/test/test_psycopg.py

    r13 r14  
    1919        passwd = raw_input("Enter the password for the PostgreSQL '%s' user:" % user) 
    2020     
    21     opts = {'Connect': ("host=localhost dbname=geniusql_test " 
    22                         "user=%s password=%s" % (user, passwd)), 
     21    opts = {'connections.Connect': 
     22                ("host=localhost dbname=geniusql_test user=%s password=%s" 
     23                 % (user, passwd)), 
    2324            } 
    2425    DB_class = "psycopg" 
  • trunk/geniusql/test/test_pypgsql.py

    r13 r14  
    1414        passwd = raw_input("Enter the password for the PostgreSQL '%s' user:" % user) 
    1515     
    16     opts = {'Connect': ("host=localhost dbname=geniusql_test " 
    17                          "user=%s password=%s" % (user, passwd)), 
     16    opts = {'connections.Connect': 
     17                ("host=localhost dbname=geniusql_test user=%s password=%s" 
     18                 % (user, passwd)), 
    1819            } 
    1920    DB_class = "postgres" 
  • trunk/geniusql/test/test_sqlite.py

    r13 r14  
    2222if _sqlite: 
    2323    DB_class = "sqlite" 
    24     opts = {"Database": dbpath
     24    opts = {
    2525     
    2626    def run(): 
     
    2828        # Isolate schema changes from one test to the next. 
    2929        reload(zoo_fixture) 
    30         zoo_fixture.run(DB_class, opts['Database'], opts) 
     30        zoo_fixture.run(DB_class, dbpath, opts) 
    3131         
    3232        print 
    3333        print "Testing SQLite with 'Perfect Dates'" 
    34         opts['Perfect Dates'] = True 
     34        opts['adaptertosql.perfect_dates'] = True 
    3535        reload(zoo_fixture) 
    36         zoo_fixture.run(DB_class, opts['Database'], opts) 
    37         opts['Perfect Dates'] = False 
     36        zoo_fixture.run(DB_class, dbpath, opts) 
     37        opts['adaptertosql.perfect_dates'] = False 
    3838         
    3939        print 
    4040        print "Testing SQLite ':memory:' database..." 
    41         opts['Database'] = ':memory:' 
    4241        reload(zoo_fixture) 
    43         zoo_fixture.run(DB_class, opts['Database'], opts) 
     42        zoo_fixture.run(DB_class, ':memory:', opts) 
    4443         
    4544        print 
    4645        print "Testing SQLite 'typeless'..." 
    47         opts['Database'] = dbpath 
    48         opts['Type Adapter'] = "geniusql.providers.sqlite.TypeAdapterSQLiteTypeless" 
     46        from geniusql.providers import sqlite 
     47        opts['typeadapter'] = sqlite.TypeAdapterSQLiteTypeless() 
    4948        reload(zoo_fixture) 
    50         zoo_fixture.run(DB_class, opts['Database'], opts) 
     49        zoo_fixture.run(DB_class, dbpath, opts) 
    5150 
    5251if __name__ == "__main__": 
  • trunk/geniusql/test/test_sqlserver.py

    r13 r14  
    66    def run(): 
    77        warnings.warn("The pythoncom module could not be imported. " 
    8                       "The MSAccess test will not be run.") 
     8                      "The SQL Server test will not be run.") 
    99else: 
    1010    from geniusql.providers import ado 
     
    1616                          "The SQLServer test will not be run.") 
    1717    else: 
    18         opts = {'Connect': ("Provider=SQLOLEDB.1; Integrated Security=SSPI; " 
    19                             "Initial Catalog=geniusql_test; " 
    20                             "Data Source=(local)"), 
     18        opts = {'connections.Connect': 
     19                    ("Provider=SQLOLEDB.1; Integrated Security=SSPI; " 
     20                     "Initial Catalog=geniusql_test; Data Source=(local)"), 
    2121                # Shorten the transaction deadlock timeout. 
    2222                # You may need to adjust this for your system. 
    23                 'CommandTimeout': 10
     23                'connections.CommandTimeout': 1
    2424                } 
    2525        DB_class = "sqlserver" 
  • trunk/geniusql/test/zoo_fixture.py

    r13 r14  
    681681        except AttributeError: 
    682682            self.old_implicit = None 
    683          
    684683     
    685684    def tearDown(self): 
     
    690689    def restore(self): 
    691690        self.boxid = 0 
    692         box = arena.new_sandbox() 
    693         box.start() 
    694         jim = box.unit(Vet, Name = 'Jim McBain') 
    695         jim.City = None 
    696         box.flush_all() 
     691         
     692        db.connections.start() 
     693        jim = schema['Vet'].select_one(Name = 'Jim McBain') 
     694        schema['Vet'].save(ID = jim['ID'], City = None) 
     695        db.connections.commit() 
    697696     
    698697    def cleanup_boxes(self): 
    699698        try: 
    700699            self.boxid = 1 
    701             self.box1.rollback() 
     700            db.connections.rollback() 
    702701        except: pass 
    703702        try: 
    704703            self.boxid = 2 
    705             self.box2.rollback() 
     704            db.connections.rollback() 
    706705        except: pass 
    707          
    708         # Destroy refs so the conns can go back in the pool. 
    709         del self.box1, self.box2 
    710706     
    711707    def attempt(self, testfunc, anomaly_name, level): 
     708        print ".", 
    712709        self.restore() 
    713710         
    714711        self.boxid = 1 
    715         self.box1 = arena.new_sandbox() 
    716         self.box1.start(level) 
     712        db.connections.start(level) 
    717713         
    718714        self.boxid = 2 
    719         self.box2 = arena.new_sandbox() 
    720         self.box2.start(level) 
     715        db.connections.start(level) 
    721716         
    722717        try: 
     
    754749            # Write City 1 
    755750            self.boxid = 1 
    756             jim1 = self.box1.unit(Vet, Name = 'Jim McBain') 
    757             jim1.City = "Addis Ababa" 
    758             self.box1.repress(jim1) 
     751            jim1 = schema['Vet'].select_one(Name = 'Jim McBain') 
     752            schema['Vet'].save(ID = jim1['ID'], City = "Addis Ababa") 
    759753             
    760754            # Read City 2. 
    761755            self.boxid = 2 
    762             jim2 = self.box2.unit(Vet, Name = 'Jim McBain') 
     756            jim2 = schema['Vet'].select_one(Name = 'Jim McBain') 
    763757            # If READ UNCOMMITTED or lower, this should fail 
    764             assert jim2.City is None 
    765          
    766         for level in geniusql.levels: 
     758            assert jim2['City'] is None 
     759         
     760        for level in geniusql.isolation.levels: 
    767761            if self.verbose: 
    768762                print 
     
    775769            # Read City 1 
    776770            self.boxid = 1 
    777             jim1 = self.box1.unit(Vet, Name = 'Jim McBain') 
    778             val1 = jim1.City 
     771            jim1 = schema['Vet'].select_one(Name = 'Jim McBain') 
     772            val1 = jim1['City'] 
    779773            assert val1 is None 
    780             self.box1.repress(jim1) 
    781774             
    782775            # Write City 2. 
    783776            self.boxid = 2 
    784             jim2 = self.box2.unit(Vet, Name = 'Jim McBain') 
    785             jim2.City = "Tehachapi" 
    786             self.box2.flush_all() 
     777            jim2 = schema['Vet'].select_one(Name = 'Jim McBain') 
     778            schema['Vet'].save(ID=jim2['ID'], City = "Tehachapi") 
     779            db.connections.commit() 
    787780         
    788781            # Re-read City 1 
    789782            self.boxid = 1 
    790             jim1 = self.box1.unit(Vet, Name = 'Jim McBain') 
     783            jim1 = schema['Vet'].select_one(Name = 'Jim McBain') 
    791784            # If READ COMMITTED or lower, this should fail 
    792             assert jim1.City == val1 
    793          
    794         for level in geniusql.levels: 
     785            assert jim1['City'] == val1 
     786         
     787        for level in geniusql.isolation.levels: 
    795788            if self.verbose: 
    796789                print 
     
    803796            # Read City 1 
    804797            self.boxid = 1 
    805             pvets = self.box1.recall(Vet, City = 'Poughkeepsie'
     798            pvets = list(schema['Vet'].select_all(City = 'Poughkeepsie')
    806799            assert len(pvets) == 0 
    807800             
    808801            # Write City 2. 
    809802            self.boxid = 2 
    810             jim2 = self.box2.unit(Vet, Name = 'Jim McBain') 
    811             jim2.City = "Poughkeepsie" 
    812             self.box2.flush_all() 
     803            jim2 = schema['Vet'].select_one(Name = 'Jim McBain') 
     804            schema['Vet'].save(ID = jim2['ID'], City = "Poughkeepsie") 
     805            db.connections.commit() 
    813806         
    814807            # Re-read City 1 
    815808            self.boxid = 1 
    816             pvets = self.box1.recall(Vet, City = 'Poughkeepsie'
     809            pvets = list(schema['Vet'].select_all(City = 'Poughkeepsie')
    817810            # If REPEATABLE READ or lower, this should fail 
    818811            assert len(pvets) == 0 
    819812         
    820         for level in geniusql.levels: 
     813        for level in geniusql.isolation.levels: 
    821814            if self.verbose: 
    822815                print 
     
    11211114            tools.TestRunner.run(zoocase) 
    11221115            print "Ran zoo cases in:", datetime.datetime.now() - startTime 
    1123 ##             
    1124 ##            # Run the other cases. 
     1116             
     1117            # Run the other cases. 
    11251118##            tools.TestRunner.run(loader(NumericTests)) 
    11261119##            tools.TestRunner.run(loader(ConcurrencyTests)) 
    1127 ##            s = arena.stores.values()[0] 
    1128 ##            if hasattr(s, "db"): 
    1129 ##                tools.TestRunner.run(loader(IsolationTests)) 
    1130 ##                tools.TestRunner.run(loader(DiscoveryTests)) 
     1120            tools.TestRunner.run(loader(IsolationTests)) 
     1121##            tools.TestRunner.run(loader(DiscoveryTests)) 
    11311122        except: 
    11321123            traceback.print_exc()