[Sqlalchemy-commits] [1325] sqlalchemy/trunk/test: Got the unit tests running again, apart from the
Brought to you by:
zzzeek
From: <co...@sq...> - 2006-04-23 21:41:45
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><style type="text/css"><!-- #msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; } #msg dt { float: left; width: 6em; font-weight: bold; } #msg dt:after { content:':';} #msg dl, #msg dt, #msg ul, #msg li { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; } #msg dl a { font-weight: bold} #msg dl a:link { color:#fc3; } #msg dl a:active { color:#ff0; } #msg dl a:visited { color:#cc6; } h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; } #msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; } #msg ul, pre { overflow: auto; } #patch { width: 100%; } #patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;} #patch .propset h4, #patch .binary h4 {margin:0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;} #patch .propset .diff, #patch .binary .diff {padding:10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;} #patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;} #patch .lines, .info {color:#888;background:#fff;} --></style> <title>[1325] sqlalchemy/trunk/test: Got the unit tests running again, apart from the two that were not working in</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>1325</dd> <dt>Author</dt> <dd>cleverdevil</dd> <dt>Date</dt> <dd>2006-04-23 16:41:36 -0500 (Sun, 23 Apr 2006)</dd> </dl> <h3>Log Message</h3> <pre>Got the unit tests running again, apart from the two that were not working in the first place. The changes to process_relationships and to sqlachemy itself were causing a double 'assign_mapper' call to cause issues. Now, we basically defer calling assign_mapper until process_relationships in cases where there are defined relationships. Also, I moved ActiveMapper to always use the default engine, as there were a lot of hacks inside ActiveMapper to allow for engine swapping. The use of the default engine and the "global_connect" functionality significantly improves the usability of ActiveMapper. ActiveMapper will be getting a bit of a refactor/cleanup at some point in the nearish future, as it has drifted a bit to complexity with the addition of some features. For now, this should do the trick!</pre> <h3>Modified Paths</h3> <ul> <li><a href="#sqlalchemytrunklibsqlalchemyextactivemapperpy">sqlalchemy/trunk/lib/sqlalchemy/ext/activemapper.py</a></li> <li><a href="#sqlalchemytrunktestactivemapperpy">sqlalchemy/trunk/test/activemapper.py</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="sqlalchemytrunklibsqlalchemyextactivemapperpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/lib/sqlalchemy/ext/activemapper.py (1324 => 1325)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/lib/sqlalchemy/ext/activemapper.py 2006-04-23 21:05:13 UTC (rev 1324) +++ sqlalchemy/trunk/lib/sqlalchemy/ext/activemapper.py 2006-04-23 21:41:36 UTC (rev 1325) </span><span class="lines">@@ -1,19 +1,10 @@ </span><del>-from sqlalchemy import objectstore, create_engine, assign_mapper, relation, mapper, join -from sqlalchemy import and_, or_ </del><ins>+from sqlalchemy import assign_mapper, relation, exceptions </ins><span class="cx"> from sqlalchemy import Table, Column, ForeignKey </span><del>-from sqlalchemy.ext.proxy import ProxyEngine </del><span class="cx"> </span><span class="cx"> import inspect </span><span class="cx"> import sys </span><span class="cx"> </span><span class="cx"> # </span><del>-# the "proxy" to the database engine... this can be swapped out at runtime -# -engine = ProxyEngine() - - - -# </del><span class="cx"> # declarative column declaration - this is so that we can infer the colname </span><span class="cx"> # </span><span class="cx"> class column(object): </span><span class="lines">@@ -87,22 +78,21 @@ </span><span class="cx"> def process_relationships(klass): </span><span class="cx"> defer = False </span><span class="cx"> for propname, reldesc in klass.relations.items(): </span><del>- #We require that every related table has been processed first </del><ins>+ # we require that every related table has been processed first </ins><span class="cx"> if not reldesc.classname in __processed_classes__: </span><span class="cx"> if not klass._classname in __deferred_classes__: __deferred_classes__.append(klass._classname) </span><span class="cx"> defer = True </span><del>- - - #Check every column item to see if it points to an existing table - #if it does not, defer... </del><ins>+ + # check every column item to see if it points to an existing table + # if it does not, defer... </ins><span class="cx"> if not defer: </span><del>- if not check_relationships(klass): - if not klass._classname in __deferred_classes__: __deferred_classes__.append(klass._classname) - defer = True - </del><ins>+ if not check_relationships(klass): + if not klass._classname in __deferred_classes__: __deferred_classes__.append(klass._classname) + defer = True + </ins><span class="cx"> if not defer: </span><span class="cx"> relations = {} </span><del>- __processed_classes__.append(klass._classname) </del><ins>+ </ins><span class="cx"> for propname, reldesc in klass.relations.items(): </span><span class="cx"> relclass = ActiveMapperMeta.classes[reldesc.classname] </span><span class="cx"> relations[propname] = relation(relclass.mapper, </span><span class="lines">@@ -111,17 +101,23 @@ </span><span class="cx"> private=reldesc.private, </span><span class="cx"> lazy=reldesc.lazy, </span><span class="cx"> uselist=reldesc.uselist) </span><del>- if len(relations)>0: - assign_mapper(klass, klass.table, properties=relations) </del><ins>+ if len(relations) > 0: + assign_ok = True + try: + assign_mapper(klass, klass.table, properties=relations) + except exceptions.ArgumentError: + assign_ok = False </ins><span class="cx"> </span><del>- if klass._classname in __deferred_classes__: __deferred_classes__.remove(klass._classname) </del><ins>+ if assign_ok: + __processed_classes__.append(klass._classname) + if klass._classname in __deferred_classes__: __deferred_classes__.remove(klass._classname) + else: + __processed_classes__.append(klass._classname) </ins><span class="cx"> </span><span class="cx"> for deferred_class in __deferred_classes__: </span><span class="cx"> process_relationships(ActiveMapperMeta.classes[deferred_class]) </span><span class="cx"> </span><span class="cx"> </span><del>- - </del><span class="cx"> class ActiveMapperMeta(type): </span><span class="cx"> classes = {} </span><span class="cx"> </span><span class="lines">@@ -129,7 +125,6 @@ </span><span class="cx"> table_name = clsname.lower() </span><span class="cx"> columns = [] </span><span class="cx"> relations = {} </span><del>- _engine = getattr( sys.modules[cls.__module__], "__engine__", engine ) </del><span class="cx"> </span><span class="cx"> if 'mapping' in dict: </span><span class="cx"> members = inspect.getmembers(dict.get('mapping')) </span><span class="lines">@@ -138,10 +133,6 @@ </span><span class="cx"> table_name = value </span><span class="cx"> continue </span><span class="cx"> </span><del>- if '__engine__' == name: - _engine= value - continue - </del><span class="cx"> if name.startswith('__'): continue </span><span class="cx"> </span><span class="cx"> if isinstance(value, column): </span><span class="lines">@@ -161,13 +152,14 @@ </span><span class="cx"> </span><span class="cx"> if isinstance(value, relationship): </span><span class="cx"> relations[name] = value </span><del>- assert _engine is not None, "No engine specified" - cls.table = Table(table_name, _engine, *columns) </del><ins>+ + cls.table = Table(table_name, redefine=True, *columns) + </ins><span class="cx"> # check for inheritence </span><del>- if hasattr( bases[0], "mapping" ): - cls._base_mapper= bases[0].mapper </del><ins>+ if hasattr(bases[0], "mapping"): + cls._base_mapper = bases[0].mapper </ins><span class="cx"> assign_mapper(cls, cls.table, inherits=cls._base_mapper) </span><del>- else: </del><ins>+ elif len(relations) == 0: </ins><span class="cx"> assign_mapper(cls, cls.table) </span><span class="cx"> cls.relations = relations </span><span class="cx"> cls._classname = clsname </span><span class="lines">@@ -191,4 +183,11 @@ </span><span class="cx"> </span><span class="cx"> def create_tables(): </span><span class="cx"> for klass in ActiveMapperMeta.classes.values(): </span><del>- klass.table.create() </del><span class="cx">\ No newline at end of file </span><ins>+ klass.table.create() + +# +# a utility function to drop all tables for all ActiveMapper classes +# +def drop_tables(): + for klass in ActiveMapperMeta.classes.values(): + klass.table.drop() </ins><span class="cx">\ No newline at end of file </span></span></pre></div> <a id="sqlalchemytrunktestactivemapperpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/test/activemapper.py (1324 => 1325)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/test/activemapper.py 2006-04-23 21:05:13 UTC (rev 1324) +++ sqlalchemy/trunk/test/activemapper.py 2006-04-23 21:41:36 UTC (rev 1325) </span><span class="lines">@@ -1,11 +1,11 @@ </span><del>-from activemapper import ActiveMapper, column, one_to_many, one_to_one -from sqlalchemy import objectstore -from sqlalchemy import and_, or_ -from sqlalchemy import ForeignKey, String, Integer, DateTime -from datetime import datetime </del><ins>+from sqlalchemy.ext.activemapper import ActiveMapper, column, one_to_many, one_to_one +from sqlalchemy.ext import activemapper +from sqlalchemy import objectstore, global_connect +from sqlalchemy import and_, or_ +from sqlalchemy import ForeignKey, String, Integer, DateTime +from datetime import datetime </ins><span class="cx"> </span><span class="cx"> import unittest </span><del>-import activemapper </del><span class="cx"> </span><span class="cx"> # </span><span class="cx"> # application-level model objects </span><span class="lines">@@ -130,6 +130,9 @@ </span><span class="cx"> </span><span class="cx"> </span><span class="cx"> def test_create(self): </span><ins>+ global_connect('sqlite:///', echo=False) + activemapper.create_tables() + </ins><span class="cx"> p1 = self.create_person_one() </span><span class="cx"> </span><span class="cx"> objectstore.commit() </span><span class="lines">@@ -222,9 +225,4 @@ </span><span class="cx"> </span><span class="cx"> </span><span class="cx"> if __name__ == '__main__': </span><del>- # go ahead and setup the database connection, and create the tables - activemapper.engine.connect('sqlite:///', echo=False) - activemapper.create_tables() - - # launch the unit tests </del><span class="cx"> unittest.main() </span><span class="cx">\ No newline at end of file </span></span></pre> </div> </div> </body> </html> |