summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt15
-rw-r--r--coverage/control.py7
-rw-r--r--test/test_api.py18
3 files changed, 33 insertions, 7 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 3c84daf..4d9bf1e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -17,10 +17,13 @@ Version 3.5
- The ``--omit`` and ``--include`` switches now interpret their values more
usefully. If the value starts with a wildcard character, it is used as-is.
If it does not, it is interpreted relative to the current directory.
- Closes `issue 121`.
+ Closes `issue 121`_.
+
+- The ``coverage()`` constructor accepts single strings for the ``omit=`` and
+ ``include=`` arguments, adapting to a common error in programmatic use.
- Modules can now be run directly using ``coverage run -m modulename``, to
- mirror Python's ``-m`` flag. Closes `issue 95_`, thanks, Brandon Rhodes.
+ mirror Python's ``-m`` flag. Closes `issue 95`_, thanks, Brandon Rhodes.
- A little bit of Jython support: `coverage run` can now measure Jython
execution by adapting when $py.class files are traced. Thanks, Adi Roiban.
@@ -40,19 +43,19 @@ Version 3.5
- Source files are now opened with Python 3.2's ``tokenize.open()`` where
possible, to get the best handling of Python source files with encodings.
- Closes `issue 107`, thanks, Brett Cannon.
+ Closes `issue 107`_, thanks, Brett Cannon.
- Syntax errors in supposed Python files can now be ignored during reporting
- with the ``-i`` switch just like other source errors. Closes `issue 115`.
+ with the ``-i`` switch just like other source errors. Closes `issue 115`_.
- Installation from source now succeeds on machines without a C compiler,
- closing `issue 80`.
+ closing `issue 80`_.
- Coverage.py can now be run directly from a working tree by specifying
the directory name to python: ``python coverage_py_working_dir run ...``.
Thanks, Brett Cannon.
-- Internally, files are now closed explicitly, fixing `issue 104`. Thanks,
+- Internally, files are now closed explicitly, fixing `issue 104`_. Thanks,
Brett Cannon.
.. _issue 80: https://bitbucket.org/ned/coveragepy/issue/80/is-there-a-duck-typing-way-to-know-we-cant
diff --git a/coverage/control.py b/coverage/control.py
index dd65661..cee073e 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -64,7 +64,8 @@ class coverage(object):
measured.
`include` and `omit` are lists of filename patterns. Files that match
- `include` will be measured, files that match `omit` will not.
+ `include` will be measured, files that match `omit` will not. Each
+ will also accept a single string argument.
"""
from coverage import __version__
@@ -95,6 +96,10 @@ class coverage(object):
self.config.data_file = env_data_file
# 4: from constructor arguments:
+ if isinstance(omit, string_class):
+ omit = [omit]
+ if isinstance(include, string_class):
+ include = [include]
self.config.from_args(
data_file=data_file, cover_pylib=cover_pylib, timid=timid,
branch=branch, parallel=bool_or_none(data_suffix),
diff --git a/test/test_api.py b/test/test_api.py
index 31d8988..0a0aabf 100644
--- a/test/test_api.py
+++ b/test/test_api.py
@@ -388,6 +388,15 @@ class SourceOmitIncludeTest(CoverageTest):
"p1b.py p1c.py p2b.py otherb.py osb.py"
)
+ def test_include_as_string(self):
+ lines = self.coverage_usepkgs_summary(include="*a.py")
+ self.filenames_in_summary(lines,
+ "p1a.py p2a.py othera.py osa.py"
+ )
+ self.filenames_not_in_summary(lines,
+ "p1b.py p1c.py p2b.py otherb.py osb.py"
+ )
+
def test_omit(self):
lines = self.coverage_usepkgs_summary(omit=["*/p1a.py"])
self.filenames_in_summary(lines,
@@ -406,6 +415,15 @@ class SourceOmitIncludeTest(CoverageTest):
"p1a.py p1c.py p2a.py othera.py osa.py"
)
+ def test_omit_as_string(self):
+ lines = self.coverage_usepkgs_summary(omit="*a.py")
+ self.filenames_in_summary(lines,
+ "p1b.py p2b.py otherb.py osb.py"
+ )
+ self.filenames_not_in_summary(lines,
+ "p1a.py p1c.py p2a.py othera.py osa.py"
+ )
+
def test_omit_and_include(self):
lines = self.coverage_usepkgs_summary(
include=["*/p1*"], omit=["*/p1a.py"]