Skip to content

Commit

Permalink
Add test_annotation_relative_paths for jazzband#1107
Browse files Browse the repository at this point in the history
  • Loading branch information
AndydeCleyre committed Jun 16, 2022
1 parent e496d34 commit b631521
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,58 @@ def test_annotate_option(pip_conf, runner, options, expected):
assert out.exit_code == 0


@pytest.mark.network
@pytest.mark.parametrize("to_stdout", (True, False))
@pytest.mark.parametrize(
"flags",
(
(),
("--write-relative-to-output",),
("--read-relative-to-input",),
("--write-relative-to-output", "--read-relative-to-input"),
),
)
@pytest.mark.parametrize(
("input_filename", "input_content", "expected"),
(
("requirements.in", "small-fake-a==0.1", " # via -r {}"),
(
"setup.py",
(
"from setuptools import setup\n"
"setup(name='fake-setuptools-a', install_requires=['small-fake-a==0.1'])"
),
" # via fake-setuptools-a ({})",
),
),
ids=("requirements.in", "setup.py"),
)
def test_annotation_relative_paths(
runner, tmp_path, input_filename, input_content, expected, flags, to_stdout
):
"""
Annotations referencing files use paths relative to the output file.
"""
run_dir = tmp_path

in_path = tmp_path / input_filename
in_path.write_text(input_content)

txt_path = tmp_path / "deeper" / "requirements.txt"
txt_path.parent.mkdir(parents=True, exist_ok=True)

output = "-" if to_stdout else str(txt_path)

with working_dir(run_dir):
out = runner.invoke(
cli,
["--find-links", MINIMAL_WHEELS_PATH, "-o", output, *flags, str(in_path)],
)
assert out.exit_code == 0
with working_dir(None if to_stdout else txt_path.parent):
assert expected.format(os.path.relpath(in_path)) in out.stderr


@pytest.mark.parametrize(
("option", "expected"),
(
Expand Down

0 comments on commit b631521

Please sign in to comment.