WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit e1bab67

Browse files
committed
🧪 Add conditional coverage pragmas if possible
These are version-dependent but are sometimes applied to conditionals checking the deps versions. They won't work perfectly but it's a start.
1 parent 1ff958c commit e1bab67

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

piptools/build.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@
2020

2121
from .utils import copy_install_requirement, install_req_from_line
2222

23-
if sys.version_info >= (3, 11):
23+
if sys.version_info >= (3, 11): # pragma: >=3.11 cover
2424
import tomllib
25-
else:
25+
else: # pragma: <3.11 cover
2626
import tomli as tomllib
2727

2828
PYPROJECT_TOML = "pyproject.toml"
2929

3030
_T = TypeVar("_T")
3131

3232

33-
if sys.version_info >= (3, 10):
33+
if sys.version_info >= (3, 10): # pragma: >=3.10 cover
3434
from importlib.metadata import PackageMetadata
35-
else:
35+
else: # pragma: <3.10 cover
3636

3737
class PackageMetadata(Protocol):
3838
@overload

piptools/utils.py

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

1515
from click.core import ParameterSource
1616

17-
if sys.version_info >= (3, 11):
17+
if sys.version_info >= (3, 11): # pragma: >=3.11 cover
1818
import tomllib
19-
else:
19+
else: # pragma: <3.11 cover
2020
import tomli as tomllib
2121

2222
import click
@@ -510,7 +510,7 @@ def copy_install_requirement(
510510
}
511511
kwargs.update(extra_kwargs)
512512

513-
if PIP_VERSION[:2] <= (23, 0):
513+
if PIP_VERSION[:2] <= (23, 0): # pragma: <3.12 cover
514514
kwargs["install_options"] = template.install_options
515515

516516
# Original link does not belong to install requirements constructor,
@@ -763,8 +763,8 @@ def is_path_relative_to(path1: Path, path2: Path) -> bool:
763763
"""Return True if ``path1`` is relative to ``path2``."""
764764
# TODO: remove this function in favor of Path.is_relative_to()
765765
# when we drop support for Python 3.8
766-
try:
766+
try: # pragma: >=3.9 cover
767767
path1.relative_to(path2)
768-
except ValueError:
768+
except ValueError: # pragma: <3.9 cover
769769
return False
770770
return True

tests/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def base_resolver(depcache):
211211
@pytest.fixture
212212
def from_line():
213213
def _from_line(*args, **kwargs):
214-
if PIP_VERSION[:2] <= (23, 0):
214+
if PIP_VERSION[:2] <= (23, 0): # pragma: <3.12 cover
215215
hash_options = kwargs.pop("hash_options", {})
216216
options = kwargs.pop("options", {})
217217
options["hashes"] = hash_options
@@ -228,7 +228,8 @@ def from_editable():
228228

229229
@pytest.fixture
230230
def runner():
231-
if Version(version_of("click")) < Version("8.2"):
231+
# Coverage is excluded because we only test with the latest Click
232+
if Version(version_of("click")) < Version("8.2"): # pragma: no cover
232233
cli_runner = CliRunner(mix_stderr=False)
233234
else:
234235
cli_runner = CliRunner()

tests/test_cli_compile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3422,9 +3422,9 @@ def test_pass_pip_cache_to_pip_args(tmpdir, runner, current_resolver):
34223422
# TODO: Remove hack once testing only on v23.3+
34233423
pip_current_version = get_pip_version_for_python_executable(sys.executable)
34243424
pip_breaking_version = Version("23.3.dev0")
3425-
if pip_current_version >= pip_breaking_version:
3425+
if pip_current_version >= pip_breaking_version: # pragma: >=3.12 cover
34263426
pip_http_cache_dir = "http-v2"
3427-
else:
3427+
else: # pragma: <3.12 cover
34283428
pip_http_cache_dir = "http"
34293429
assert os.listdir(os.path.join(str(cache_dir), pip_http_cache_dir))
34303430

@@ -4017,7 +4017,7 @@ def test_second_order_requirements_relative_path_in_separate_dir(
40174017
output_path = test_files_collection.get_path_to("requirements2.in")
40184018

40194019
# for older pip versions, recompute the output path to be relative to the input path
4020-
if not pip_produces_absolute_paths:
4020+
if not pip_produces_absolute_paths: # FIXME: figure out how to cover piplowest
40214021
# traverse upwards to the root tmp dir, and append the output path to that
40224022
# similar to pathlib.Path.relative_to(..., walk_up=True)
40234023
relative_segments = len(pathlib.Path(input_path).parents) - 1

tests/test_sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def test_diff_should_not_uninstall(fake_dist):
175175
# on Python 3.12 and above, `ensurepip` and `venv` do not default to installing
176176
# 'setuptools' -- as such, `pip` changes behavior on many Python 3.12 environments
177177
# to use isolated builds
178-
if sys.version_info < (3, 12):
178+
if sys.version_info < (3, 12): # pragma: <3.12 cover
179179
ignored += (
180180
"setuptools==34.0.0",
181181
"wheel==0.29.0",

0 commit comments

Comments
 (0)