[GRASS-SVN] r61176 - sandbox/wenzeslaus/gunittest

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jul 7 14:39:42 PDT 2014


Author: wenzeslaus
Date: 2014-07-07 14:39:41 -0700 (Mon, 07 Jul 2014)
New Revision: 61176

Modified:
   sandbox/wenzeslaus/gunittest/main.py
Log:
gunittest: do code coverage only if package is available

Modified: sandbox/wenzeslaus/gunittest/main.py
===================================================================
--- sandbox/wenzeslaus/gunittest/main.py	2014-07-07 21:25:10 UTC (rev 61175)
+++ sandbox/wenzeslaus/gunittest/main.py	2014-07-07 21:39:41 UTC (rev 61176)
@@ -49,15 +49,23 @@
 def test():
     """Run a test of a module.
     """
-    import coverage
-    cov = coverage.coverage(omit="*testsuite*")
-    cov.start()
+    # TODO: put the link to to the report only if available
+    doing_coverage = False
+    try:
+        import coverage
+        doing_coverage = True
+        cov = coverage.coverage(omit="*testsuite*")
+        cov.start()
+    except ImportError:
+        pass
+        # TODO: add some message somewhere
 
     # TODO: enable passing omit to exclude also gunittest or nothing
     program = GrassTestProgram(module='__main__', exit_at_end=False, grass_location='all')
 
-    cov.stop()
-    cov.html_report(directory='testcodecoverage')
+    if doing_coverage:
+        cov.stop()
+        cov.html_report(directory='testcodecoverage')
 
     # TODO: is sys.exit the right thing here
     sys.exit(not program.result.wasSuccessful())
@@ -76,14 +84,21 @@
     Runs using::
         python main.py discovery [start_directory]
     """
-    import coverage
-    cov = coverage.coverage(omit="*testsuite*")
-    cov.start()
+    doing_coverage = False
+    try:
+        import coverage
+        doing_coverage = True
+        cov = coverage.coverage(omit="*testsuite*")
+        cov.start()
+    except ImportError:
+        pass
+        # TODO: add some message somewhere
 
     program = GrassTestProgram(grass_location='nc', exit_at_end=False)
 
-    cov.stop()
-    cov.html_report(directory='testcodecoverage')
+    if doing_coverage:
+        cov.stop()
+        cov.html_report(directory='testcodecoverage')
 
     sys.exit(not program.result.wasSuccessful())
 



More information about the grass-commit mailing list