[GRASS-SVN] r61199 - sandbox/wenzeslaus/gunittest
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jul 8 12:16:04 PDT 2014
Author: wenzeslaus
Date: 2014-07-08 12:16:04 -0700 (Tue, 08 Jul 2014)
New Revision: 61199
Modified:
sandbox/wenzeslaus/gunittest/case.py
sandbox/wenzeslaus/gunittest/reporters.py
Log:
gunittest: add SVN revision to main index with a link to Trac
Modified: sandbox/wenzeslaus/gunittest/case.py
===================================================================
--- sandbox/wenzeslaus/gunittest/case.py 2014-07-08 17:10:14 UTC (rev 61198)
+++ sandbox/wenzeslaus/gunittest/case.py 2014-07-08 19:16:04 UTC (rev 61199)
@@ -484,6 +484,7 @@
self.fail(self._formatMessage(msg, stdmsg))
+# TODO: add tests and documentation to methods which are using this function
def _module_from_parameters(module, **kwargs):
if kwargs:
if not isinstance(module, basestring):
Modified: sandbox/wenzeslaus/gunittest/reporters.py
===================================================================
--- sandbox/wenzeslaus/gunittest/reporters.py 2014-07-08 17:10:14 UTC (rev 61198)
+++ sandbox/wenzeslaus/gunittest/reporters.py 2014-07-08 19:16:04 UTC (rev 61199)
@@ -4,10 +4,26 @@
import sys
import datetime
import xml.sax.saxutils as saxutils
+import xml.etree.ElementTree as et
+import subprocess
-from utils import ensure_dir
+from .utils import ensure_dir
+def get_source_url(path, revision, line=None):
+ """
+
+ :param path: directory or file path relative to remote repository root
+ :param revision: SVN revision (should be a number)
+ :param line: line in the file (should be None for directories)
+ """
+ tracurl = 'http://trac.osgeo.org/grass/browser/'
+ if line:
+ return '{tracurl}{path}?rev={revision}#L{line}'.format(**locals())
+ else:
+ return '{tracurl}{path}?rev={revision}'.format(**locals())
+
+
def html_escape(text):
"""Escape ``'&'``, ``'<'``, and ``'>'`` in a string of data."""
return saxutils.escape(text)
@@ -36,6 +52,64 @@
return line
+def get_svn_revision():
+ """Get SVN revision number
+
+ :returns: SVN revision number as string or None if it is not possible to get
+ """
+ # TODO: here should be starting directory
+ # but now we are using current as starting
+ p = subprocess.Popen(['svnversion', '.'],
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ stdout, stderr = p.communicate()
+ rc = p.poll()
+ if not rc:
+ stdout = stdout.strip()
+ if stdout.endswith('M'):
+ stdout = stdout[:-1]
+ if ':' in stdout:
+ # the first one is the one of source code
+ stdout = stdout.split(':')[0]
+ return stdout
+ else:
+ return None
+
+
+def get_svn_info():
+ """Get important information from ``svn info``
+
+ :returns: SVN info as dictionary or None
+ if it is not possible to obtain it
+ """
+ try:
+ # TODO: introduce directory, not only current
+ p = subprocess.Popen(['svn', 'info', '.', '--xml'],
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ stdout, stderr = p.communicate()
+ rc = p.poll()
+ info = {}
+ if not rc:
+ root = et.fromstring(stdout)
+ # TODO: get also date if this make sense
+ # expecting only one <entry>
+ entry = root.find('entry')
+ info['revision'] = entry.get('revision')
+ info['url'] = entry.find('url').text
+ relurl = entry.find('relative-url').text
+ # relative path has ^ at the beginning
+ if relurl.startswith('^'):
+ relurl = relurl[1:]
+ info['relative-url'] = relurl
+ return info
+ # TODO: add this to svnversion function
+ except OSError as e:
+ import errno
+ # ignore No such file or directory
+ if e.errno != errno.ENOENT:
+ raise
+ return None
+
+
class GrassTestFilesReporter(object):
def __init__(self, results_dir):
@@ -46,16 +120,30 @@
self.main_index = open(os.path.join(results_dir, 'index.html'), 'w')
# this might be moved to some report start method
self.main_start_time = datetime.datetime.now()
+ svn_info = get_svn_info()
+ if not svn_info:
+ svn_text = ('<span style="font-size: 60%">'
+ 'SVN revision cannot be be obtained'
+ '</span>')
+ else:
+ url = get_source_url(path=svn_info['relative-url'],
+ revision=svn_info['revision'])
+ svn_text = ('SVN revision'
+ ' <a href="{url}">'
+ '{rev}</a>'
+ ).format(url=url, rev=svn_info['revision'])
self.main_index.write('<html><body>'
'<h1>Test results</h1>'
'{time:%Y-%m-%d %H:%M:%S}'
+ ' ({svn})'
'<table>'
'<thead><tr>'
'<th>Tested directory</th>'
'<th>Test file</th>'
'<th>Status</th>'
'</tr></thead><tbody>'.format(
- time=self.main_start_time))
+ time=self.main_start_time,
+ svn=svn_text))
self.file_start_time = None
self._start_file_test_called = False
More information about the grass-commit
mailing list