Skip to content

Commit ecd6ab1

Browse files
authored
Create Way to force package even if filepath exists (#1026)
Fixes: #268
1 parent 39e6d1d commit ecd6ab1

File tree

8 files changed

+29
-2
lines changed

8 files changed

+29
-2
lines changed

coverage/config.py

+2
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ def __init__(self):
195195
self.run_include = None
196196
self.run_omit = None
197197
self.source = None
198+
self.source_pkgs = []
198199
self.timid = False
199200
self._crash = None
200201

@@ -361,6 +362,7 @@ def copy(self):
361362
('run_include', 'run:include', 'list'),
362363
('run_omit', 'run:omit', 'list'),
363364
('source', 'run:source', 'list'),
365+
('source_pkgs', 'run:source_pkgs', 'list'),
364366
('timid', 'run:timid', 'boolean'),
365367
('_crash', 'run:_crash'),
366368

coverage/control.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def current(cls):
9999
def __init__(
100100
self, data_file=_DEFAULT_DATAFILE, data_suffix=None, cover_pylib=None,
101101
auto_data=False, timid=None, branch=None, config_file=True,
102-
source=None, omit=None, include=None, debug=None,
102+
source=None, source_pkgs=None, omit=None, include=None, debug=None,
103103
concurrency=None, check_preimported=False, context=None,
104104
):
105105
"""
@@ -188,7 +188,7 @@ def __init__(
188188
config_file=config_file,
189189
data_file=data_file, cover_pylib=cover_pylib, timid=timid,
190190
branch=branch, parallel=bool_or_none(data_suffix),
191-
source=source, run_omit=omit, run_include=include, debug=debug,
191+
source=source, source_pkgs=source_pkgs, run_omit=omit, run_include=include, debug=debug,
192192
report_omit=omit, report_include=include,
193193
concurrency=concurrency, context=context,
194194
)

coverage/inorout.py

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def __init__(self, warn, debug):
132132

133133
def configure(self, config):
134134
"""Apply the configuration to get ready for decision-time."""
135+
self.source_pkgs.extend(config.source_pkgs)
135136
for src in config.source or []:
136137
if os.path.isdir(src):
137138
self.source.append(canonical_filename(src))

tests/modules/ambigious/__init__.py

Whitespace-only changes.

tests/modules/ambigious/pkg1/__init__.py

Whitespace-only changes.

tests/modules/ambigious/pkg1/ambigious.py

Whitespace-only changes.

tests/test_api.py

+22
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,28 @@ def test_source_package_as_package_part_omitted(self):
935935
self.filenames_not_in(lines, "p1b")
936936
self.assertEqual(lines['p1c'], 0)
937937

938+
def test_ambigious_source_package_as_dir(self):
939+
# pkg1 is a directory and a pkg, since we cd into tests/modules/ambigious
940+
self.chdir(self.nice_file(TESTS_DIR, 'modules', "ambigious"))
941+
# pkg1 defaults to directory because tests/modules/ambigious/pkg1 exists
942+
lines = self.coverage_usepkgs(source=["pkg1"])
943+
self.assertEqual(
944+
self.coverage_usepkgs(source=["pkg1"]),
945+
{
946+
u"__init__.py": 0, u"__init__": 0,
947+
u"ambigious.py": 0, u"ambigious": 0,
948+
},
949+
)
950+
951+
def test_ambigious_source_package_as_package(self):
952+
# pkg1 is a directory and a pkg, since we cd into tests/modules/ambigious
953+
self.chdir(self.nice_file(TESTS_DIR, 'modules', "ambigious"))
954+
lines = self.coverage_usepkgs(source_pkgs=["pkg1"])
955+
self.filenames_in(lines, "p1a p1b")
956+
self.filenames_not_in(lines, "p2a p2b othera otherb osa osb ambigious")
957+
# Because source= was specified, we do search for unexecuted files.
958+
self.assertEqual(lines['p1c'], 0)
959+
938960

939961
class ReportIncludeOmitTest(IncludeOmitTestsMixin, CoverageTest):
940962
"""Tests of the report include/omit functionality."""

tests/test_config.py

+2
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest):
462462
; this omit is overriden by the omit from [report]
463463
omit = twenty
464464
source = myapp
465+
source_pkgs = ned
465466
plugins =
466467
plugins.a_plugin
467468
plugins.another
@@ -553,6 +554,7 @@ def assert_config_settings_are_correct(self, cov):
553554
self.assertTrue(cov.config.parallel)
554555
self.assertEqual(cov.config.concurrency, ["thread"])
555556
self.assertEqual(cov.config.source, ["myapp"])
557+
self.assertEqual(cov.config.source_pkgs, ["ned"])
556558
self.assertEqual(cov.config.disable_warnings, ["abcd", "efgh"])
557559

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

0 commit comments

Comments
 (0)