Skip to content

Commit 3f32685

Browse files
committed
Merge branch 'coverage' into 'master'
Clean up coverage settings by using the new plugin system in coverage 4.5 See merge request python-devs/importlib_resources!54
2 parents 2e1e34f + 70c5f2e commit 3f32685

File tree

5 files changed

+32
-13
lines changed

5 files changed

+32
-13
lines changed

coverage.ini

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,20 @@ omit =
55
setup*
66
.tox/*/lib/python*/site-packages/*
77
*/tests/*.py
8-
/tmp/*
9-
/private/var/folders/*
108
*/testing/*.py
119
importlib_resources/_py${OMIT}.py
1210
importlib_resources/__init__.py
1311
importlib_resources/_compat.py
1412
importlib_resources/abc.py
13+
plugins =
14+
coverplug
1515

1616
[report]
1717
exclude_lines =
1818
pragma: nocover
19-
pragma: missed
20-
pragma: ge${GEVER}
21-
pragma: le${LEVER}
2219
raise NotImplementedError
2320
raise AssertionError
21+
pragma: FIXME
2422
assert\s
2523

2624
[paths]

coverplug.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Coverage plugin to add exclude lines based on the Python version."""
2+
3+
import sys
4+
5+
from coverage import CoveragePlugin
6+
7+
8+
class MyConfigPlugin(CoveragePlugin):
9+
def configure(self, config):
10+
opt_name = 'report:exclude_lines'
11+
exclude_lines = config.get_option(opt_name)
12+
# Python >= 3.6 has os.PathLike.
13+
if sys.version_info >= (3, 6):
14+
exclude_lines.append('pragma: >=36')
15+
else:
16+
exclude_lines.append('pragma: <=35')
17+
config.set_option(opt_name, exclude_lines)
18+
19+
20+
def coverage_init(reg, options):
21+
reg.add_configurer(MyConfigPlugin())

importlib_resources/_py2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def is_resource(package, name):
169169
# ENOTDIR, but then we'd have to depend on another external
170170
# library since Python 2 doesn't have unittest.mock. It's not
171171
# worth it.
172-
raise # pragma: ge3
172+
raise # pragma: nocover
173173
return False
174174
if name not in package_contents:
175175
return False
@@ -232,7 +232,7 @@ def contents(package):
232232
# ENOTDIR, but then we'd have to depend on another external
233233
# library since Python 2 doesn't have unittest.mock. It's not
234234
# worth it.
235-
raise # pragma: ge3
235+
raise # pragma: nocover
236236
# The package is probably in a zip file.
237237
archive_path = getattr(package.__loader__, 'archive', None)
238238
if archive_path is None:

importlib_resources/_py3.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
Package = Union[ModuleType, str]
2020
if sys.version_info >= (3, 6):
21-
Resource = Union[str, os.PathLike] # pragma: ge35
21+
Resource = Union[str, os.PathLike] # pragma: <=35
2222
else:
23-
Resource = str # pragma: le35
23+
Resource = str # pragma: >=36
2424

2525

2626
def _get_package(package) -> ModuleType:
@@ -173,7 +173,7 @@ def path(package: Package, resource: Resource) -> Iterator[Path]:
173173
# resource_path() raises FileNotFoundError.
174174
package_directory = Path(package.__spec__.origin).parent
175175
file_path = package_directory / resource
176-
if file_path.exists():
176+
if file_path.exists(): # pragma: FIXME
177177
yield file_path
178178
else:
179179
with open_binary(package, resource) as fp:
@@ -213,10 +213,10 @@ def is_resource(package: Package, name: str) -> bool:
213213
# contents doesn't necessarily mean it's a resource. Directories are not
214214
# resources, so let's try to find out if it's a directory or not.
215215
path = Path(package.__spec__.origin).parent / name
216-
if path.is_file():
216+
if path.is_file(): # pragma: FIXME
217217
return True
218218
if path.is_dir():
219-
return False
219+
return False # pragma: FIXME
220220
# If it's not a file and it's not a directory, what is it? Well, this
221221
# means the file doesn't exist on the file system, so it probably lives
222222
# inside a zip file. We have to crack open the zip, look at its table of

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ passenv =
2020
LANG*
2121
LC_*
2222
deps =
23-
cov,diffcov: coverage
23+
cov,diffcov: coverage>=4.5
2424
diffcov: diff_cover
2525
setenv =
2626
cov: COVERAGE_PROCESS_START={[coverage]rcfile}

0 commit comments

Comments
 (0)