summaryrefslogtreecommitdiff
path: root/coverage/noseplugin.py
blob: b2bf9b5a1a130476dea4e3665f3556dc648ecb51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import logging
import unittest, os
from nose.plugins import Plugin
import sys

from coverage.testplugin import CoverageTestWrapper, options as coverage_opts

log = logging.getLogger(__name__)


class Coverage(Plugin):
    """
    Activate a coverage report using Ned Batchelder's coverage module.
    """
    
    name = "coverage_new"
    score = 1
    status = {}
    
    def options(self, parser, env):
        """
        Add options to command line.
        """
        Plugin.options(self, parser, env)
        for opt in coverage_opts:
            parser.add_option(opt)
    
    def configure(self, options, config):
        """
        Configure plugin.
        """
        try:
            self.status.pop('active')
        except KeyError:
            pass
        Plugin.configure(self, options, config)
        if self.enabled:
            try:
                import coverage
            except ImportError:
                log.error("Coverage not available: "
                          "unable to import coverage module")
                self.enabled = False
                return
        
        self.config = config
        self.status['active'] = True
        self.options = options
        
    def begin(self):
        """
        Begin recording coverage information.
        """
        log.debug("Coverage begin")
        # Load the runner and start it up
        self.coverage = CoverageTestWrapper(self.options)
        self.coverage.start()
        
    def report(self, stream):
        """
        Output code coverage report.
        """
        log.debug("Coverage report")
        stream.write("Processing Coverage...")
        # finish up with coverage
        self.coverage.finish(stream)