Skip to content

Commit

Permalink
cover --annotation-style=line with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AndydeCleyre committed Sep 20, 2021
1 parent d28dfbe commit 368e1e4
Showing 1 changed file with 72 additions and 8 deletions.
80 changes: 72 additions & 8 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ def test_generate_hashes_with_annotations(runner):


@pytest.mark.network
def test_generate_hashes_with_long_annotations(runner):
def test_generate_hashes_with_split_style_annotations(runner):
with open("requirements.in", "w") as fp:
fp.write("Django==1.11.29\n")
fp.write("django-debug-toolbar==1.11\n")
Expand All @@ -900,7 +900,7 @@ def test_generate_hashes_with_long_annotations(runner):
fp.write("pytz==2020.4\n")
fp.write("sqlparse==0.3.1\n")

out = runner.invoke(cli, ["--generate-hashes"])
out = runner.invoke(cli, ["--generate-hashes", "--annotation-style", "split"])
assert out.stderr == dedent(
f"""\
#
Expand Down Expand Up @@ -946,6 +946,54 @@ def test_generate_hashes_with_long_annotations(runner):
)


@pytest.mark.network
def test_generate_hashes_with_line_style_annotations(runner):
with open("requirements.in", "w") as fp:
fp.write("Django==1.11.29\n")
fp.write("django-debug-toolbar==1.11\n")
fp.write("django-storages==1.9.1\n")
fp.write("django-taggit==0.24.0\n")
fp.write("pytz==2020.4\n")
fp.write("sqlparse==0.3.1\n")

out = runner.invoke(cli, ["--generate-hashes", "--annotation-style", "line"])
assert out.stderr == dedent(
f"""\
#
# This file is autogenerated by pip-compile with python \
{sys.version_info.major}.{sys.version_info.minor}
# To update, run:
#
# pip-compile --annotation-style=line --generate-hashes
#
django==1.11.29 \\
--hash=sha256:014e3392058d94f40569206a24523ce254d55ad2f9f46c6550b0fe2e4f94cf3f \\
--hash=sha256:4200aefb6678019a0acf0005cd14cfce3a5e6b9b90d06145fcdd2e474ad4329c
# via -r requirements.in, django-debug-toolbar, django-storages, django-taggit
django-debug-toolbar==1.11 \\
--hash=sha256:89d75b60c65db363fb24688d977e5fbf0e73386c67acf562d278402a10fc3736 \\
--hash=sha256:c2b0134119a624f4ac9398b44f8e28a01c7686ac350a12a74793f3dd57a9eea0
# via -r requirements.in
django-storages==1.9.1 \\
--hash=sha256:3103991c2ee8cef8a2ff096709973ffe7106183d211a79f22cf855f33533d924 \\
--hash=sha256:a59e9923cbce7068792f75344ed7727021ee4ac20f227cf17297d0d03d141e91
# via -r requirements.in
django-taggit==0.24.0 \\
--hash=sha256:710b4d15ec1996550cc68a0abbc41903ca7d832540e52b1336e6858737e410d8 \\
--hash=sha256:bb8f27684814cd1414b2af75b857b5e26a40912631904038a7ecacd2bfafc3ac
# via -r requirements.in
pytz==2020.4 \\
--hash=sha256:3e6b7dd2d1e0a59084bcee14a17af60c5c562cdc16d828e8eba2e683d3a7e268 \\
--hash=sha256:5c55e189b682d420be27c6995ba6edce0c0a77dd67bfbe2ae6607134d5851ffd
# via -r requirements.in, django
sqlparse==0.3.1 \\
--hash=sha256:022fb9c87b524d1f7862b3037e541f68597a730a8843245c349fc93e1643dc4e \\
--hash=sha256:e162203737712307dfe78860cc56c8da8a852ab2ee33750e33aeadf38d12c548
# via -r requirements.in, django-debug-toolbar
"""
)


def test_filter_pip_markers(pip_conf, runner):
"""
Check that pip-compile works with pip environment markers (PEP496)
Expand Down Expand Up @@ -1078,10 +1126,10 @@ def test_multiple_input_files_without_output_file(runner):


@pytest.mark.parametrize(
("option", "expected"),
("options", "expected"),
(
pytest.param(
"--annotate",
("--annotate",),
f"""\
#
# This file is autogenerated by pip-compile with python \
Expand All @@ -1101,7 +1149,23 @@ def test_multiple_input_files_without_output_file(runner):
id="annotate",
),
pytest.param(
"--no-annotate",
("--annotate", "--annotation-style", "line"),
f"""\
#
# This file is autogenerated by pip-compile with python \
{sys.version_info.major}.{sys.version_info.minor}
# To update, run:
#
# pip-compile --annotation-style=line --no-emit-find-links
#
small-fake-a==0.1 # via -c constraints.txt, small-fake-with-deps
small-fake-with-deps==0.1 # via -r requirements.in
Dry-run, so nothing updated.
""",
id="annotate line style",
),
pytest.param(
("--no-annotate",),
f"""\
#
# This file is autogenerated by pip-compile with python \
Expand All @@ -1118,17 +1182,17 @@ def test_multiple_input_files_without_output_file(runner):
),
),
)
def test_annotate_option(pip_conf, runner, option, expected):
def test_annotate_option(pip_conf, runner, options, expected):
"""
The output lines has have annotations if option is turned on.
The output lines have annotations if the option is turned on.
"""
with open("constraints.txt", "w") as constraints_in:
constraints_in.write("small-fake-a==0.1")
with open("requirements.in", "w") as req_in:
req_in.write("-c constraints.txt\n")
req_in.write("small_fake_with_deps")

out = runner.invoke(cli, [option, "-n", "--no-emit-find-links"])
out = runner.invoke(cli, [*options, "-n", "--no-emit-find-links"])

assert out.stderr == dedent(expected)
assert out.exit_code == 0
Expand Down

0 comments on commit 368e1e4

Please sign in to comment.