[GRASS-SVN] r61400 - grass/trunk/lib/python/gunittest

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jul 25 06:58:29 PDT 2014


Author: wenzeslaus
Date: 2014-07-25 06:58:29 -0700 (Fri, 25 Jul 2014)
New Revision: 61400

Modified:
   grass/trunk/lib/python/gunittest/invoker.py
   grass/trunk/lib/python/gunittest/reporters.py
Log:
gunittest: add function to obtain SVN authors and store test file authors to key-value summary

Modified: grass/trunk/lib/python/gunittest/invoker.py
===================================================================
--- grass/trunk/lib/python/gunittest/invoker.py	2014-07-25 09:57:16 UTC (rev 61399)
+++ grass/trunk/lib/python/gunittest/invoker.py	2014-07-25 13:58:29 UTC (rev 61400)
@@ -25,7 +25,7 @@
 from .loader import GrassTestLoader, discover_modules
 from .reporters import (GrassTestFilesMultiReporter,
                         GrassTestFilesTextReporter,
-                        GrassTestFilesHtmlReporter)
+                        GrassTestFilesHtmlReporter, get_svn_path_authors)
 from .utils import silent_rmtree, ensure_dir
 
 import grass.script.setup as gsetup
@@ -54,6 +54,7 @@
     return text
 
 
+# TODO: this might be more extend then update
 def update_keyval_file(filename, module, returncode):
     if os.path.exists(filename):
         with open(filename, 'r') as keyval_file:
@@ -61,12 +62,17 @@
     else:
         keyval = {}
 
+    # this is for one file
+    # TODO: testing authors are more appropriate stat for testsuite dir index
+    test_file_authors = get_svn_path_authors(module.abs_file_path)
+
     # always owerwrite name and ok
     keyval['name'] = module.name
     keyval['tested_dir'] = module.tested_dir
     if 'status' not in keyval.keys():
         keyval['status'] = 'failed' if returncode else 'passed'
     keyval['returncode'] = returncode
+    keyval['test_file_authors'] = test_file_authors
     with open(filename, 'w') as keyval_file:
         keyval_file.write(keyvalue_to_text(keyval))
     return keyval

Modified: grass/trunk/lib/python/gunittest/reporters.py
===================================================================
--- grass/trunk/lib/python/gunittest/reporters.py	2014-07-25 09:57:16 UTC (rev 61399)
+++ grass/trunk/lib/python/gunittest/reporters.py	2014-07-25 13:58:29 UTC (rev 61400)
@@ -131,6 +131,45 @@
     return None
 
 
+def years_ago(date, years):
+    # dateutil relative delte would be better but this is more portable
+    return date - datetime.timedelta(weeks=years * 52)
+
+
+# TODO: these functions should be called only if we know that svn is installed
+# this will simplify the functions, caller must handle it anyway
+def get_svn_path_authors(path, from_date=None):
+    """
+
+    :returns: a set of authors
+    """
+    if from_date is None:
+        # this is the SVN default for local copies
+        revision_range = 'BASE:1'
+    else:
+        revision_range = 'BASE:{%s}' % from_date
+    try:
+        # TODO: allow also usage of --limit
+        p = subprocess.Popen(['svn', 'log', '--xml',
+                              '--revision', revision_range, path],
+                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        stdout, stderr = p.communicate()
+        rc = p.poll()
+        if not rc:
+            root = et.fromstring(stdout)
+            # TODO: get also date if this make sense
+            # expecting only one <entry> element
+            author_nodes = root.iterfind('*/author')
+            authors = [n.text for n in author_nodes]
+            return set(authors)
+    except OSError as e:
+        import errno
+        # ignore No such file or directory
+        if e.errno != errno.ENOENT:
+            raise
+    return None
+
+
 class GrassTestFilesMultiReporter(object):
 
     def __init__(self, reporters, forgiving=False):
@@ -417,6 +456,7 @@
         self.wrap_stdstream_to_html(infile=stderr,
                                     outfile=os.path.join(cwd, 'stderr.html'),
                                     module=module, stream='stderr')
+
         file_index_path = os.path.join(cwd, 'index.html')
         file_index = open(file_index_path, 'w')
         file_index.write(
@@ -433,7 +473,8 @@
             '</body></html>'
             .format(
                 dur=self.file_time, m=module,
-                status=self.returncode_to_html_sentence(returncode)))
+                status=self.returncode_to_html_sentence(returncode),
+                ))
         file_index.close()
 
         if returncode:
@@ -484,7 +525,8 @@
                 .format(
                     d=module.tested_dir,
                     m=module.name))
-            num_failed = test_summary.get('failures', None)
+            num_failed = test_summary.get('failures', 0)
+            num_failed += test_summary.get('errors', 0)
             if num_failed:
                 if num_failed > 1:
                     text = ' ({f} tests failed)'



More information about the grass-commit mailing list