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

get_coverage()   A

Complexity

Conditions 4

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4.0218
Metric Value
dl 0
loc 14
rs 9.2
ccs 8
cts 9
cp 0.8889
cc 4
crap 4.0218
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