]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- coverage dumps out separate reports for individual packages
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 29 Mar 2009 20:23:05 +0000 (20:23 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 29 Mar 2009 20:23:05 +0000 (20:23 +0000)
- other coverage tips

README.unittests
test/profiling/alltests.py
test/testlib/config.py

index 4698494234b7db566b15831028947f1a99fe02a3..f70f6ab17751a02b0b2dc9fc6eb403ef1e8315e1 100644 (file)
@@ -131,6 +131,9 @@ statements that are missed with !, by running the coverage.py utility with the
 This will create a new annotated file ./lib/sqlalchemy/sql.py,cover. Pretty
 cool!
 
+BIG COVERAGE TIP !!!  There is an issue where existing .pyc files may
+store the incorrect filepaths, which will break the coverage system.  If
+coverage numbers are coming out as low/zero, try deleting all .pyc files.
 
 TESTING NEW DIALECTS
 --------------------
index 9f35007481bee92403d20f6c361d15fda0adb888..19401098c19117f4fdbefd1c8eca04e099112f41 100644 (file)
@@ -11,6 +11,9 @@ def suite():
         'profiling.zoomark_orm',
         )
     alltests = unittest.TestSuite()
+    if testenv.testlib.config.coverage_enabled:
+        return alltests
+        
     for name in modules_to_test:
         mod = __import__(name)
         for token in name.split('.')[1:]:
index ac9f397177b22aaad52291f43e75c204f37fcfeb..cef4c6e1dcf641808034fe455f8aaca1584d2a82 100644 (file)
@@ -9,6 +9,7 @@ db_label, db_url, db_opts = None, None, {}
 
 options = None
 file_config = None
+coverage_enabled = False
 
 base_config = """
 [db]
@@ -77,24 +78,50 @@ def _log(option, opt_str, value, parser):
     elif opt_str.endswith('-debug'):
         logging.getLogger(value).setLevel(logging.DEBUG)
 
-def _start_coverage(option, opt_str, value, parser):
+def _start_cumulative_coverage(option, opt_str, value, parser):
+    _start_coverage(option, opt_str, value, parser, erase=False)
+
+def _start_coverage(option, opt_str, value, parser, erase=True):
     import sys, atexit, coverage
     true_out = sys.stdout
-
-    def _iter_covered_files():
-        import sqlalchemy
-        for rec in os.walk(os.path.dirname(sqlalchemy.__file__)):
+    
+    global coverage_enabled
+    coverage_enabled = True
+    
+    def _iter_covered_files(mod, recursive=True):
+        
+        if recursive:
+            ff = os.walk
+        else:
+            ff = os.listdir
+            
+        for rec in ff(os.path.dirname(mod.__file__)):
             for x in rec[2]:
                 if x.endswith('.py'):
                     yield os.path.join(rec[0], x)
+            
     def _stop():
         coverage.stop()
         true_out.write("\nPreparing coverage report...\n")
-        coverage.report(list(_iter_covered_files()),
-                        show_missing=False, ignore_errors=False,
-                        file=true_out)
+
+        from sqlalchemy import sql, orm, engine, \
+                            ext, databases, log
+                        
+        import sqlalchemy
+        
+        for modset in [
+            _iter_covered_files(sqlalchemy, recursive=False),
+            _iter_covered_files(databases),
+            _iter_covered_files(engine),
+            _iter_covered_files(ext),
+            _iter_covered_files(orm),
+        ]:
+            coverage.report(list(modset),
+                            show_missing=False, ignore_errors=False,
+                            file=true_out)
     atexit.register(_stop)
-    coverage.erase()
+    if erase:
+        coverage.erase()
     coverage.start()
 
 def _list_dbs(*args):
@@ -151,6 +178,8 @@ opt("--table-option", action="append", dest="tableopts", default=[],
     help="Add a dialect-specific table option, key=value")
 opt("--coverage", action="callback", callback=_start_coverage,
     help="Dump a full coverage report after running tests")
+opt("--cumulative-coverage", action="callback", callback=_start_cumulative_coverage,
+    help="Like --coverage, but accumlate coverage into the current DB")
 opt("--profile", action="append", dest="profile_targets", default=[],
     help="Enable a named profile target (multiple OK.)")
 opt("--profile-sort", action="store", dest="profile_sort", default=None,