~vcs-imports/quotient/main

« back to all changes in this revision

Viewing changes to quotient/test/test_coverage.py

  • Committer: glyph
  • Date: 2003-10-26 23:44:25 UTC
  • Revision ID: Arch-1:unnamed@bazaar.ubuntu.com%series--4208--patch-749
whitespace

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
Test our code coverage.
 
3
"""
 
4
 
 
5
import time, sys, os
 
6
 
 
7
from twisted.trial import unittest, reporter
 
8
 
 
9
import quotient
 
10
from quotient.benchmarks import coverage
 
11
 
 
12
class CoverageTest(unittest.TestCase):
 
13
    def benchmarkCoverage(self):
 
14
        coverage.start()
 
15
        t = unittest.TestSuite()
 
16
        t.addPackage("quotient.test")
 
17
        t.run(reporter.MinimalReporter(sys.stdout))
 
18
        coverage.stop()
 
19
        exclude = ['test', 'benchmarks']
 
20
        totLines = 0
 
21
        uncoveredLines = 0
 
22
        for path, subdirs, filenames in os.walk(os.path.dirname(os.path.abspath(quotient.__file__))):
 
23
            if os.path.basename(path) not in exclude:
 
24
                for f in filenames:
 
25
                    if f.endswith('.py'):
 
26
                        module = os.path.join(path, f)                    
 
27
                        fname, statements, uncovered, _ = coverage.analysis(module)
 
28
                        totLines += len(statements)
 
29
                        uncoveredLines += len(uncovered)
 
30
            
 
31
        pctCovered = (1.0 - (uncoveredLines/float(totLines))) * 100
 
32
        self.recordStat({'testCoverage': (pctCovered, "percentage covered")})