Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Way to force package even if filepath exists #1026

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions coverage/config.py
Expand Up @@ -195,6 +195,7 @@ def __init__(self):
self.run_include = None
self.run_omit = None
self.source = None
self.source_pkgs = []
self.timid = False
self._crash = None

Expand Down Expand Up @@ -361,6 +362,7 @@ def copy(self):
('run_include', 'run:include', 'list'),
('run_omit', 'run:omit', 'list'),
('source', 'run:source', 'list'),
('source_pkgs', 'run:source_pkgs', 'list'),
('timid', 'run:timid', 'boolean'),
('_crash', 'run:_crash'),

Expand Down
4 changes: 2 additions & 2 deletions coverage/control.py
Expand Up @@ -99,7 +99,7 @@ def current(cls):
def __init__(
self, data_file=_DEFAULT_DATAFILE, data_suffix=None, cover_pylib=None,
auto_data=False, timid=None, branch=None, config_file=True,
source=None, omit=None, include=None, debug=None,
source=None, source_pkgs=None, omit=None, include=None, debug=None,
concurrency=None, check_preimported=False, context=None,
):
"""
Expand Down Expand Up @@ -188,7 +188,7 @@ def __init__(
config_file=config_file,
data_file=data_file, cover_pylib=cover_pylib, timid=timid,
branch=branch, parallel=bool_or_none(data_suffix),
source=source, run_omit=omit, run_include=include, debug=debug,
source=source, source_pkgs=source_pkgs, run_omit=omit, run_include=include, debug=debug,
report_omit=omit, report_include=include,
concurrency=concurrency, context=context,
)
Expand Down
1 change: 1 addition & 0 deletions coverage/inorout.py
Expand Up @@ -132,6 +132,7 @@ def __init__(self, warn, debug):

def configure(self, config):
"""Apply the configuration to get ready for decision-time."""
self.source_pkgs.extend(config.source_pkgs)
for src in config.source or []:
if os.path.isdir(src):
self.source.append(canonical_filename(src))
Expand Down
Empty file.
Empty file.
Empty file.
22 changes: 22 additions & 0 deletions tests/test_api.py
Expand Up @@ -926,6 +926,28 @@ def test_source_package_as_package_part_omitted(self):
self.filenames_not_in(lines, "p1b")
self.assertEqual(lines['p1c'], 0)

def test_ambigious_source_package_as_dir(self):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ambiguous was probably intended here!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# pkg1 is a directory and a pkg, since we cd into tests/modules/ambigious
self.chdir(self.nice_file(TESTS_DIR, 'modules', "ambigious"))
# pkg1 defaults to directory because tests/modules/ambigious/pkg1 exists
lines = self.coverage_usepkgs(source=["pkg1"])
self.assertEqual(
self.coverage_usepkgs(source=["pkg1"]),
{
u"__init__.py": 0, u"__init__": 0,
u"ambigious.py": 0, u"ambigious": 0,
},
)

def test_ambigious_source_package_as_package(self):
# pkg1 is a directory and a pkg, since we cd into tests/modules/ambigious
self.chdir(self.nice_file(TESTS_DIR, 'modules', "ambigious"))
lines = self.coverage_usepkgs(source_pkgs=["pkg1"])
self.filenames_in(lines, "p1a p1b")
self.filenames_not_in(lines, "p2a p2b othera otherb osa osb ambigious")
# Because source= was specified, we do search for unexecuted files.
self.assertEqual(lines['p1c'], 0)


class ReportIncludeOmitTest(IncludeOmitTestsMixin, CoverageTest):
"""Tests of the report include/omit functionality."""
Expand Down
2 changes: 2 additions & 0 deletions tests/test_config.py
Expand Up @@ -462,6 +462,7 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest):
; this omit is overriden by the omit from [report]
omit = twenty
source = myapp
source_pkgs = ned
plugins =
plugins.a_plugin
plugins.another
Expand Down Expand Up @@ -553,6 +554,7 @@ def assert_config_settings_are_correct(self, cov):
self.assertTrue(cov.config.parallel)
self.assertEqual(cov.config.concurrency, ["thread"])
self.assertEqual(cov.config.source, ["myapp"])
self.assertEqual(cov.config.source_pkgs, ["ned"])
self.assertEqual(cov.config.disable_warnings, ["abcd", "efgh"])

self.assertEqual(cov.get_exclude_list(), ["if 0:", r"pragma:?\s+no cover", "another_tab"])
Expand Down