=====================
Test Coverage Reports
=====================

The main objective of this package is to convert the text-based coverage
output into an HTML coverage report. This is done by specifying the directory
of the test reports and the desired output directory.

Luckily we already have the text input ready:

    >>> import os
    >>> import z3c.coverage
    >>> inputDir = os.path.join(
    ...     os.path.dirname(z3c.coverage.__file__), 'sampleinput')

Let's create a temporary directory for the output

    >>> import tempfile, shutil
    >>> tempDir = tempfile.mkdtemp(prefix='tmp-z3c.coverage-report-')

The output directory will be created if it doesn't exist already

    >>> outputDir = os.path.join(tempDir, 'report')

We can now create the coverage report as follows:

    >>> from z3c.coverage import coveragereport
    >>> coveragereport.main([inputDir, outputDir, '--quiet'])

Looking at the output directory, we now see several files:

    >>> print '\n'.join(sorted(os.listdir(outputDir)))
    all.html
    z3c.coverage.__init__.html
    z3c.coverage.coveragediff.html
    z3c.coverage.coveragereport.html
    z3c.coverage.html
    z3c.html

Let's clean up

    >>> shutil.rmtree(tempDir)


coverage.py support
~~~~~~~~~~~~~~~~~~~

We also support coverage reports generated by coverage.py 

    >>> inputFile = os.path.join(
    ...     os.path.dirname(z3c.coverage.__file__), 'sampleinput.pickle')

    >>> from z3c.coverage import coveragereport
    >>> coveragereport.main([inputFile, outputDir, '-q',
    ...                      '--strip-prefix=/home/mg/src/z3c.coverage/src'])
    >>> print '\n'.join(sorted(os.listdir(outputDir)))
    all.html
    z3c.coverage.__init__.html
    z3c.coverage.coveragediff.html
    z3c.coverage.coveragereport.html
    z3c.coverage.html
    z3c.html


`coveragereport.py` is a script
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For convenience you can download the ``coveragereport.py`` module and run it
as a script:

  >>> import sys
  >>> sys.argv = ['coveragereport', inputDir, outputDir, '--quiet']

  >>> script_file = os.path.join(
  ...     z3c.coverage.__path__[0], 'coveragereport.py')

  >>> execfile(script_file, dict(__name__='__main__'))

Let's clean up

  >>> shutil.rmtree(tempDir)

