Skip to content

Commit

Permalink
Try and fix the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysle committed Jul 16, 2023
1 parent 383fbd6 commit 401c5fd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion piptools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ def parse_config_file(
try:
piptools_config = {
cli_opts["--" + k].name: (
not v if k.startswith("no-") and isinstance(v, bool) else v
not v if k.startswith("no-") and not k == "no-index" and isinstance(v, bool) else v
)
for k, v in piptools_config.items()
}
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3002,13 +3002,13 @@ def test_raise_error_on_unknown_config_option(
out = runner.invoke(cli, [req_in.as_posix(), "--config", config_file.as_posix()])

assert out.exit_code == 2
assert "No such config key 'unknown_option'" in out.stderr
assert "No such config key 'unknown-option'" in out.stderr


def test_raise_error_on_invalid_config_option(
pip_conf, runner, tmp_path, make_config_file
):
config_file = make_config_file("dry-run", ["invalid", "value"])
config_file = make_config_file("dry_run", ["invalid", "value"])

req_in = tmp_path / "requirements.in"
req_in.touch()
Expand All @@ -3030,7 +3030,7 @@ def test_cli_boolean_flag_config_option_has_valid_context(
out = runner.invoke(cli, [req_in.as_posix(), "--config", config_file.as_posix()])

assert out.exit_code == 0
assert "No such config key 'no_annotate'." not in out.stderr
assert "No such config key 'no-annotate'." not in out.stderr


def test_invalid_cli_boolean_flag_config_option_captured(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def test_raise_error_on_unknown_config_option(run, runner, tmp_path, make_config
out = runner.invoke(cli, ["--config", config_file.as_posix()])

assert out.exit_code == 2
assert "No such config key 'unknown_option'" in out.stderr
assert "No such config key 'unknown-option'" in out.stderr


@mock.patch("piptools.sync.run")
Expand Down
14 changes: 9 additions & 5 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import shlex
import sys
from pathlib import Path
import itertools

import pip
import pytest
Expand All @@ -20,7 +21,6 @@
flat_map,
format_requirement,
format_specifier,
get_click_dest_for_option,
get_compile_command,
get_hashes_from_ireq,
get_pip_version_for_python_executable,
Expand Down Expand Up @@ -585,7 +585,7 @@ def test_get_sys_path_for_python_executable():
("pip-args", "changed"),
("pre", True),
("rebuild", True),
("extras", ["changed"]),
("extra", ["changed"]),
("all-extras", True),
("index-url", "changed"),
("header", False),
Expand Down Expand Up @@ -615,10 +615,15 @@ def test_callback_config_file_defaults(pyproject_param, new_default, make_config
# Create a "compile" run example pointing to the config file
ctx = Context(compile_cli)
ctx.params["src_files"] = (str(config_file),)
cli_opts = {
opt: option
for option in ctx.command.params
for opt in itertools.chain(option.opts, option.secondary_opts)
}
found_config_file = override_defaults_from_config_file(ctx, "config", None)
assert found_config_file == config_file
# Make sure the default has been updated
lookup_param = get_click_dest_for_option(pyproject_param)
lookup_param = cli_opts["--" + pyproject_param].name
assert ctx.default_map[lookup_param] == new_default


Expand Down Expand Up @@ -661,8 +666,7 @@ def test_callback_config_file_defaults_precedence(make_config_file):
found_config_file = override_defaults_from_config_file(ctx, "config", None)
# The pip-tools specific config file should take precedence over pyproject.toml
assert found_config_file == piptools_config_file
lookup_param = get_click_dest_for_option("newline")
assert ctx.default_map[lookup_param] == "LF"
assert ctx.default_map["newline"] == "LF"


def test_callback_config_file_defaults_unreadable_toml(make_config_file):
Expand Down

0 comments on commit 401c5fd

Please sign in to comment.