Skip to content

Commit

Permalink
Support custom coverage data locations
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Sep 9, 2018
1 parent dc06c56 commit e76d2dc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision History

## 2.1 (unreleased)

- Added support for custom `coverage.py` data locations.

## 2.0 (2018-09-08)

- BREAKING: Renamed PyPI project to `coveragespace`.
Expand Down
7 changes: 5 additions & 2 deletions coveragespace/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _find_plugin(cwd, allow_missing=False):
if allow_missing:
return None

raise RuntimeError(msg + '.')
raise RuntimeError(msg)


def _launched_recently(path):
Expand All @@ -100,7 +100,10 @@ class CoveragePy(BasePlugin): # pylint: disable=no-init
"""Coverage extractor for the coverage.py format."""

def matches(self, cwd):
return '.coverage' in os.listdir(cwd)
return any((
'.coverage' in os.listdir(cwd),
'.coveragerc' in os.listdir(cwd),
))

def get_coverage(self, cwd):
os.chdir(cwd)
Expand Down
23 changes: 23 additions & 0 deletions coveragespace/tests/test_plugins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# pylint: disable=missing-docstring,unused-variable,unused-argument,expression-not-assigned,singleton-comparison

import os
import time

import pytest
Expand All @@ -23,6 +25,23 @@ def coveragepy_data(tmpdir):
with open("foobar.py", 'w') as stream:
pass
with open(".coverage", 'w') as stream:
stream.write("""
!coverage.py: This is a private format, don\'t read it directly!
{"arcs":{"foobar.py": [[-1, 2]]}}
""".strip())

@pytest.fixture
def coveragepy_data_custom(tmpdir):
cwd = tmpdir.chdir()
with open("foobar.py", 'w') as stream:
pass
with open(".coveragerc", 'w') as stream:
stream.write("""
[run]
data_file = .cache/coverage
""".strip())
os.makedirs('.cache')
with open(".cache/coverage", 'w') as stream:
stream.write("""
!coverage.py: This is a private format, don\'t read it directly!
{"arcs":{"foobar.py": [[-1, 3]]}}
Expand All @@ -32,6 +51,10 @@ def coveragepy_data(tmpdir):
def it_supports_coveragepy(coveragepy_data):
expect(get_coverage()) == 42.5

@patch('coverage.Coverage', MockCoverage)
def it_supports_coveragepy_with_custom_location(coveragepy_data_custom):
expect(get_coverage()) == 42.5


def describe_launched_recently():

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]

name = "coveragespace"
version = "2.0.0"
version = "2.1.0b1"
description = "A place to track your code coverage metrics."

license = "MIT"
Expand Down

0 comments on commit e76d2dc

Please sign in to comment.