[Checkins] SVN: z3c.coverage/trunk/ Add a test suite. Add a --web option to coveragediff.py. Bump the version

Marius Gedminas marius at pov.lt
Thu Jul 19 11:30:51 EDT 2007


Log message for revision 78161:
  Add a test suite.  Add a --web option to coveragediff.py.  Bump the version
  number to 0.2.1.  Add a changelog to README.txt.
  
  

Changed:
  U   z3c.coverage/trunk/README.txt
  U   z3c.coverage/trunk/setup.py
  U   z3c.coverage/trunk/src/z3c/coverage/coveragediff.py
  A   z3c.coverage/trunk/src/z3c/coverage/coveragediff.txt
  A   z3c.coverage/trunk/src/z3c/coverage/tests.py

-=-
Modified: z3c.coverage/trunk/README.txt
===================================================================
--- z3c.coverage/trunk/README.txt	2007-07-19 15:29:02 UTC (rev 78160)
+++ z3c.coverage/trunk/README.txt	2007-07-19 15:30:51 UTC (rev 78161)
@@ -1,3 +1,6 @@
+z3c.coverage
+============
+
 This package produces a nice HTML representation of the coverage data
 generated by the Zope test runner.
 
@@ -3,2 +6,23 @@
 It also has a script to check for differences in coverage and report
 any regressions (increases in the number of untested lines).
+
+
+Changes
+-------
+
+0.2.1
+~~~~~
+
+- Added the --web option to coveragediff.
+- Added a test suite.
+
+0.2.0
+~~~~~
+
+- Added coveragediff.py.
+
+0.1.0
+-----
+
+- Initial release of coveragereport.py.
+

Modified: z3c.coverage/trunk/setup.py
===================================================================
--- z3c.coverage/trunk/setup.py	2007-07-19 15:29:02 UTC (rev 78160)
+++ z3c.coverage/trunk/setup.py	2007-07-19 15:30:51 UTC (rev 78161)
@@ -23,7 +23,7 @@
 
 setup (
     name='z3c.coverage',
-    version='0.2.0',
+    version='0.2.1',
     author = "Zope Community",
     author_email = "zope3-dev at zope.org",
     description = "A script to visualize coverage reports via HTML",

Modified: z3c.coverage/trunk/src/z3c/coverage/coveragediff.py
===================================================================
--- z3c.coverage/trunk/src/z3c/coverage/coveragediff.py	2007-07-19 15:29:02 UTC (rev 78160)
+++ z3c.coverage/trunk/src/z3c/coverage/coveragediff.py	2007-07-19 15:30:51 UTC (rev 78161)
@@ -36,6 +36,16 @@
 except NameError:
     # python 2.4 compatibility
     def any(list):
+        """Return True if bool(x) is True for any x in the iterable.
+
+            >>> any([1, 'yes', 0, None])
+            True
+            >>> any([0, None, ''])
+            False
+            >>> any([])
+            False
+
+        """
         for item in list:
             if item:
                 return True
@@ -177,6 +187,37 @@
     return string
 
 
+def urljoin(base, *suburls):
+    """Join base URL and zero or more subURLs.
+
+    This function is best described by examples:
+
+        >>> urljoin('http://example.com')
+        'http://example.com/'
+
+        >>> urljoin('http://example.com/')
+        'http://example.com/'
+
+        >>> urljoin('http://example.com', 'a', 'b/c', 'd')
+        'http://example.com/a/b/c/d'
+
+        >>> urljoin('http://example.com/', 'a', 'b/c', 'd')
+        'http://example.com/a/b/c/d'
+
+        >>> urljoin('http://example.com/a', 'b/c', 'd')
+        'http://example.com/a/b/c/d'
+
+        >>> urljoin('http://example.com/a/', 'b/c', 'd')
+        'http://example.com/a/b/c/d'
+
+    SubURLs should not contain trailing or leading slashes (with one exception:
+    the last subURL may have a trailing slash).  SubURLs should not be empty.
+    """
+    if not base.endswith('/'):
+        base += '/'
+    return base + '/'.join(suburls)
+
+
 class MailSender(object):
     """Send emails over SMTP"""
 
@@ -202,12 +243,14 @@
 class ReportEmailer(object):
     """Warning collector and emailer."""
 
-    def __init__(self, from_addr, to_addr, subject, mailer=None):
+    def __init__(self, from_addr, to_addr, subject, web_url=None,
+                 mailer=None):
         if not mailer:
             mailer = MailSender()
         self.from_addr = from_addr
         self.to_addr = to_addr
         self.subject = subject
+        self.web_url = web_url
         self.mailer = mailer
         self.warnings = []
 
@@ -215,6 +258,9 @@
         """Warn about test coverage regression."""
         module = strip(os.path.basename(filename), '.cover')
         self.warnings.append('%s: %s' % (module, message))
+        if self.web_url:
+            url = urljoin(self.web_url, module + '.html')
+            self.warnings.append('See ' + url + '\n')
 
     def send(self):
         """Send the warnings (if any)."""
@@ -224,7 +270,6 @@
                                    body)
 
 
-
 def selftest():
     """Run all unit tests in this module."""
     import doctest
@@ -252,6 +297,9 @@
     parser.add_option('--subject', metavar='SUBJECT',
                       default='Unit test coverage regression',
                       help='set the email subject')
