[SQL-CVS] r1591 - in MetaSQLObject/trunk: . metasqlobject sqlobject tests tests/so
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2006-02-11 09:52:04
|
Author: ianb Date: 2006-02-11 02:51:51 -0700 (Sat, 11 Feb 2006) New Revision: 1591 Added: MetaSQLObject/trunk/metasqlobject/classinst.py MetaSQLObject/trunk/metasqlobject/events.py MetaSQLObject/trunk/sqlobject/ MetaSQLObject/trunk/sqlobject/__init__.py MetaSQLObject/trunk/sqlobject/col.py MetaSQLObject/trunk/sqlobject/events.py MetaSQLObject/trunk/sqlobject/main.py MetaSQLObject/trunk/tests/ MetaSQLObject/trunk/tests/conftest.py MetaSQLObject/trunk/tests/so/ Modified: MetaSQLObject/trunk/metasqlobject/declarative.py MetaSQLObject/trunk/setup.cfg MetaSQLObject/trunk/setup.py MetaSQLObject/trunk/tests/so/dbtest.py MetaSQLObject/trunk/tests/so/test_auto.py MetaSQLObject/trunk/tests/so/test_auto_old.py MetaSQLObject/trunk/tests/so/test_create_drop.py MetaSQLObject/trunk/tests/so/test_cyclic_reference.py MetaSQLObject/trunk/tests/so/test_datetime.py MetaSQLObject/trunk/tests/so/test_joins_conditional.py MetaSQLObject/trunk/tests/so/test_paste.py MetaSQLObject/trunk/tests/so/test_string_id.py Log: Intermediate commit while stuff is getting moved around Added: MetaSQLObject/trunk/metasqlobject/classinst.py =================================================================== --- MetaSQLObject/trunk/metasqlobject/classinst.py 2006-02-10 21:04:09 UTC (rev 1590) +++ MetaSQLObject/trunk/metasqlobject/classinst.py 2006-02-11 09:51:51 UTC (rev 1591) @@ -0,0 +1,37 @@ +__all__ = ['classinstancemethod'] + +class classinstancemethod(object): + """ + Acts like a class method when called from a class, like an + instance method when called by an instance. The method should + take two arguments, 'self' and 'cls'; one of these will be None + depending on how the method was called. + """ + + def __init__(self, func): + self.func = func + + def __get__(self, obj, type=None): + return _methodwrapper(self.func, obj=obj, type=type) + +class _methodwrapper(object): + + def __init__(self, func, obj, type): + self.func = func + self.obj = obj + self.type = type + + def __call__(self, *args, **kw): + assert not kw.has_key('self') and not kw.has_key('cls'), ( + "You cannot use 'self' or 'cls' arguments to a " + "classinstancemethod") + return self.func(*((self.obj, self.type) + args), **kw) + + def __repr__(self): + if self.obj is None: + return ('<bound class method %s.%s>' + % (self.type.__name__, self.func.func_name)) + else: + return ('<bound method %s.%s of %r>' + % (self.type.__name__, self.func.func_name, + self.obj)) Property changes on: MetaSQLObject/trunk/metasqlobject/classinst.py ___________________________________________________________________ Name: svn:eol-style + native Modified: MetaSQLObject/trunk/metasqlobject/declarative.py =================================================================== --- MetaSQLObject/trunk/metasqlobject/declarative.py 2006-02-10 21:04:09 UTC (rev 1590) +++ MetaSQLObject/trunk/metasqlobject/declarative.py 2006-02-11 09:51:51 UTC (rev 1591) @@ -7,39 +7,36 @@ (So if a class is received, we'll simply instantiate an instance with no arguments). -You can provide a variable __unpackargs__ (a list of strings), and if -the constructor is called with non-keyword arguments they will be -interpreted as the given keyword arguments. +You can provide a class variable ``__unpackargs__`` (a list of +strings), and if the constructor is called with non-keyword arguments +they will be interpreted as the given keyword arguments. -If __unpackargs__ is ('*', name), then all the arguments will be put -in a variable by that name. +If ``__unpackargs__`` is ``('*', name)``, then all the arguments will +be put in a variable by that name. -You can define a __classinit__(cls, new_attrs) method, which will be -called when the class is created (including subclasses). Note: you -can't use super() in __classinit__ because the class isn't bound to a -name. As an analog to __classinit__, Declarative adds -__instanceinit__ which is called with the same argument (new_attrs). -This is like __init__, but after __unpackargs__ and other factors have -been taken into account. +You can define a ``__classinit__(cls, new_attrs)`` method, which will +be called when the class is created (including subclasses). Note: you +can't use ``super()`` in ``__classinit__`` because the class isn't +bound to a name. As an analog to ``__classinit__``, ``Declarative`` +adds ``__instanceinit__`` which is called with the same argument +(``new_attrs``). This is like ``__init__``, but applied after +``__unpackargs__`` and other factors have been taken into account. -If __mutableattributes__ is defined as a sequence of strings, these -attributes will not be shared between superclasses and their +If ``__mutableattributes__`` is defined as a sequence of strings, +these attributes will not be shared between superclasses and their subclasses. E.g., if you have a class variable that contains a list and you append to that list, changes to subclasses will effect -superclasses unless you add the attribute here. - -Also defines classinstancemethod, which acts as either a class method -or an instance method depending on where it is called. +superclasses unless you add the attribute here. So any variables +listed there will be copied (shallowly). """ from __future__ import generators import threading -import events - -__all__ = ('classinstancemethod', 'DeclarativeMeta', 'Declarative') - import copy +from classinst import classinstancemethod +__all__ = ('DeclarativeMeta', 'Declarative') + try: import itertools counter = itertools.count() @@ -51,55 +48,6 @@ yield i counter = _counter() -class classinstancemethod(object): - """ - Acts like a class method when called from a class, like an - instance method when called by an instance. The method should - take two arguments, 'self' and 'cls'; one of these will be None - depending on how the method was called. - """ - - def __init__(self, func): - self.func = func - - def __get__(self, obj, type=None): - return _methodwrapper(self.func, obj=obj, type=type) - -class _methodwrapper(object): - - def __init__(self, func, obj, type): - self.func = func - self.obj = obj - self.type = type - - def __call__(self, *args, **kw): - assert not kw.has_key('self') and not kw.has_key('cls'), ( - "You cannot use 'self' or 'cls' arguments to a " - "classinstancemethod") - return self.func(*((self.obj, self.type) + args), **kw) - - def __repr__(self): - if self.obj is None: - return ('<bound class method %s.%s>' - % (self.type.__name__, self.func.func_name)) - else: - return ('<bound method %s.%s of %r>' - % (self.type.__name__, self.func.func_name, self.obj)) - -def threadSafeMethod(lock): - def decorator(fn): - def _wrapper(self, *args, **kwargs): - lock.acquire() - return_value = fn(self, *args, **kwargs) - lock.release() - return return_value - try: - _wrapper.func_name = fn.func_name - except TypeError: - pass - return _wrapper - return decorator - class DeclarativeMeta(type): def __new__(meta, class_name, bases, new_attrs): Copied: MetaSQLObject/trunk/metasqlobject/events.py (from rev 1562, SQLObject/trunk/sqlobject/events.py) =================================================================== --- SQLObject/trunk/sqlobject/events.py 2006-02-03 19:08:46 UTC (rev 1562) +++ MetaSQLObject/trunk/metasqlobject/events.py 2006-02-11 09:51:51 UTC (rev 1591) @@ -0,0 +1,44 @@ +from weakref import ref +from UserDict import DictMixin + +__all__ = ['EventHub', 'Signal'] + +class EventHub(DictMixin): + + def __init__(self): + self._events = {} + + def copy(self): + new = self.__class__() + new._events = self._events.copy() + return new + + def listen(self, signal, listener, weak=True): + if weak: + listener = ref(listener) + else: + listener = lambda l=listener: l + self._events.setdefault(signal, []).append(listener) + + def send(self, signal, **kw): + for listener in self._events.get(signal, ()): + listener(**kw) + +class _Signal(object): + """ + Base event for all SQLObject events. + + In general the sender for these methods is the class, not the + instance. + """ + + def __init__(self, class_name, bases, attrs): + self.name = self.__name__ = class_name + for name, value in attrs.items(): + setattr(self, name, value) + + def __repr__(self): + return '<Signal:%s>' % (self.name) + +Signal = _Signal('Signal', (), {}) + Modified: MetaSQLObject/trunk/setup.cfg =================================================================== --- MetaSQLObject/trunk/setup.cfg 2006-02-10 21:04:09 UTC (rev 1590) +++ MetaSQLObject/trunk/setup.cfg 2006-02-11 09:51:51 UTC (rev 1591) @@ -7,7 +7,7 @@ docs = docs/index.txt doc_base = docs/ dest = docs/html -modules = metasqlobject +modules = metasqlobject sqlobject title = Meta SQLObject mailing_list_url = http://sqlobject.org/community.html settings = normal_link_color=#039 Modified: MetaSQLObject/trunk/setup.py =================================================================== --- MetaSQLObject/trunk/setup.py 2006-02-10 21:04:09 UTC (rev 1590) +++ MetaSQLObject/trunk/setup.py 2006-02-11 09:51:51 UTC (rev 1591) @@ -17,7 +17,7 @@ include_package_data=True, zip_safe=False, install_requires=[ - # -*- Extra requirements: -*- + 'Louie', ], entry_points=""" # -*- Entry points: -*- Added: MetaSQLObject/trunk/sqlobject/__init__.py =================================================================== --- MetaSQLObject/trunk/sqlobject/__init__.py 2006-02-10 21:04:09 UTC (rev 1590) +++ MetaSQLObject/trunk/sqlobject/__init__.py 2006-02-11 09:51:51 UTC (rev 1591) @@ -0,0 +1 @@ +# Property changes on: MetaSQLObject/trunk/sqlobject/__init__.py ___________________________________________________________________ Name: svn:eol-style + native Added: MetaSQLObject/trunk/sqlobject/col.py =================================================================== --- MetaSQLObject/trunk/sqlobject/col.py 2006-02-10 21:04:09 UTC (rev 1590) +++ MetaSQLObject/trunk/sqlobject/col.py 2006-02-11 09:51:51 UTC (rev 1591) @@ -0,0 +1,28 @@ +from metasqlobject.declarative import Declarative + +class Col(Declarative): + + standard_sql_type = None + sql_type_parameters = {} + + def _add_sql_type_param(self, **params): + if self.sql_type_parameters is self.__class__.sql_type_parameters: + self.sql_type_parameters = self.sql_type_parameters.copy() + self.sql_type_parameters.update(params) + +class StringCol(Col): + + standard_sql_type = 'TEXT' + + def __init__(self, length=None): + if length is not None: + self._add_sql_type_param(length=length) + +class IntCol(Col): + + standard_sql_type = 'INT' + +class FloatCol(Col): + + standard_sql_type = 'FLOAT' + Property changes on: MetaSQLObject/trunk/sqlobject/col.py ___________________________________________________________________ Name: svn:eol-style + native Added: MetaSQLObject/trunk/sqlobject/events.py =================================================================== --- MetaSQLObject/trunk/sqlobject/events.py 2006-02-10 21:04:09 UTC (rev 1590) +++ MetaSQLObject/trunk/sqlobject/events.py 2006-02-11 09:51:51 UTC (rev 1591) @@ -0,0 +1,114 @@ +from metasqlobject.eventhub import Signal + +class ClassCreateSignal(Signal): + """ + Signal raised after class creation. The sender is the superclass + (in case of multiple superclasses, the first superclass). The + arguments are ``(new_class_name, bases, new_attrs, post_funcs, + early_funcs)``. ``new_attrs`` is a dictionary and may be modified + (but ``new_class_name`` and ``bases`` are immutable). + ``post_funcs`` is an initially-empty list that can have callbacks + appended to it. + + Note: at the time this event is called, the new class has not yet + been created. The functions in ``post_funcs`` will be called + after the class is created, with the single arguments of + ``(new_class)``. Also, ``early_funcs`` will be called at the + soonest possible time after class creation (``post_funcs`` is + called after the class's ``__classinit__``). + """ + +# @@: Should there be a class reload event? This would allow modules +# to be reloaded, possibly. Or it could even be folded into +# ClassCreateSignal, since anything that listens to that needs to pay +# attention to reloads (or else it is probably buggy). + +class RowCreateSignal(Signal): + """ + Called before an instance is created, with the class as the + sender. Called with the arguments ``(kwargs, post_funcs)``. + There may be a ``connection`` argument. ``kwargs``may be usefully + modified. ``post_funcs`` is a list of callbacks, intended to have + functions appended to it, and are called with the arguments + ``(new_instance)``. + + Note: this is not called when an instance is created from an + existing database row. + """ + +# @@: An event for getting a row? But for each row, when doing a +# select? For .sync, .syncUpdate, .expire? + +class RowDestroySignal(Signal): + """ + Called before an instance is deleted. Sender is the instance's + class. Arguments are ``(instance)``. You cannot cancel the delete, + but you can raise an exception (which will probably cancel the + delete, but also cause an uncaught exception if not expected). + + Note: this is not called when an instance is destroyed through + garbage collection. + + @@: Should this allow ``instance`` to be a primary key, so that a + row can be deleted without first fetching it? + """ + +class RowUpdateSignal(Signal): + """ + Called when an instance is updated through a call to ``.set()``. + The arguments are ``(instance, kwargs)``. ``kwargs`` can be + modified. This is run *before* the instance is updated; if you + want to look at the current values, simply look at ``instance``. + """ + +class AddColumnSignal(Signal): + """ + Called when a column is added to a class, with arguments ``(cls, + connection, column_name, column_definition, changeSchema, + post_funcs)``. This is called *after* the column has been added, + and is called for each column after class creation. + + post_funcs are called with ``(cls, so_column_obj)`` + """ + +class DeleteColumnSignal(Signal): + """ + Called when a column is removed from a class, with the arguments + ``(cls, connection, column_name, so_column_obj, post_funcs)``. + Like ``AddColumnSignal`` this is called after the action has been + performed, and is called for subclassing (when a column is + implicitly removed by setting it to ``None``). + + post_funcs are called with ``(cls, so_column_obj)`` + """ + +# @@: Signals for indexes and joins? These are mostly event consumers, +# though. + +class CreateTableSignal(Signal): + """ + Called when a table is created. If ``ifNotExists==True`` and the + table exists, this event is not called. + + Called with ``(cls, connection, extra_sql, post_funcs)``. + ``extra_sql`` is a list (which can be appended to) of extra SQL + statements to be run after the table is created. ``post_funcs`` + functions are called with ``(cls, connection)`` after the table + has been created. Those functions are *not* called simply when + constructing the SQL. + """ + +class DropTableSignal(Signal): + """ + Called when a table is dropped. If ``ifExists==True`` and the + table doesn't exist, this event is not called. + + Called with ``(cls, connection, extra_sql, post_funcs)``. + ``post_funcs`` functions are called with ``(cls, connection)`` + after the table has been dropped. + """ + +__all__ = [] +for name, value in globals().items(): + if isinstance(value, type) and issubclass(value, Signal): + __all__.append(name) Property changes on: MetaSQLObject/trunk/sqlobject/events.py ___________________________________________________________________ Name: svn:eol-style + native Added: MetaSQLObject/trunk/sqlobject/main.py =================================================================== --- MetaSQLObject/trunk/sqlobject/main.py 2006-02-10 21:04:09 UTC (rev 1590) +++ MetaSQLObject/trunk/sqlobject/main.py 2006-02-11 09:51:51 UTC (rev 1591) @@ -0,0 +1,49 @@ +from metasqlobject.declarative import Declarative +from sqlapi import sql + +class sqlmeta(object): + + _creating = False + + lazy = False + + def __init__(self, instance): + self.instance = instance + + #@classmethod + def _set_soclass(cls, soclass): + cls.soclass = soclass + + _set_soclass = classmethod(_set_soclass) + + def create(self): + conn = self.connection + sql = sql.Insert(self._values, self.table) + + + +class SQLObject(Declarative): + + def __classinit__(cls, new_attrs): + if not isinstance(cls.sqlmeta, sqlmeta): + new_sqlmeta = type(sqlmeta, (cls.__bases__[0].sqlmeta,), + cls.sqlmeta.__dict__) + cls.sqlmeta = new_sqlmeta + cls.sqlmeta._set_soclass(cls) + + def __init__(self, **kw): + self.sqlmeta = self.sqlmeta(self) + self.sqlmeta._creating = True + self.sqlmeta._values = {} + for name, value in kw: + if hasattr(self, name): + setattr(self, name, value) + else: + raise TypeError( + "%s() called with unknown keyword %s" + % (self.__class__.__name__, name)) + + if not self.sqlmeta.lazy: + self.sqlmeta.create() + + Property changes on: MetaSQLObject/trunk/sqlobject/main.py ___________________________________________________________________ Name: svn:eol-style + native Added: MetaSQLObject/trunk/tests/conftest.py =================================================================== --- MetaSQLObject/trunk/tests/conftest.py 2006-02-10 21:04:09 UTC (rev 1590) +++ MetaSQLObject/trunk/tests/conftest.py 2006-02-11 09:51:51 UTC (rev 1591) @@ -0,0 +1,4 @@ +import sys, os +sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) +import pkg_resources +pkg_resources.require('MetaSQLObject') Property changes on: MetaSQLObject/trunk/tests/conftest.py ___________________________________________________________________ Name: svn:eol-style + native Copied: MetaSQLObject/trunk/tests/so (from rev 1562, SQLObject/trunk/sqlobject/tests) Modified: MetaSQLObject/trunk/tests/so/dbtest.py =================================================================== --- SQLObject/trunk/sqlobject/tests/dbtest.py 2006-02-03 19:08:46 UTC (rev 1562) +++ MetaSQLObject/trunk/tests/so/dbtest.py 2006-02-11 09:51:51 UTC (rev 1591) @@ -43,169 +43,20 @@ '-limitSelect' : 'mssql' } +def setConnection(conn): + if isinstance(conn, basestring): + conn = sqlobject.connectionForURI(conn) + sqlobject.sqlhub.processConnection = conn -def setupClass(soClasses, force=False): - """ - Makes sure the classes have a corresponding and correct table. - This won't recreate the table if it already exists. It will check - that the table is properly defined (in case you change your table - definition). - - You can provide a single class or a list of classes; if a list - then classes will be created in the order you provide, and - destroyed in the opposite order. So if class A depends on class - B, then do setupClass([B, A]) and B won't be destroyed or cleared - until after A is destroyed or cleared. - - If force is true, then the database will be recreated no matter - what. - """ - global hub +def setupClass(soClasses): if not isinstance(soClasses, (list, tuple)): soClasses = [soClasses] - connection = getConnection() - for soClass in soClasses: - ## This would be an alternate way to register connections... - #try: - # hub - #except NameError: - # hub = sqlobject.dbconnection.ConnectionHub() - #soClass._connection = hub - #hub.threadConnection = connection - #hub.processConnection = connection - soClass._connection = connection - installOrClear(soClasses, force=force) - return soClasses + reversed = soClasses[:] + for class_ in reversed: + class_.dropTable(ifExists=True, cascade=True) + for class_ in soClasses: + class_.createTable() -installedDBFilename = os.path.join(getcwd(), 'dbs_data.tmp') - -installedDBTracker = sqlobject.connectionForURI( - 'sqlite:///' + installedDBFilename) - -def getConnection(**kw): - name = getConnectionURI() - conn = sqlobject.connectionForURI(name, **kw) - if conftest.option.show_sql: - conn.debug = True - if conftest.option.show_sql_output: - conn.debugOutput = True - return conn - -def getConnectionURI(): - name = conftest.option.Database - if conftest.connectionShortcuts.has_key(name): - name = conftest.connectionShortcuts[name] - return name - -try: - connection = getConnection() -except Exception, e: - # At least this module should be importable... - print >> sys.stderr, ( - "Could not open database: %s" % e) - - -class InstalledTestDatabase(sqlobject.SQLObject): - """ - This table is set up in SQLite (always, regardless of --Database) and - tracks what tables have been set up in the 'real' database. This - way we don't keep recreating the tables over and over when there - are multiple tests that use a table. - """ - - _connection = installedDBTracker - tableName = sqlobject.StringCol(notNull=True) - createSQL = sqlobject.StringCol(notNull=True) - connectionURI = sqlobject.StringCol(notNull=True) - - def installOrClear(cls, soClasses, force=False): - cls.setup() - reversed = list(soClasses)[:] - reversed.reverse() - # If anything needs to be dropped, they all must be dropped - # But if we're forcing it, then we'll always drop - if force: - any_drops = True - else: - any_drops = False - for soClass in reversed: - table = soClass.sqlmeta.table - if not soClass._connection.tableExists(table): - continue - items = list(cls.selectBy( - tableName=table, - connectionURI=soClass._connection.uri())) - if items: - instance = items[0] - sql = instance.createSQL - else: - sql = None - newSQL, constraints = soClass.createTableSQL() - if sql != newSQL: - if sql is not None: - instance.destroySelf() - any_drops = True - break - for soClass in reversed: - if soClass._connection.tableExists(soClass.sqlmeta.table): - if any_drops: - cls.drop(soClass) - else: - cls.clear(soClass) - for soClass in soClasses: - table = soClass.sqlmeta.table - if not soClass._connection.tableExists(table): - cls.install(soClass) - installOrClear = classmethod(installOrClear) - - def install(cls, soClass): - """ - Creates the given table in its database. - """ - sql = getattr(soClass, soClass._connection.dbName + 'Create', - None) - all_extra = [] - if sql: - soClass._connection.query(sql) - else: - sql, extra_sql = soClass.createTableSQL() - soClass.createTable(applyConstraints=False) - all_extra.extend(extra_sql) - cls(tableName=soClass.sqlmeta.table, - createSQL=sql, - connectionURI=soClass._connection.uri()) - for extra_sql in all_extra: - soClass._connection.query(extra_sql) - install = classmethod(install) - - def drop(cls, soClass): - """ - Drops a the given table from its database - """ - sql = getattr(soClass, soClass._connection.dbName + 'Drop', None) - if sql: - soClass._connection.query(sql) - else: - soClass.dropTable() - drop = classmethod(drop) - - def clear(cls, soClass): - """ - Removes all the rows from a table. - """ - soClass.clearTable() - clear = classmethod(clear) - - def setup(cls): - """ - This sets up *this* table. - """ - if not cls._connection.tableExists(cls.sqlmeta.table): - cls.createTable() - setup = classmethod(setup) - -installOrClear = InstalledTestDatabase.installOrClear - class Dummy(object): """ @@ -255,7 +106,7 @@ return results def supports(feature): - dbName = connection.dbName + dbName = sqlobject.sqlhub.getConnection().dbName support = supportsMatrix.get('+' + feature, None) notSupport = supportsMatrix.get('-' + feature, None) if support is not None and dbName in support.split(): @@ -294,6 +145,6 @@ sqlobject.main.warnings_level = None sqlobject.main.exception_level = 0 -__all__ = ['getConnection', 'getConnectionURI', 'setupClass', 'Dummy', 'raises', +__all__ = ['setupClass', 'Dummy', 'raises', 'd', 'inserts', 'supports', 'deprecated_module', 'setup_module', 'teardown_module'] Modified: MetaSQLObject/trunk/tests/so/test_auto.py =================================================================== --- SQLObject/trunk/sqlobject/tests/test_auto.py 2006-02-03 19:08:46 UTC (rev 1562) +++ MetaSQLObject/trunk/tests/so/test_auto.py 2006-02-11 09:51:51 UTC (rev 1591) @@ -135,14 +135,16 @@ mssqlDrop = sybaseDrop def setup_method(self, meth): - conn = getConnection() + conn = sqlhub.getConnection() + if conn.tableExists('auto_test'): + conn.dropTable('auto_test') dbName = conn.dbName creator = getattr(self, dbName + 'Create', None) if creator: conn.query(creator) def teardown_method(self, meth): - conn = getConnection() + conn = sqlhub.getConnection() dbName = conn.dbName dropper = getattr(self, dbName + 'Drop', None) if dropper: @@ -152,7 +154,7 @@ if not supports('fromDatabase'): return class AutoTest(SQLObject): - _connection = getConnection() + _connection = sqlhub.getConnection() class sqlmeta(sqlmeta): idName = 'auto_id' fromDatabase = True Modified: MetaSQLObject/trunk/tests/so/test_auto_old.py =================================================================== --- SQLObject/trunk/sqlobject/tests/test_auto_old.py 2006-02-03 19:08:46 UTC (rev 1562) +++ MetaSQLObject/trunk/tests/so/test_auto_old.py 2006-02-11 09:51:51 UTC (rev 1591) @@ -28,8 +28,7 @@ class TestPeople: def setup_method(self, meth): - setupClass(OldPerson, force=True) - setupClass(OldPhone, force=True) + setupClass([OldPerson, OldPhone]) for n in ['jane', 'tim', 'bob', 'jake']: OldPerson(name=n) for p in ['555-555-5555', '555-394-2930', @@ -137,14 +136,14 @@ DROP TABLE old_auto_test """ def setup_method(self, meth): - conn = getConnection() + conn = sqlhub.getConnection() dbName = conn.dbName creator = getattr(self, dbName + 'Create', None) if creator: conn.query(creator) def teardown_method(self, meth): - conn = getConnection() + conn = sqlhub.getConnection() dbName = conn.dbName dropper = getattr(self, dbName + 'Drop', None) if dropper: @@ -154,7 +153,7 @@ if not supports('fromDatabase'): return class OldAutoTest(SQLObject): - _connection = getConnection() + _connection = sqlhub.getConnection() class sqlmeta(sqlmeta): idName = 'auto_id' fromDatabase = True Modified: MetaSQLObject/trunk/tests/so/test_create_drop.py =================================================================== --- SQLObject/trunk/sqlobject/tests/test_create_drop.py 2006-02-03 19:08:46 UTC (rev 1562) +++ MetaSQLObject/trunk/tests/so/test_create_drop.py 2006-02-11 09:51:51 UTC (rev 1591) @@ -12,7 +12,7 @@ blobcol = BLOBCol() def test_create_drop(): - conn = getConnection() + conn = sqlhub.getConnection() TestCreateDrop.setConnection(conn) TestCreateDrop.dropTable(ifExists=True) assert not conn.tableExists(TestCreateDrop.sqlmeta.table) Modified: MetaSQLObject/trunk/tests/so/test_cyclic_reference.py =================================================================== --- SQLObject/trunk/sqlobject/tests/test_cyclic_reference.py 2006-02-03 19:08:46 UTC (rev 1562) +++ MetaSQLObject/trunk/tests/so/test_cyclic_reference.py 2006-02-11 09:51:51 UTC (rev 1591) @@ -24,7 +24,7 @@ fkeya = ForeignKey('TestCyclicReferenceA') def test_cyclic_reference(): - conn = getConnection() + conn = sqlhub.getConnection() TestCyclicReferenceA.setConnection(conn) TestCyclicReferenceB.setConnection(conn) TestCyclicReferenceA.dropTable(ifExists=True, cascade=True) Modified: MetaSQLObject/trunk/tests/so/test_datetime.py =================================================================== --- SQLObject/trunk/sqlobject/tests/test_datetime.py 2006-02-03 19:08:46 UTC (rev 1562) +++ MetaSQLObject/trunk/tests/so/test_datetime.py 2006-02-11 09:51:51 UTC (rev 1591) @@ -44,7 +44,7 @@ from mx.DateTime import now, Time dateFormat = None # use default - if getConnection().dbName == "sqlite": + if sqlhub.getConnection().dbName == "sqlite": from sqlobject.sqlite.sqliteconnection import using_sqlite2 if using_sqlite2: # PySQLite2 returns full date/time for a date dateFormat = "%Y-%m-%d %H:%M:%S" Modified: MetaSQLObject/trunk/tests/so/test_joins_conditional.py =================================================================== --- SQLObject/trunk/sqlobject/tests/test_joins_conditional.py 2006-02-03 19:08:46 UTC (rev 1562) +++ MetaSQLObject/trunk/tests/so/test_joins_conditional.py 2006-02-11 09:51:51 UTC (rev 1591) @@ -26,7 +26,7 @@ join = LEFTJOIN("table1", "table2") assert str(join) == "table1 LEFT JOIN table2" join = LEFTJOINOn("table1", "table2", "tabl1.col1 = table2.col2") - assert getConnection().sqlrepr(join) == "table1 LEFT JOIN table2 ON tabl1.col1 = table2.col2" + assert sqlhub.getConnection().sqlrepr(join) == "table1 LEFT JOIN table2 ON tabl1.col1 = table2.col2" def test_2select_syntax(): setup() Modified: MetaSQLObject/trunk/tests/so/test_paste.py =================================================================== --- SQLObject/trunk/sqlobject/tests/test_paste.py 2006-02-03 19:08:46 UTC (rev 1562) +++ MetaSQLObject/trunk/tests/so/test_paste.py 2006-02-11 09:51:51 UTC (rev 1591) @@ -26,7 +26,7 @@ def makestack(abort=False, begin=False, fail=False, **kw): app = makeapp(abort=abort, begin=begin, fail=fail) - app = make_middleware(app, {}, database=getConnectionURI(), **kw) + app = make_middleware(app, {}, database=sqlhub.getConnection(), **kw) return app def runapp(**kw): @@ -43,11 +43,11 @@ def setup(): setupClass(NameOnly) - getConnection().query('DELETE FROM name_only') + sqlhub.getConnection().query('DELETE FROM name_only') NameOnly._connection = sqlhub def names(): - names = [n.name for n in NameOnly.select(connection=getConnection())] + names = [n.name for n in NameOnly.select(connection=sqlhub.getConnection())] names.sort() return names Modified: MetaSQLObject/trunk/tests/so/test_string_id.py =================================================================== --- SQLObject/trunk/sqlobject/tests/test_string_id.py 2006-02-03 19:08:46 UTC (rev 1562) +++ MetaSQLObject/trunk/tests/so/test_string_id.py 2006-02-11 09:51:51 UTC (rev 1591) @@ -8,7 +8,7 @@ name = StringCol() def test_string_id(): - conn = getConnection() + conn = sqlhub.getConnection() TestStringID.setConnection(conn) TestStringID.dropTable(ifExists=True) assert not conn.tableExists(TestStringID.sqlmeta.table) |