]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix coverage again- try really hard not to load anything from lib/ until after the...
authorJason Kirtland <jek@discorporate.us>
Fri, 27 Jul 2007 20:21:36 +0000 (20:21 +0000)
committerJason Kirtland <jek@discorporate.us>
Fri, 27 Jul 2007 20:21:36 +0000 (20:21 +0000)
test/testlib/config.py
test/testlib/profiling.py
test/testlib/schema.py
test/testlib/testing.py

index f05cda46d3bed690fed5954f03f31c00beb2c239..987832b11c3973715a71a5e3919ca85de78fde03 100644 (file)
@@ -1,3 +1,4 @@
+import testbase
 import optparse, os, sys, ConfigParser, StringIO
 logging, require = None, None
 
index 697df4ea2e99857b2b320fac35606ae1dbd1789e..efcc1340fbafed46942703793e83ddb70f687092 100644 (file)
@@ -1,5 +1,6 @@
 """Profiling support for unit and performance tests."""
 
+import testbase
 from testlib.config import parser, post_configure
 import testlib.config
 
index a2fc912650962c8af15eb8e1fe74662b4e3b7145..6ca15bb6c4374695d9709ca24c4e2573dd0f723d 100644 (file)
@@ -1,5 +1,5 @@
 import testbase
-from sqlalchemy import schema
+schema = None
 
 __all__ = 'Table', 'Column',
 
@@ -8,6 +8,10 @@ table_options = {}
 def Table(*args, **kw):
     """A schema.Table wrapper/hook for dialect-specific tweaks."""
 
+    global schema
+    if schema is None:
+        from sqlalchemy import schema
+        
     test_opts = dict([(k,kw.pop(k)) for k in kw.keys()
                       if k.startswith('test_')])
 
@@ -23,6 +27,10 @@ def Table(*args, **kw):
 def Column(*args, **kw):
     """A schema.Column wrapper/hook for dialect-specific tweaks."""
 
+    global schema
+    if schema is None:
+        from sqlalchemy import schema
+
     # TODO: a Column that creates a Sequence automatically for PK columns,
     # which would help Oracle tests
     return schema.Column(*args, **kw)
index 213772e9e167975129c0f3f195137b80d5baa7e9..9b92f46d5c0acf3164bf1ead6ab16119e49b58b7 100644 (file)
@@ -2,11 +2,12 @@
 
 # monkeypatches unittest.TestLoader.suiteClass at import time
 
+import testbase
 import unittest, re, sys, os
 from cStringIO import StringIO
-from sqlalchemy import MetaData, sql
-from sqlalchemy.orm import clear_mappers
 import testlib.config as config
+sql, Metadata, clear_mappers = None, None, None
+
 
 __all__ = 'PersistTest', 'AssertMixin', 'ORMTest'
 
@@ -70,6 +71,10 @@ class ExecutionContextWrapper(object):
     can be tracked."""
     
     def __init__(self, ctx):
+        global sql
+        if sql is None:
+            from sqlalchemy import sql
+
         self.__dict__['ctx'] = ctx
     def __getattr__(self, key):
         return getattr(self.ctx, key)
@@ -228,7 +233,11 @@ class ORMTest(AssertMixin):
     keep_data = False
 
     def setUpAll(self):
-        global _otest_metadata
+        global MetaData, _otest_metadata
+
+        if MetaData is None:
+            from sqlalchemy import MetaData
+        
         _otest_metadata = MetaData(config.db)
         self.define_tables(_otest_metadata)
         _otest_metadata.create_all()
@@ -248,6 +257,9 @@ class ORMTest(AssertMixin):
         _otest_metadata.drop_all()
 
     def tearDown(self):
+        if clear_mappers is None:
+            from sqlalchemy.orm import clear_mappers
+
         if not self.keep_mappers:
             clear_mappers()
         if not self.keep_data:
@@ -305,30 +317,9 @@ class TTestSuite(unittest.TestSuite):
             return (exctype, excvalue, tb)
         return (exctype, excvalue, tb)
 
+# monkeypatch
 unittest.TestLoader.suiteClass = TTestSuite
 
-def _iter_covered_files():
-    import sqlalchemy
-    for rec in os.walk(os.path.dirname(sqlalchemy.__file__)):
-        for x in rec[2]:
-            if x.endswith('.py'):
-                yield os.path.join(rec[0], x)
-
-def cover(callable_, file_=None):
-    from testlib import coverage
-    coverage_client = coverage.the_coverage
-    coverage_client.get_ready()
-    coverage_client.exclude('#pragma[: ]+[nN][oO] [cC][oO][vV][eE][rR]')
-    coverage_client.erase()
-    coverage_client.start()
-    try:
-        return callable_()
-    finally:
-        coverage_client.stop()
-        coverage_client.save()
-        coverage_client.report(list(_iter_covered_files()),
-                               show_missing=False, ignore_errors=False,
-                               file=file_)
 
 class DevNullWriter(object):
     def write(self, msg):