Django

Code

Changeset 2940

Show
Ignore:
Timestamp:
05/18/06 13:25:49 (2 years ago)
Author:
jacob
Message:

The tests now run correctly with the new psycopg2 backend. There's 4 failures, but they all have to do with the new way the psycopg2 handles datetimes and are probably a single fix.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/tests/runtests.py

    r2939 r2940  
    115115            TEST_DATABASE_NAME = ":memory:" 
    116116        else: 
    117             # Create the test database and connect to it. We need autocommit() 
    118             # because PostgreSQL doesn't allow CREATE DATABASE statements 
    119             # within transactions. 
     117            # Create the test database and connect to it. We need to autocommit 
     118            # if the database supports it because PostgreSQL doesn't allow  
     119            # CREATE/DROP DATABASE statements within transactions. 
    120120            cursor = connection.cursor() 
    121             try: 
    122                 connection.connection.autocommit(1) 
    123             except AttributeError: 
    124                 pass 
     121            self._set_autocommit(connection) 
    125122            self.output(1, "Creating test database") 
    126123            try: 
     
    225222            cursor = connection.cursor() 
    226223            self.output(1, "Deleting test database") 
    227             try: 
    228                 connection.connection.autocommit(1) 
    229             except AttributeError: 
    230                 pass 
    231             else: 
    232                 time.sleep(1) # To avoid "database is being accessed by other users" errors. 
     224            self._set_autocommit(connection) 
     225            time.sleep(1) # To avoid "database is being accessed by other users" errors. 
    233226            cursor.execute("DROP DATABASE %s" % TEST_DATABASE_NAME) 
    234227 
     
    243236        else: 
    244237            print "All tests passed." 
     238             
     239    def _set_autocommit(self, connection): 
     240        """ 
     241        Make sure a connection is in autocommit mode. 
     242        """ 
     243        if hasattr(connection.connection, "autocommit"): 
     244            connection.connection.autocommit(True) 
     245        elif hasattr(connection.connection, "set_isolation_level"): 
     246            connection.connection.set_isolation_level(0) 
    245247 
    246248if __name__ == "__main__":