]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- use class name by itself in flush warnings to prevent overflow of warnings registry
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 29 Nov 2010 23:38:44 +0000 (18:38 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 29 Nov 2010 23:38:44 +0000 (18:38 -0500)
- test suite swaps out warnings.warn with warnings.warn_explicit, to solve warnings registry issue
- explicitly disallow functions from inside test.bootstrap, test.lib being interpreted as tests

lib/sqlalchemy/orm/dependency.py
lib/sqlalchemy/orm/unitofwork.py
lib/sqlalchemy/orm/util.py
lib/sqlalchemy/util/langhelpers.py
test/bootstrap/noseplugin.py
test/lib/testing.py

index e57b1575ac7bc89d5fca62d327d4c86b109d3977..b9958f77584698af23f02e44ba922796033c4c59 100644 (file)
@@ -727,9 +727,9 @@ class ManyToOneDP(DependencyProcessor):
             child is not None and \
             not uowcommit.session._contains_state(child):
             util.warn(
-                "Child %s not in session, %s "
+                "Object of type %s not in session, %s "
                 "operation along '%s' won't proceed" % 
-                (mapperutil.state_str(child), operation, self.prop))
+                (mapperutil.state_class_str(child), operation, self.prop))
             return
             
         if clearkeys or child is None:
@@ -1097,9 +1097,9 @@ class ManyToManyDP(DependencyProcessor):
         if child is not None and not uowcommit.session._contains_state(child):
             if not child.deleted:
                 util.warn(
-                    "Child %s not in session, %s "
+                    "Object of type %s not in session, %s "
                     "operation along '%s' won't proceed" % 
-                    (mapperutil.state_str(child), operation, self.prop))
+                    (mapperutil.state_class_str(child), operation, self.prop))
             return False
             
         self._verify_canload(child)
index 8f7475c4b7daccdcf42fa3cad154aa23000486a6..db20acb90bb14582d4308ddf2942d067ecea2725 100644 (file)
@@ -180,9 +180,9 @@ class UOWTransaction(object):
                             operation=None, prop=None):
         if not self.session._contains_state(state):
             if not state.deleted and operation is not None:
-                util.warn("Object %s not in session, %s operation "
+                util.warn("Object of type %s not in session, %s operation "
                             "along '%s' will not proceed" % 
-                            (mapperutil.state_str(state), operation, prop))
+                            (mapperutil.state_class_str(state), operation, prop))
             return False
 
         if state not in self.states:
index 4661b4b000efdebcc04ad9e87e246b9c0b9b1df9..23154bd4e18bb67c099d63dbcadc09c6a1e3991c 100644 (file)
@@ -595,6 +595,14 @@ def state_str(state):
     else:
         return '<%s at 0x%x>' % (state.class_.__name__, id(state.obj()))
 
+def state_class_str(state):
+    """Return a string describing an instance's class via its InstanceState."""
+
+    if state is None:
+        return "None"
+    else:
+        return '<%s>' % (state.class_.__name__, )
+    
 def attribute_str(instance, attribute):
     return instance_str(instance) + "." + attribute
 
index 5c12cf67bef1738f6aee0a1f6de53c2d771da950..68d9709f82fec9cdcb9838ff8c10caeebff33f03 100644 (file)
@@ -684,6 +684,17 @@ def warn_exception(func, *args, **kwargs):
 
 
 def warn(msg, stacklevel=3):
+    """Issue a warning.
+    
+    If msg is a string, :class:`.exc.SAWarning` is used as 
+    the category.
+    
+    .. note:: This function is swapped out when the test suite
+       runs, with a compatible version that uses 
+       warnings.warn_explicit, so that the warnings registry can
+       be controlled.
+       
+    """
     if isinstance(msg, basestring):
         warnings.warn(msg, exc.SAWarning, stacklevel=stacklevel)
     else:
index c2a152aa6ecb9e4156f26a62125e3136bdce36fc..838ad0042a353584ae23bc6a1e024e2e9dc3bf52 100644 (file)
@@ -94,7 +94,12 @@ class NoseSQLAlchemy(Plugin):
         
     def describeTest(self, test):
         return ""
-        
+    
+    def wantFunction(self, fn):
+        if fn.__module__.startswith('test.lib') or \
+            fn.__module__.startswith('test.bootstrap'):
+            return False
+            
     def wantClass(self, cls):
         """Return true if you want the main test selector to collect
         tests from this class, false if you don't, and None if you don't
index da2a3dfd30eab13ef322bdf64bc8c098d4623a80..00b65c6e3aad56f326c0ec8a1d767bad12889a64 100644 (file)
@@ -13,7 +13,8 @@ from test.lib import assertsql, util as testutil
 from sqlalchemy.util import function_named, py3k
 from engines import drop_all_tables
 
-from sqlalchemy import exc as sa_exc, util, types as sqltypes, schema, pool, orm
+from sqlalchemy import exc as sa_exc, util, types as sqltypes, schema, \
+    pool, orm
 from sqlalchemy.engine import default
 from nose import SkipTest
 
@@ -333,7 +334,6 @@ def emits_warning(*messages):
     strings; these will be matched to the root of the warning description by
     warnings.filterwarnings().
     """
-
     # TODO: it would be nice to assert that a named warning was
     # emitted. should work with some monkeypatching of warnings,
     # and may work on non-CPython if they keep to the spirit of
@@ -427,16 +427,26 @@ def uses_deprecated(*messages):
         return function_named(safe, fn.__name__)
     return decorate
 
+def testing_warn(msg, stacklevel=3):
+    """Replaces sqlalchemy.util.warn during tests."""
+    
+    filename = "test.lib.testing"
+    lineno = 1
+    if isinstance(msg, basestring):
+        warnings.warn_explicit(msg, sa_exc.SAWarning, filename, lineno)
+    else:
+        warnings.warn_explicit(msg, filename, lineno)
+
 def resetwarnings():
     """Reset warning behavior to testing defaults."""
-
+    
+    util.warn = util.langhelpers.warn = testing_warn
+    
     warnings.filterwarnings('ignore',
                             category=sa_exc.SAPendingDeprecationWarning) 
     warnings.filterwarnings('error', category=sa_exc.SADeprecationWarning)
     warnings.filterwarnings('error', category=sa_exc.SAWarning)
 
-#    warnings.simplefilter('error')
-
 
 def global_cleanup_assertions():
     """Check things that have to be finalized at the end of a test suite.