+    parser.add_option('--web-url', metavar='BASEURL', dest='web_url',
+                      help='include hyperlinks to HTML-ized coverage'
+                           ' reports at a given URL')
     parser.add_option('--selftest', help='run integrity tests',
                       action='store_true')
     opts, args = parser.parse_args()
@@ -262,7 +310,7 @@
         parser.error("wrong number of arguments")
     olddir, newdir = args
     if opts.email:
-        mailer = ReportEmailer(opts.sender, opts.email, opts.subject)
+        mailer = ReportEmailer(opts.sender, opts.email, opts.subject, opts.web_url)
         warnfunc = mailer.warn
     else:
         warnfunc = warn

Added: z3c.coverage/trunk/src/z3c/coverage/coveragediff.txt
===================================================================
--- z3c.coverage/trunk/src/z3c/coverage/coveragediff.txt	                        (rev 0)
+++ z3c.coverage/trunk/src/z3c/coverage/coveragediff.txt	2007-07-19 15:30:51 UTC (rev 78161)
@@ -0,0 +1,91 @@
+coveragediff
+============
+
+``coveragediff`` is a tool that can be used to compare two directories with
+coverage reports.  It reports regressions, that is, increases in the number
+of untested code.
+
+This document describes the internals of ``coveragediff``.  It also acts as
+a test suite.
+
+
+ReportEmailer
+-------------
+
+The ``ReportEmailer`` class collects warnings and sends them via email.
+
+You pass the basic email parameters (sender, recipient and subject line)
+to the constructor:
+
+    >>> from z3c.coverage.coveragediff import ReportEmailer
+    >>> emailer = ReportEmailer('Some Bot <bot at example.com>',
+    ...                         'Maintainer <m at example.com>',
+    ...                         'Test coverage regressions')
+
+You add warnings about Python modules by passing the filename of the
+coverage file and the message
+
+    >>> emailer.warn('/tmp/coverage/z3c.coverage.coveragediff.cover',
+    ...              '3 new untested lines')
+    >>> emailer.warn('/tmp/coverage/z3c.coverage.coveragereport.cover',
+    ...              '2 new untested lines')
+
+Finally you send the email.  Since it wouldn't be a good idea to actually
+send emails from the test suite, we'll use a stub MailSender class:
+
+    >>> class FakeMailSender(object):
+    ...     def send_email(self, from_addr, to_addr, subject, body):
+    ...         print "From:", from_addr
+    ...         print "To:", to_addr
+    ...         print "Subject:", subject
+    ...         print "---"
+    ...         print body
+    >>> emailer.mailer = FakeMailSender()
+    >>> emailer.send()
+    From: Some Bot <bot at example.com>
+    To: Maintainer <m at example.com>
+    Subject: Test coverage regressions
+    ---
+    z3c.coverage.coveragediff: 3 new untested lines
+    z3c.coverage.coveragereport: 2 new untested lines
+
+
+Links to web pages
+~~~~~~~~~~~~~~~~~~
+
+Report emailer can also include links to web pages with the coverage reports
+(e.g. the ones you can get from ``coveragereport``).
+
+    >>> emailer = ReportEmailer('Some Bot <bot at example.com>',
+    ...                         'Maintainer <m at example.com>',
+    ...                         'Test coverage regressions',
+    ...                         web_url='http://example.com/coverage',
+    ...                         mailer=FakeMailSender())
+    >>> emailer.warn('/tmp/coverage/z3c.coverage.coveragediff.cover',
+    ...              '3 new untested lines')
+    >>> emailer.warn('/tmp/coverage/z3c.coverage.coveragereport.cover',
+    ...              '2 new untested lines')
+    >>> emailer.send()
+    From: Some Bot <bot at example.com>
+    To: Maintainer <m at example.com>
+    Subject: Test coverage regressions
+    ---
+    z3c.coverage.coveragediff: 3 new untested lines
+    See http://example.com/coverage/z3c.coverage.coveragediff.html
+    <BLANKLINE>
+    z3c.coverage.coveragereport: 2 new untested lines
+    See http://example.com/coverage/z3c.coverage.coveragereport.html
+    <BLANKLINE>
+
+
+Empty reports
+~~~~~~~~~~~~~
+
+Empty reports are not sent out.
+
+    >>> emailer = ReportEmailer('Some Bot <bot at example.com>',
+    ...                         'Maintainer <m at example.com>',
+    ...                         'Test coverage regressions',
+    ...                         mailer=FakeMailSender())
+    >>> emailer.send()
+


Property changes on: z3c.coverage/trunk/src/z3c/coverage/coveragediff.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.coverage/trunk/src/z3c/coverage/tests.py
===================================================================
--- z3c.coverage/trunk/src/z3c/coverage/tests.py	                        (rev 0)
+++ z3c.coverage/trunk/src/z3c/coverage/tests.py	2007-07-19 15:30:51 UTC (rev 78161)
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+"""
+Test suite for z3c.coverage
+"""
+
+import unittest
+
+# prefer the zope.testing version, if it is available
+try:
+    from zope.testing import doctest
+except ImportError:
+    import doctest
+
+
+def test_suite():
+    return unittest.TestSuite([
+                doctest.DocFileSuite('coveragediff.txt'),
+                doctest.DocTestSuite('z3c.coverage.coveragediff'),
+                doctest.DocTestSuite('z3c.coverage.coveragereport'),
+                               ])
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')


Property changes on: z3c.coverage/trunk/src/z3c/coverage/tests.py
___________________________________________________________________
Name: svn:keywords
   + Id



More information about the Checkins mailing list