[Sqlalchemy-commits] [3697] sqlalchemy/trunk/test/testlib: Added command line options to add tripwi
Brought to you by:
zzzeek
From: <co...@sq...> - 2007-10-31 23:49:17
|
<!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><meta http-equiv="content-type" content="text/html; charset=utf-8" /><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, #header, #footer { 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; } #header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; } #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>[3697] sqlalchemy/trunk/test/testlib: Added command line options to add tripwires for __hash__, __eq__ and __nonzero__ on mapped classes.</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>3697</dd> <dt>Author</dt> <dd>jek</dd> <dt>Date</dt> <dd>2007-10-31 19:49:09 -0400 (Wed, 31 Oct 2007)</dd> </dl> <h3>Log Message</h3> <pre>Added command line options to add tripwires for __hash__, __eq__ and __nonzero__ on mapped classes.</pre> <h3>Modified Paths</h3> <ul> <li><a href="#sqlalchemytrunktesttestlib__init__py">sqlalchemy/trunk/test/testlib/__init__.py</a></li> <li><a href="#sqlalchemytrunktesttestlibconfigpy">sqlalchemy/trunk/test/testlib/config.py</a></li> </ul> <h3>Added Paths</h3> <ul> <li><a href="#sqlalchemytrunktesttestlibormpy">sqlalchemy/trunk/test/testlib/orm.py</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="sqlalchemytrunktesttestlib__init__py"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/test/testlib/__init__.py (3696 => 3697)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/test/testlib/__init__.py 2007-10-31 19:53:27 UTC (rev 3696) +++ sqlalchemy/trunk/test/testlib/__init__.py 2007-10-31 23:49:09 UTC (rev 3697) </span><span class="lines">@@ -5,6 +5,7 @@ </span><span class="cx"> </span><span class="cx"> import testlib.config </span><span class="cx"> from testlib.schema import Table, Column </span><ins>+from testlib.orm import mapper </ins><span class="cx"> import testlib.testing as testing </span><span class="cx"> from testlib.testing import PersistTest, AssertMixin, ORMTest, SQLCompileTest </span><span class="cx"> import testlib.profiling as profiling </span><span class="lines">@@ -12,6 +13,7 @@ </span><span class="cx"> </span><span class="cx"> </span><span class="cx"> __all__ = ('testing', </span><ins>+ 'mapper', </ins><span class="cx"> 'Table', 'Column', </span><span class="cx"> 'PersistTest', 'AssertMixin', 'ORMTest', 'SQLCompileTest', </span><span class="cx"> 'profiling', 'engines') </span></span></pre></div> <a id="sqlalchemytrunktesttestlibconfigpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/test/testlib/config.py (3696 => 3697)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/test/testlib/config.py 2007-10-31 19:53:27 UTC (rev 3696) +++ sqlalchemy/trunk/test/testlib/config.py 2007-10-31 23:49:09 UTC (rev 3697) </span><span class="lines">@@ -74,7 +74,7 @@ </span><span class="cx"> atexit.register(_stop) </span><span class="cx"> coverage.erase() </span><span class="cx"> coverage.start() </span><del>- </del><ins>+ </ins><span class="cx"> def _list_dbs(*args): </span><span class="cx"> print "Available --db options (use --dburi to override)" </span><span class="cx"> for macro in sorted(file_config.options('db')): </span><span class="lines">@@ -114,6 +114,12 @@ </span><span class="cx"> opt("--reversetop", action="store_true", dest="reversetop", default=False, </span><span class="cx"> help="Reverse the collection ordering for topological sorts (helps " </span><span class="cx"> "reveal dependency issues)") </span><ins>+opt("--unhashable", action="store_true", dest="unhashable", default=False, + help="Disallow SQLAlchemy from performing a hash() on mapped test objects.") +opt("--noncomparable", action="store_true", dest="noncomparable", default=False, + help="Disallow SQLAlchemy from performing == on mapped test objects.") +opt("--truthless", action="store_true", dest="truthless", default=False, + help="Disallow SQLAlchemy from truth-evaluating mapped test objects.") </ins><span class="cx"> opt("--serverside", action="callback", callback=_server_side_cursors, </span><span class="cx"> help="Turn on server side cursors for PG") </span><span class="cx"> opt("--mysql-engine", action="store", dest="mysql_engine", default=None, </span></span></pre></div> <a id="sqlalchemytrunktesttestlibormpy"></a> <div class="addfile"><h4>Added: sqlalchemy/trunk/test/testlib/orm.py (0 => 3697)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/test/testlib/orm.py (rev 0) +++ sqlalchemy/trunk/test/testlib/orm.py 2007-10-31 23:49:09 UTC (rev 3697) </span><span class="lines">@@ -0,0 +1,49 @@ </span><ins>+import testbase +from testlib import config +import inspect +orm = None + +__all__ = 'mapper', + + +def _make_blocker(method_name, fallback): + def method(self, *args, **kw): + frame_r = None + try: + frame_r = inspect.stack()[1] + module = frame_r[0].f_globals.get('__name__', '') + + type_ = type(self) + + if not module.startswith('sqlalchemy'): + supermeth = getattr(super(type_, self), method_name, None) + if supermeth is None or supermeth.im_func is method: + return fallback(self, *args, **kw) + else: + return supermeth(*args, **kw) + else: + raise AssertionError( + "%s.%s called in %s, line %s in %s" % ( + type_.__name__, method_name, module, frame_r[2], frame_r[3])) + finally: + del frame_r + method.__name__ = method_name + return method + +def mapper(type_, *args, **kw): + global orm + if orm is None: + from sqlalchemy import orm + + forbidden = [ + ('__hash__', 'unhashable', None), + ('__eq__', 'noncomparable', lambda s, x, y: x is y), + ('__nonzero__', 'truthless', lambda s: 1), ] + + if type_.__bases__ == (object,): + for method_name, option, fallback in forbidden: + if (getattr(config.options, option, False) and + method_name not in type_.__dict__): + setattr(type_, method_name, _make_blocker(method_name, fallback)) + + return orm.mapper(type_, *args, **kw) </ins><span class="cx">Property changes on: sqlalchemy/trunk/test/testlib/orm.py </span><span class="cx">___________________________________________________________________ </span><span class="cx">Name: svn:eol-style </span><span class="cx"> + native </span></span></pre> </div> </div> </body> </html> |