Completed
Push — develop ( 8ba6e7...644415 )
by Jace
01:48
created

CoveragePy   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%
Metric Value
wmc 3
dl 0
loc 16
rs 10
ccs 10
cts 10
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A match() 0 2 1
A run() 0 10 2
1
"""Plugins to extract coverage data from various formats."""
2
3 1
import os
4
5 1
import coverage
6
7 1
from .base import BasePlugin
8
9
10 1
def get_coverage():
11
    """Find a matching coverage plugin and use it to extract coverage data."""
12 1
    cwd = os.getcwd()
13
14 1
    for cls in BasePlugin.__subclasses__():  # pylint: disable=no-member
15 1
        plugin = cls()
16 1
        if plugin.match(cwd):
17 1
            break
18
    else:
19
        raise RuntimeError("No coverage data found in the current directory.")
20
21 1
    percentage = plugin.run(cwd)
22
23 1
    return round(percentage, 1)
24
25
26 1
class CoveragePy(BasePlugin):
27
    """Coverage extracter for the coverage.py format."""
28
29 1
    def match(self, cwd):
30 1
        return '.coverage' in os.listdir(cwd)
31
32 1
    def run(self, cwd):
33 1
        os.chdir(cwd)
34
35 1
        cov = coverage.Coverage()
0 ignored issues
show
Bug introduced by
The Module coverage does not seem to have a member named Coverage.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
36 1
        cov.load()
37
38 1
        with open(os.devnull, 'w') as ignore:
39 1
            total = cov.report(file=ignore)
40
41
        return total
42