Harbor format: 871 coding_baseline tasks (part 48)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- tasks/pallets__click.fde47b4b.combine_file__1dmpgrck/tests/trusted-inventory.json +167 -0
- tasks/pallets__click.fde47b4b.combine_file__1dmpgrck/tests/trusted/tests/typing/typing_progressbar.py +24 -0
- tasks/pallets__click.fde47b4b.combine_file__1dmpgrck/tests/trusted/tests/typing/typing_simple_example.py +17 -0
- tasks/pallets__click.fde47b4b.combine_file__1dmpgrck/tests/trusted/tests/typing/typing_version_option.py +16 -0
- tasks/pallets__click.fde47b4b.combine_file__1dmpgrck/tests/trusted/tox.ini +55 -0
- tasks/pallets__click.fde47b4b.combine_file__1dmpgrck/validation/canaries/first-hunk-only.sh +35 -0
- tasks/pallets__click.fde47b4b.combine_file__1dmpgrck/validation/canaries/original-bug.sh +3 -0
- tasks/pallets__click.fde47b4b.combine_file__1dmpgrck/validation/openenv.json +27 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/LICENSE.source +28 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/adapter.json +127 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/dependency-setup.sh +8 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/environment/Dockerfile +3 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/instruction.md +46 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/metadata.json +744 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/provenance.json +88 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/provided-gold.diff +95 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/solution/solve.sh +101 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/task.toml +23 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/check_pytest.py +91 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/expected-panels.json +485 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/grade.py +128 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/panel-config.json +23 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/test.sh +6 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted-inventory.json +167 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/pyproject.toml +102 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/conftest.py +8 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_arguments.py +436 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_basic.py +575 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_chain.py +245 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_command_decorators.py +92 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_commands.py +407 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_compat.py +10 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_context.py +545 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_custom_classes.py +112 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_defaults.py +86 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_formatting.py +368 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_imports.py +69 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_info_dict.py +275 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_normalization.py +38 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_options.py +1017 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_parser.py +32 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_shell_completion.py +442 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_termui.py +487 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_testing.py +430 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_types.py +252 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_utils.py +653 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/typing/typing_aliased_group.py +46 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/typing/typing_confirmation_option.py +14 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/typing/typing_group_kw_options.py +11 -0
- tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/typing/typing_help_option.py +13 -0
tasks/pallets__click.fde47b4b.combine_file__1dmpgrck/tests/trusted-inventory.json
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"directory_roots": [
|
| 3 |
+
"tests"
|
| 4 |
+
],
|
| 5 |
+
"files": {
|
| 6 |
+
"pyproject.toml": {
|
| 7 |
+
"bytes": 2059,
|
| 8 |
+
"mode": 420,
|
| 9 |
+
"sha256": "9613cb0037dd9c13abedfa097793fd78f78560ac605a995852caa3be5cb1d6ae"
|
| 10 |
+
},
|
| 11 |
+
"tests/conftest.py": {
|
| 12 |
+
"bytes": 131,
|
| 13 |
+
"mode": 420,
|
| 14 |
+
"sha256": "192be82444d6048fd222e2d73cd5c3bec768d65c6e10c0ffc230f307f363590b"
|
| 15 |
+
},
|
| 16 |
+
"tests/test_arguments.py": {
|
| 17 |
+
"bytes": 11929,
|
| 18 |
+
"mode": 420,
|
| 19 |
+
"sha256": "f8ebd354ffba0e644bf3516d379955ff4894d63137a8fd2b491f2478c48382bd"
|
| 20 |
+
},
|
| 21 |
+
"tests/test_basic.py": {
|
| 22 |
+
"bytes": 15452,
|
| 23 |
+
"mode": 420,
|
| 24 |
+
"sha256": "a22bb35be13097b31e48a9f352019c0319d88dc8e5c62bf8031f9a92d8408bb3"
|
| 25 |
+
},
|
| 26 |
+
"tests/test_chain.py": {
|
| 27 |
+
"bytes": 5786,
|
| 28 |
+
"mode": 420,
|
| 29 |
+
"sha256": "32247d8a208c84e571a89e87cbce389cc9aac08e98ece741c7d53fca0c63d881"
|
| 30 |
+
},
|
| 31 |
+
"tests/test_command_decorators.py": {
|
| 32 |
+
"bytes": 1880,
|
| 33 |
+
"mode": 420,
|
| 34 |
+
"sha256": "234ede359da2839923af2436056680bab68bdba622bf596452bbfbe1e1cfd6fa"
|
| 35 |
+
},
|
| 36 |
+
"tests/test_commands.py": {
|
| 37 |
+
"bytes": 11043,
|
| 38 |
+
"mode": 420,
|
| 39 |
+
"sha256": "9775d56ac9b373b3c6a1e92705b13f4ed5fc43a0bf984becd988437e815d2119"
|
| 40 |
+
},
|
| 41 |
+
"tests/test_compat.py": {
|
| 42 |
+
"bytes": 307,
|
| 43 |
+
"mode": 420,
|
| 44 |
+
"sha256": "5373454ca4b0718b079d1f49f1d153b0535686d6cf1f25291253b2dff1b5e748"
|
| 45 |
+
},
|
| 46 |
+
"tests/test_context.py": {
|
| 47 |
+
"bytes": 14294,
|
| 48 |
+
"mode": 420,
|
| 49 |
+
"sha256": "e7ab67acb6d3d413b8ecc1ad6d1ef64ac4ce49173b805b2f7d5851c81d680e54"
|
| 50 |
+
},
|
| 51 |
+
"tests/test_custom_classes.py": {
|
| 52 |
+
"bytes": 3022,
|
| 53 |
+
"mode": 420,
|
| 54 |
+
"sha256": "9d403c3b960ca927170645dcb144db33eb42c705208b6fa3b235c54889eee8e0"
|
| 55 |
+
},
|
| 56 |
+
"tests/test_defaults.py": {
|
| 57 |
+
"bytes": 2531,
|
| 58 |
+
"mode": 420,
|
| 59 |
+
"sha256": "1f835d0531beaaaa0fe99dcfa57635fa5e2cc9edd85d279a3f854a85551c8e45"
|
| 60 |
+
},
|
| 61 |
+
"tests/test_formatting.py": {
|
| 62 |
+
"bytes": 9413,
|
| 63 |
+
"mode": 420,
|
| 64 |
+
"sha256": "79c8ed50dd4507ef491a49dc7a69f2db65ee740f07fad31a09ff03b568141192"
|
| 65 |
+
},
|
| 66 |
+
"tests/test_imports.py": {
|
| 67 |
+
"bytes": 1414,
|
| 68 |
+
"mode": 420,
|
| 69 |
+
"sha256": "60310370edf02e88a94bb7f63c5a73eee7386b0b7adf6aa3e52633c073d7f929"
|
| 70 |
+
},
|
| 71 |
+
"tests/test_info_dict.py": {
|
| 72 |
+
"bytes": 7932,
|
| 73 |
+
"mode": 420,
|
| 74 |
+
"sha256": "544256b586fb50143e795b2f8023f5799e84ffdb57e34dcef31e386e6537098c"
|
| 75 |
+
},
|
| 76 |
+
"tests/test_normalization.py": {
|
| 77 |
+
"bytes": 955,
|
| 78 |
+
"mode": 420,
|
| 79 |
+
"sha256": "fab82963f1fe5a747429e324186e7fd34f7ef08a7ac20092c1899db3263f2376"
|
| 80 |
+
},
|
| 81 |
+
"tests/test_options.py": {
|
| 82 |
+
"bytes": 31807,
|
| 83 |
+
"mode": 420,
|
| 84 |
+
"sha256": "e18616e6a0a2e6f2bd9d8cb612c6ab0b36eafb1b6b3ac28fd374ffde3b4bfad3"
|
| 85 |
+
},
|
| 86 |
+
"tests/test_parser.py": {
|
| 87 |
+
"bytes": 915,
|
| 88 |
+
"mode": 420,
|
| 89 |
+
"sha256": "9e3a95fb896166e23bb8070de55a7d81a72a95c0b4909da659e54274b1615069"
|
| 90 |
+
},
|
| 91 |
+
"tests/test_shell_completion.py": {
|
| 92 |
+
"bytes": 14917,
|
| 93 |
+
"mode": 420,
|
| 94 |
+
"sha256": "faec10970de514a4a78abafb81573876f4ff383754969ef75954a6b850bf0f9e"
|
| 95 |
+
},
|
| 96 |
+
"tests/test_termui.py": {
|
| 97 |
+
"bytes": 15248,
|
| 98 |
+
"mode": 420,
|
| 99 |
+
"sha256": "14788f5acdeb49f9d3f8fefe2144bfad501a4519a2b42eec246c95746256fcf6"
|
| 100 |
+
},
|
| 101 |
+
"tests/test_testing.py": {
|
| 102 |
+
"bytes": 11102,
|
| 103 |
+
"mode": 420,
|
| 104 |
+
"sha256": "c63512960c836d493f11c143df8e35d43aa94b8b34af3516f97ca68bf348e369"
|
| 105 |
+
},
|
| 106 |
+
"tests/test_types.py": {
|
| 107 |
+
"bytes": 7807,
|
| 108 |
+
"mode": 420,
|
| 109 |
+
"sha256": "1d48de1f111b92b78153377db2286f6f37c306ded4b6b8c76111037743d7c8a1"
|
| 110 |
+
},
|
| 111 |
+
"tests/test_utils.py": {
|
| 112 |
+
"bytes": 21175,
|
| 113 |
+
"mode": 420,
|
| 114 |
+
"sha256": "424dee62b698503934682408d9aa28fe5be890f27ae4c92c7ab666ea9d2060f1"
|
| 115 |
+
},
|
| 116 |
+
"tests/typing/typing_aliased_group.py": {
|
| 117 |
+
"bytes": 1191,
|
| 118 |
+
"mode": 420,
|
| 119 |
+
"sha256": "0908243a61416433ff835ad517abf2a0f95275686dbb2fdb965579115a1f3189"
|
| 120 |
+
},
|
| 121 |
+
"tests/typing/typing_confirmation_option.py": {
|
| 122 |
+
"bytes": 326,
|
| 123 |
+
"mode": 420,
|
| 124 |
+
"sha256": "b25f68dfcef2a29c707aba78b722e46abe53a8e384e925f051e90e9e1e9d97c5"
|
| 125 |
+
},
|
| 126 |
+
"tests/typing/typing_group_kw_options.py": {
|
| 127 |
+
"bytes": 156,
|
| 128 |
+
"mode": 420,
|
| 129 |
+
"sha256": "53cb7ef7d78a9bbb1cd82e2e841a2b43efd1bf6b235ae002398eaf3272ecc87e"
|
| 130 |
+
},
|
| 131 |
+
"tests/typing/typing_help_option.py": {
|
| 132 |
+
"bytes": 262,
|
| 133 |
+
"mode": 420,
|
| 134 |
+
"sha256": "5dc1e21f7d8f4328f9c050294e1fc5964dd6b5ec01964b0f371fc2750721e545"
|
| 135 |
+
},
|
| 136 |
+
"tests/typing/typing_options.py": {
|
| 137 |
+
"bytes": 390,
|
| 138 |
+
"mode": 420,
|
| 139 |
+
"sha256": "a6579a3777cd63a27b030be925dcc1f38acbb46daf22f4092a3aee50b18ba043"
|
| 140 |
+
},
|
| 141 |
+
"tests/typing/typing_password_option.py": {
|
| 142 |
+
"bytes": 255,
|
| 143 |
+
"mode": 420,
|
| 144 |
+
"sha256": "71b7ae0e53bdde145628cbcb5f7a06a21e88ae58b438abfe99a8f0685549f4b6"
|
| 145 |
+
},
|
| 146 |
+
"tests/typing/typing_progressbar.py": {
|
| 147 |
+
"bytes": 559,
|
| 148 |
+
"mode": 420,
|
| 149 |
+
"sha256": "ba0529f20aa25016ffe36176db14437030b1fc7805a083b11742c5e03b3ba59c"
|
| 150 |
+
},
|
| 151 |
+
"tests/typing/typing_simple_example.py": {
|
| 152 |
+
"bytes": 508,
|
| 153 |
+
"mode": 420,
|
| 154 |
+
"sha256": "82c6a9d71dad51af7ce9f3c3cba5a9f9fc89184592d17d9385c14f330b81c64f"
|
| 155 |
+
},
|
| 156 |
+
"tests/typing/typing_version_option.py": {
|
| 157 |
+
"bytes": 287,
|
| 158 |
+
"mode": 420,
|
| 159 |
+
"sha256": "668cfdf7b197f178e519034ac8bce9f3901786ba6a9db0d1f2a9ef3c4b2d1ada"
|
| 160 |
+
},
|
| 161 |
+
"tox.ini": {
|
| 162 |
+
"bytes": 1203,
|
| 163 |
+
"mode": 420,
|
| 164 |
+
"sha256": "34183c21fb749d74f9a8299feaf931dcf01679634e3e9367923770cf83bb2838"
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
}
|
tasks/pallets__click.fde47b4b.combine_file__1dmpgrck/tests/trusted/tests/typing/typing_progressbar.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from typing_extensions import assert_type
|
| 4 |
+
|
| 5 |
+
from click import progressbar
|
| 6 |
+
from click._termui_impl import ProgressBar
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def test_length_is_int() -> None:
|
| 10 |
+
with progressbar(length=5) as bar:
|
| 11 |
+
assert_type(bar, ProgressBar[int])
|
| 12 |
+
for i in bar:
|
| 13 |
+
assert_type(i, int)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def it() -> tuple[str, ...]:
|
| 17 |
+
return ("hello", "world")
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def test_generic_on_iterable() -> None:
|
| 21 |
+
with progressbar(it()) as bar:
|
| 22 |
+
assert_type(bar, ProgressBar[str])
|
| 23 |
+
for s in bar:
|
| 24 |
+
assert_type(s, str)
|
tasks/pallets__click.fde47b4b.combine_file__1dmpgrck/tests/trusted/tests/typing/typing_simple_example.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The simple example from https://github.com/pallets/click#a-simple-example."""
|
| 2 |
+
|
| 3 |
+
from typing_extensions import assert_type
|
| 4 |
+
|
| 5 |
+
import click
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
@click.command()
|
| 9 |
+
@click.option("--count", default=1, help="Number of greetings.")
|
| 10 |
+
@click.option("--name", prompt="Your name", help="The person to greet.")
|
| 11 |
+
def hello(count: int, name: str) -> None:
|
| 12 |
+
"""Simple program that greets NAME for a total of COUNT times."""
|
| 13 |
+
for _ in range(count):
|
| 14 |
+
click.echo(f"Hello, {name}!")
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
assert_type(hello, click.Command)
|
tasks/pallets__click.fde47b4b.combine_file__1dmpgrck/tests/trusted/tests/typing/typing_version_option.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
From https://click.palletsprojects.com/en/8.1.x/options/#callbacks-and-eager-options.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from typing_extensions import assert_type
|
| 6 |
+
|
| 7 |
+
import click
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@click.command()
|
| 11 |
+
@click.version_option("0.1")
|
| 12 |
+
def hello() -> None:
|
| 13 |
+
click.echo("Hello World!")
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
assert_type(hello, click.Command)
|
tasks/pallets__click.fde47b4b.combine_file__1dmpgrck/tests/trusted/tox.ini
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[tox]
|
| 2 |
+
envlist =
|
| 3 |
+
py3{13,12,11,10,9,8}
|
| 4 |
+
pypy310
|
| 5 |
+
style
|
| 6 |
+
typing
|
| 7 |
+
docs
|
| 8 |
+
skip_missing_interpreters = true
|
| 9 |
+
|
| 10 |
+
[testenv]
|
| 11 |
+
package = wheel
|
| 12 |
+
wheel_build_env = .pkg
|
| 13 |
+
constrain_package_deps = true
|
| 14 |
+
use_frozen_constraints = true
|
| 15 |
+
deps = -r requirements/tests.txt
|
| 16 |
+
commands = pytest -v --tb=short --basetemp={envtmpdir} {posargs}
|
| 17 |
+
|
| 18 |
+
[testenv:style]
|
| 19 |
+
deps = pre-commit
|
| 20 |
+
skip_install = true
|
| 21 |
+
commands = pre-commit run --all-files
|
| 22 |
+
|
| 23 |
+
[testenv:typing]
|
| 24 |
+
deps = -r requirements/typing.txt
|
| 25 |
+
commands =
|
| 26 |
+
mypy
|
| 27 |
+
pyright tests/typing
|
| 28 |
+
pyright --verifytypes click --ignoreexternal
|
| 29 |
+
|
| 30 |
+
[testenv:docs]
|
| 31 |
+
deps = -r requirements/docs.txt
|
| 32 |
+
commands = sphinx-build -E -W -b dirhtml docs docs/_build/dirhtml
|
| 33 |
+
|
| 34 |
+
[testenv:update-actions]
|
| 35 |
+
labels = update
|
| 36 |
+
deps = gha-update
|
| 37 |
+
commands = gha-update
|
| 38 |
+
|
| 39 |
+
[testenv:update-pre_commit]
|
| 40 |
+
labels = update
|
| 41 |
+
deps = pre-commit
|
| 42 |
+
skip_install = true
|
| 43 |
+
commands = pre-commit autoupdate -j4
|
| 44 |
+
|
| 45 |
+
[testenv:update-requirements]
|
| 46 |
+
labels = update
|
| 47 |
+
deps = pip-tools
|
| 48 |
+
skip_install = true
|
| 49 |
+
change_dir = requirements
|
| 50 |
+
commands =
|
| 51 |
+
pip-compile build.in -q {posargs:-U}
|
| 52 |
+
pip-compile docs.in -q {posargs:-U}
|
| 53 |
+
pip-compile tests.in -q {posargs:-U}
|
| 54 |
+
pip-compile typing.in -q {posargs:-U}
|
| 55 |
+
pip-compile dev.in -q {posargs:-U}
|
tasks/pallets__click.fde47b4b.combine_file__1dmpgrck/validation/canaries/first-hunk-only.sh
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -Eeuo pipefail
|
| 3 |
+
cd /testbed/repo
|
| 4 |
+
cat > /tmp/openenv-reference.diff <<'OPENENV_PARTIAL'
|
| 5 |
+
diff --git a/src/click/_termui_impl.py b/src/click/_termui_impl.py
|
| 6 |
+
index fafd58d0a6786e5e2e7df260be5c825ae230e6bc..a6c7e6b3661f3e0b9cf719bbe3f93e3ff2235aed 100644
|
| 7 |
+
--- a/src/click/_termui_impl.py
|
| 8 |
+
+++ b/src/click/_termui_impl.py
|
| 9 |
+
@@ -189,18 +189,18 @@
|
| 10 |
+
if self.length is not None:
|
| 11 |
+
bar_length = int(self.pct * self.width)
|
| 12 |
+
bar = self.fill_char * bar_length
|
| 13 |
+
- bar += self.empty_char * (self.width - bar_length + 1)
|
| 14 |
+
+ bar += self.empty_char * (self.width - bar_length)
|
| 15 |
+
elif self.finished:
|
| 16 |
+
- bar = self.empty_char * self.width
|
| 17 |
+
- else:
|
| 18 |
+
- chars = list(self.fill_char * (self.width or 1))
|
| 19 |
+
+ bar = self.fill_char * self.width
|
| 20 |
+
+ else:
|
| 21 |
+
+ chars = list(self.empty_char * (self.width or 1))
|
| 22 |
+
if self.time_per_iteration != 0:
|
| 23 |
+
chars[
|
| 24 |
+
int(
|
| 25 |
+
- (math.sin(self.pos * self.time_per_iteration) / 2.0 + 0.5)
|
| 26 |
+
+ (math.cos(self.pos * self.time_per_iteration) / 2.0 + 0.5)
|
| 27 |
+
* self.width
|
| 28 |
+
)
|
| 29 |
+
- ] = self.empty_char
|
| 30 |
+
+ ] = self.fill_char
|
| 31 |
+
bar = "".join(chars)
|
| 32 |
+
return bar
|
| 33 |
+
|
| 34 |
+
OPENENV_PARTIAL
|
| 35 |
+
/usr/bin/git -c core.hooksPath=/dev/null -c core.fsmonitor=false apply --whitespace=nowarn /tmp/openenv-reference.diff
|
tasks/pallets__click.fde47b4b.combine_file__1dmpgrck/validation/canaries/original-bug.sh
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -Eeuo pipefail
|
| 3 |
+
:
|
tasks/pallets__click.fde47b4b.combine_file__1dmpgrck/validation/openenv.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"canaries": "validation/canaries",
|
| 3 |
+
"profile": "harbor-semantic-v1",
|
| 4 |
+
"requires_credentials": false,
|
| 5 |
+
"resources": {
|
| 6 |
+
"cpu": 2,
|
| 7 |
+
"disk_mb": 16384,
|
| 8 |
+
"episode_timeout_s": 1800,
|
| 9 |
+
"memory_mb": 8192
|
| 10 |
+
},
|
| 11 |
+
"reward": {
|
| 12 |
+
"floor_margin": 0.1,
|
| 13 |
+
"oracle_tolerance": 0,
|
| 14 |
+
"range": [
|
| 15 |
+
0,
|
| 16 |
+
1
|
| 17 |
+
]
|
| 18 |
+
},
|
| 19 |
+
"reward_key": "reward",
|
| 20 |
+
"types": {
|
| 21 |
+
"tags": [
|
| 22 |
+
"swe",
|
| 23 |
+
"python",
|
| 24 |
+
"mutation-repair"
|
| 25 |
+
]
|
| 26 |
+
}
|
| 27 |
+
}
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/LICENSE.source
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright 2014 Pallets
|
| 2 |
+
|
| 3 |
+
Redistribution and use in source and binary forms, with or without
|
| 4 |
+
modification, are permitted provided that the following conditions are
|
| 5 |
+
met:
|
| 6 |
+
|
| 7 |
+
1. Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
|
| 10 |
+
2. Redistributions in binary form must reproduce the above copyright
|
| 11 |
+
notice, this list of conditions and the following disclaimer in the
|
| 12 |
+
documentation and/or other materials provided with the distribution.
|
| 13 |
+
|
| 14 |
+
3. Neither the name of the copyright holder nor the names of its
|
| 15 |
+
contributors may be used to endorse or promote products derived from
|
| 16 |
+
this software without specific prior written permission.
|
| 17 |
+
|
| 18 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 19 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 20 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
| 21 |
+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 22 |
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 23 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
| 24 |
+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
| 25 |
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
| 26 |
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
| 27 |
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 28 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/adapter.json
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"canary_selection": "Fixed first provided gold hunk only when at least2hunks exist; strict subset, never reward-selected. Single-hunk task original-bug canary is explicitly NOP-equivalent and adds no signal beyond floor_gap.",
|
| 3 |
+
"collector_sha256": "352e555112f2de8a1393f939903e4971c9ace0e944843762b707a725c5c72481",
|
| 4 |
+
"dependency_installation_pinned": false,
|
| 5 |
+
"dependency_setup_sha256": "3a63d6a3502a27f06313581dcecb335018a18a55a2d1b5f0db2805ea49cc2052",
|
| 6 |
+
"gold_patch_sha256": "c777bf7b2212fa53743824eb181b46a4a13093227be84a27928afed54cc3812a",
|
| 7 |
+
"hostile_code_isolation_established": false,
|
| 8 |
+
"known_wrong_semantic_implementations": 0,
|
| 9 |
+
"native_inventory_sha256": "ddc55ffa2d50d767d810017108572caeae1294cba017721329f7178459610cb0",
|
| 10 |
+
"new_files_deletions_and_executable_modes_supported": true,
|
| 11 |
+
"official_profile": {
|
| 12 |
+
"eval_sets": [],
|
| 13 |
+
"profile_class": "ClickFde47b4b4",
|
| 14 |
+
"profile_lines": [
|
| 15 |
+
229,
|
| 16 |
+
232
|
| 17 |
+
],
|
| 18 |
+
"profile_source_commit": "9b74ac08118a85c39c356802f7961893af73e07f",
|
| 19 |
+
"profile_source_path": "swesmith/profiles/python.py",
|
| 20 |
+
"profile_source_sha256": "eadf29551ca2e706950d3f2311b47a3d08c2ccee3c8dd217fa299014a08e4286",
|
| 21 |
+
"upstream_commit": "fde47b4b4f978f179b9dff34583cb2b99021f482",
|
| 22 |
+
"upstream_repo": "pallets/click"
|
| 23 |
+
},
|
| 24 |
+
"original_bug_canary_nop_equivalent": true,
|
| 25 |
+
"original_bug_runtime_wrongness_established": false,
|
| 26 |
+
"partial_repair_canary": true,
|
| 27 |
+
"partial_repair_sha256": "b69df9d02a20849dbf931e97860ad3f78b55bc106bab458d78a4753727c0dc62",
|
| 28 |
+
"partial_repair_wrongness_established": false,
|
| 29 |
+
"provided_original_bug_control": true,
|
| 30 |
+
"repo_url": "https://github.com/swesmith/pallets__click.fde47b4b.git",
|
| 31 |
+
"runtime_image": null,
|
| 32 |
+
"runtime_ready": false,
|
| 33 |
+
"runtime_recipe": {
|
| 34 |
+
"dependency_installation_pinned": false,
|
| 35 |
+
"official_install_cmds": [
|
| 36 |
+
"python -m pip install -e ."
|
| 37 |
+
],
|
| 38 |
+
"official_pytest_argv": [
|
| 39 |
+
"pytest",
|
| 40 |
+
"--disable-warnings",
|
| 41 |
+
"--color=no",
|
| 42 |
+
"--tb=no",
|
| 43 |
+
"--verbose"
|
| 44 |
+
],
|
| 45 |
+
"official_test_command": "source /opt/miniconda3/bin/activate; conda activate testbed; pytest --disable-warnings --color=no --tb=no --verbose",
|
| 46 |
+
"panel_normalization": "Override project addopts only to execute the exact frozen native panels; add JUnit output, preserve official pytest options and all selectors.",
|
| 47 |
+
"python_version": "3.10",
|
| 48 |
+
"source_bound_test_dependency_cmds": [
|
| 49 |
+
"python -m pip install -r requirements/tests.txt"
|
| 50 |
+
],
|
| 51 |
+
"test_dependency_source_sha256": {
|
| 52 |
+
"requirements/tests.txt": "35f217825acd2a107dfb2c7b848d8a963e8d2eba6d7bd50e9fb34f3912e68658",
|
| 53 |
+
"tox.ini": "34183c21fb749d74f9a8299feaf931dcf01679634e3e9367923770cf83bb2838"
|
| 54 |
+
}
|
| 55 |
+
},
|
| 56 |
+
"runtime_resource_review_required": false,
|
| 57 |
+
"schema": "python-git-patch-jobs-v1",
|
| 58 |
+
"source_base_commit": "0452dae4dbf9634371b6bdf30ada275d95e599ea",
|
| 59 |
+
"source_completion_sha256": "342065db8f9dfa4aa2e1a8233184267e6b8fff93cb3a7ef9439c64eae9841254",
|
| 60 |
+
"source_index_sha256": "a8bacb23b190ac8227d8d322773176a10ed65e6b16cccd869cb625a465522876",
|
| 61 |
+
"source_pr_url": null,
|
| 62 |
+
"source_record": {
|
| 63 |
+
"anti_training_canary": false,
|
| 64 |
+
"anti_training_reviewed": true,
|
| 65 |
+
"candidate_id": "swesmith-py:pallets__click.fde47b4b.combine_file__3hfoaaic",
|
| 66 |
+
"cloud_launch_ready": false,
|
| 67 |
+
"eligibility": {
|
| 68 |
+
"reasons": [],
|
| 69 |
+
"semantic_nonoverlap_established": false,
|
| 70 |
+
"status": "eligible_for_controls",
|
| 71 |
+
"training_admissible": false,
|
| 72 |
+
"warnings": []
|
| 73 |
+
},
|
| 74 |
+
"healthy_mirror_commit": "642a0737fd895f3adba643e7502081ce98f5abbb",
|
| 75 |
+
"instruction_sha256": "45367013c7477f15a1a1e66bbcd21bb281c15c0eab16640646ad4997c1262169",
|
| 76 |
+
"is_fork": true,
|
| 77 |
+
"learner_path": "tasks/012bd400c7ad13fa808fde1c/learner",
|
| 78 |
+
"license_evidence": {
|
| 79 |
+
"source_code": {
|
| 80 |
+
"actual_upstream_commit": "fde47b4b4f978f179b9dff34583cb2b99021f482",
|
| 81 |
+
"actual_upstream_url": "https://raw.githubusercontent.com/pallets/click/fde47b4b4f978f179b9dff34583cb2b99021f482/LICENSE.txt",
|
| 82 |
+
"reviewed": true,
|
| 83 |
+
"sha256": "9a8ad106a394e853bfe21f42f4e72d592819a22805d991b5f3275029292b658d",
|
| 84 |
+
"spdx": "BSD-3-Clause",
|
| 85 |
+
"training_allowed": true,
|
| 86 |
+
"url": "https://raw.githubusercontent.com/swesmith/pallets__click.fde47b4b/0452dae4dbf9634371b6bdf30ada275d95e599ea/LICENSE.txt"
|
| 87 |
+
},
|
| 88 |
+
"task_bundle": {
|
| 89 |
+
"reviewed": true,
|
| 90 |
+
"sha256": "18afda407941c9d3c65ff530bedd3bc93f3a13d9504ee5728e959fb43ffce808",
|
| 91 |
+
"spdx": "MIT",
|
| 92 |
+
"training_allowed": true,
|
| 93 |
+
"url": "https://huggingface.co/datasets/SWE-bench/SWE-smith-py/raw/77cab9055d42ab4a5c25c89a8f937096db13558e/README.md"
|
| 94 |
+
}
|
| 95 |
+
},
|
| 96 |
+
"original_source_commit": "fde47b4b4f978f179b9dff34583cb2b99021f482",
|
| 97 |
+
"patch_sha256": "3314835b6acae3bcd146678a99dd26d7b1956dad88ce9e296cc7edbe22fd9c1f",
|
| 98 |
+
"provenance_path": "tasks/012bd400c7ad13fa808fde1c/source-proof.json",
|
| 99 |
+
"repository_lineage": [
|
| 100 |
+
"swesmith/pallets__click.fde47b4b",
|
| 101 |
+
"pallets/click"
|
| 102 |
+
],
|
| 103 |
+
"rfc008_complete": false,
|
| 104 |
+
"runtime_qualified": false,
|
| 105 |
+
"semantic_nonoverlap_established": false,
|
| 106 |
+
"source_commit": "0452dae4dbf9634371b6bdf30ada275d95e599ea",
|
| 107 |
+
"source_dataset": "SWE-bench/SWE-smith-py",
|
| 108 |
+
"source_head_commit": "3097ec466315f1f9ad82fbd894dfb9235b6bc1cf",
|
| 109 |
+
"source_kind": "mutation",
|
| 110 |
+
"source_repo": "swesmith/pallets__click.fde47b4b",
|
| 111 |
+
"source_revision": "77cab9055d42ab4a5c25c89a8f937096db13558e",
|
| 112 |
+
"source_split": "train",
|
| 113 |
+
"target_model_calibrated": false,
|
| 114 |
+
"task_id": "pallets__click.fde47b4b.combine_file__3hfoaaic",
|
| 115 |
+
"task_sha256": "7b537833ef61b3cda2b29a6f983e61d078e2be53b30c3945ce1063a0f10fb426",
|
| 116 |
+
"training_admissible": false,
|
| 117 |
+
"upstream_identity_reviewed": true,
|
| 118 |
+
"upstream_repo": "pallets/click",
|
| 119 |
+
"usage": "quarantine_only"
|
| 120 |
+
},
|
| 121 |
+
"source_repo": "swesmith/pallets__click.fde47b4b",
|
| 122 |
+
"symlink_submodule_changes_supported": false,
|
| 123 |
+
"task_id": "pallets__click.fde47b4b.combine_file__3hfoaaic",
|
| 124 |
+
"transfer": "index-independent-worktree-to-Git-binary-patch",
|
| 125 |
+
"transfer_path": "/testbed/submission.patch",
|
| 126 |
+
"upstream_repo": "pallets/click"
|
| 127 |
+
}
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/dependency-setup.sh
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -Eeuo pipefail
|
| 3 |
+
source /opt/miniconda3/bin/activate
|
| 4 |
+
conda activate testbed
|
| 5 |
+
cd /testbed/repo
|
| 6 |
+
python -c 'import sys; assert sys.version_info[:2] == (3, 10)'
|
| 7 |
+
python -m pip install -e .
|
| 8 |
+
python -m pip install -r requirements/tests.txt
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/environment/Dockerfile
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Runtime is selected only by an independently qualified immutable amd64 receipt.
|
| 2 |
+
FROM ubuntu:22.04
|
| 3 |
+
RUN false
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/instruction.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Click decorators broken after recent changes
|
| 2 |
+
|
| 3 |
+
I'm encountering issues with Click decorators that seem to have broken functionality. When trying to use basic Click commands with decorators like `@click.pass_context` and `@click.pass_obj`, I'm getting unexpected errors.
|
| 4 |
+
|
| 5 |
+
#### Steps/Code to Reproduce
|
| 6 |
+
|
| 7 |
+
```python
|
| 8 |
+
import click
|
| 9 |
+
|
| 10 |
+
@click.group()
|
| 11 |
+
@click.pass_context
|
| 12 |
+
def cli(ctx):
|
| 13 |
+
ctx.obj = 'test'
|
| 14 |
+
|
| 15 |
+
@cli.command()
|
| 16 |
+
@click.pass_obj
|
| 17 |
+
def test(obj):
|
| 18 |
+
click.echo(obj)
|
| 19 |
+
|
| 20 |
+
if __name__ == '__main__':
|
| 21 |
+
cli()
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
Running this simple example throws a `TypeError: Attempted to convert a callback into a command twice.`
|
| 25 |
+
|
| 26 |
+
Also having issues with basic option decorators:
|
| 27 |
+
|
| 28 |
+
```python
|
| 29 |
+
import click
|
| 30 |
+
|
| 31 |
+
@click.command()
|
| 32 |
+
@click.option('--name', default='World')
|
| 33 |
+
def hello(name):
|
| 34 |
+
click.echo(f'Hello {name}!')
|
| 35 |
+
|
| 36 |
+
if __name__ == '__main__':
|
| 37 |
+
hello()
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
This also fails with similar errors. The decorators seem to be malfunctioning and not properly wrapping the functions as expected.
|
| 41 |
+
|
| 42 |
+
The issue appears to affect multiple decorator types including `@click.pass_context`, `@click.pass_obj`, `@click.option`, and others. Basic Click functionality that was working before is now completely broken.
|
| 43 |
+
|
| 44 |
+
## Environment
|
| 45 |
+
|
| 46 |
+
The repository is at `/testbed/repo`. Its dependencies, including pytest, are installed in the `testbed` conda environment, which comes first on PATH. If `python -m pytest` reports that pytest is missing, use the full interpreter path: `/opt/miniconda3/envs/testbed/bin/python -m pytest <tests>`. Don't install packages: the tests need nothing else, and the sandbox may have no network access.
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/metadata.json
ADDED
|
@@ -0,0 +1,744 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"all_runtime_and_training_flags": false,
|
| 3 |
+
"official_profile": {
|
| 4 |
+
"eval_sets": [],
|
| 5 |
+
"profile_class": "ClickFde47b4b4",
|
| 6 |
+
"profile_lines": [
|
| 7 |
+
229,
|
| 8 |
+
232
|
| 9 |
+
],
|
| 10 |
+
"profile_source_commit": "9b74ac08118a85c39c356802f7961893af73e07f",
|
| 11 |
+
"profile_source_path": "swesmith/profiles/python.py",
|
| 12 |
+
"profile_source_sha256": "eadf29551ca2e706950d3f2311b47a3d08c2ccee3c8dd217fa299014a08e4286",
|
| 13 |
+
"upstream_commit": "fde47b4b4f978f179b9dff34583cb2b99021f482",
|
| 14 |
+
"upstream_repo": "pallets/click"
|
| 15 |
+
},
|
| 16 |
+
"source_healthy_reference_proof": {
|
| 17 |
+
"FAIL_TO_PASS": [
|
| 18 |
+
"tests/test_arguments.py::test_nargs_star",
|
| 19 |
+
"tests/test_arguments.py::test_nargs_tup",
|
| 20 |
+
"tests/test_arguments.py::test_nargs_tup_composite[opts0]",
|
| 21 |
+
"tests/test_arguments.py::test_nargs_tup_composite[opts1]",
|
| 22 |
+
"tests/test_arguments.py::test_nargs_tup_composite[opts2]",
|
| 23 |
+
"tests/test_arguments.py::test_nargs_tup_composite[opts3]",
|
| 24 |
+
"tests/test_arguments.py::test_nargs_err",
|
| 25 |
+
"tests/test_arguments.py::test_bytes_args",
|
| 26 |
+
"tests/test_arguments.py::test_file_args",
|
| 27 |
+
"tests/test_arguments.py::test_path_allow_dash",
|
| 28 |
+
"tests/test_arguments.py::test_file_atomics",
|
| 29 |
+
"tests/test_arguments.py::test_stdout_default",
|
| 30 |
+
"tests/test_arguments.py::test_nargs_envvar[2--None]",
|
| 31 |
+
"tests/test_arguments.py::test_nargs_envvar[-1--expect5]",
|
| 32 |
+
"tests/test_arguments.py::test_envvar_flag_value",
|
| 33 |
+
"tests/test_arguments.py::test_nargs_envvar_only_if_values_empty",
|
| 34 |
+
"tests/test_arguments.py::test_empty_nargs",
|
| 35 |
+
"tests/test_arguments.py::test_missing_arg",
|
| 36 |
+
"tests/test_arguments.py::test_implicit_non_required",
|
| 37 |
+
"tests/test_arguments.py::test_eat_options",
|
| 38 |
+
"tests/test_arguments.py::test_nargs_star_ordering",
|
| 39 |
+
"tests/test_arguments.py::test_nargs_specified_plus_star_ordering",
|
| 40 |
+
"tests/test_arguments.py::test_defaults_for_nargs",
|
| 41 |
+
"tests/test_arguments.py::test_subcommand_help",
|
| 42 |
+
"tests/test_arguments.py::test_nested_subcommand_help",
|
| 43 |
+
"tests/test_arguments.py::test_when_argument_decorator_is_used_multiple_times_cls_is_preserved",
|
| 44 |
+
"tests/test_arguments.py::test_duplicate_names_warning[args_one0-args_two0]",
|
| 45 |
+
"tests/test_basic.py::test_basic_functionality",
|
| 46 |
+
"tests/test_basic.py::test_repr",
|
| 47 |
+
"tests/test_basic.py::test_return_values",
|
| 48 |
+
"tests/test_basic.py::test_basic_group",
|
| 49 |
+
"tests/test_basic.py::test_group_commands_dict",
|
| 50 |
+
"tests/test_basic.py::test_group_from_list",
|
| 51 |
+
"tests/test_basic.py::test_string_option[args1-S:[42]]",
|
| 52 |
+
"tests/test_basic.py::test_string_option[args3-S:[]]",
|
| 53 |
+
"tests/test_basic.py::test_string_option[args4-S:[\\u2603]]",
|
| 54 |
+
"tests/test_basic.py::test_int_option[args0-I:[84]]",
|
| 55 |
+
"tests/test_basic.py::test_int_option[args1-I:[46]]",
|
| 56 |
+
"tests/test_basic.py::test_uuid_option[args0-U:[ba122011-349f-423b-873b-9d6a79c688ab]]",
|
| 57 |
+
"tests/test_basic.py::test_uuid_option[args1-U:[821592c1-c50e-4971-9cd6-e89dc6832f86]]",
|
| 58 |
+
"tests/test_basic.py::test_float_option[args0-F:[42.0]]",
|
| 59 |
+
"tests/test_basic.py::test_float_option[--f=23.5-F:[23.5]]",
|
| 60 |
+
"tests/test_basic.py::test_boolean_switch[args0-True-True]",
|
| 61 |
+
"tests/test_basic.py::test_boolean_switch[args0-True-False]",
|
| 62 |
+
"tests/test_basic.py::test_boolean_switch[args1-False-True]",
|
| 63 |
+
"tests/test_basic.py::test_boolean_switch[args1-False-False]",
|
| 64 |
+
"tests/test_basic.py::test_boolean_switch[args2-None-True]",
|
| 65 |
+
"tests/test_basic.py::test_boolean_switch[args2-None-False]",
|
| 66 |
+
"tests/test_basic.py::test_boolean_flag[args0-True-True]",
|
| 67 |
+
"tests/test_basic.py::test_boolean_flag[args0-True-False]",
|
| 68 |
+
"tests/test_basic.py::test_boolean_flag[args1-False-True]",
|
| 69 |
+
"tests/test_basic.py::test_boolean_flag[args1-False-False]",
|
| 70 |
+
"tests/test_basic.py::test_boolean_conversion[1-True]",
|
| 71 |
+
"tests/test_basic.py::test_boolean_conversion[true-True]",
|
| 72 |
+
"tests/test_basic.py::test_boolean_conversion[t-True]",
|
| 73 |
+
"tests/test_basic.py::test_boolean_conversion[yes-True]",
|
| 74 |
+
"tests/test_basic.py::test_boolean_conversion[y-True]",
|
| 75 |
+
"tests/test_basic.py::test_boolean_conversion[on-True]",
|
| 76 |
+
"tests/test_basic.py::test_boolean_conversion[0-False]",
|
| 77 |
+
"tests/test_basic.py::test_boolean_conversion[false-False]",
|
| 78 |
+
"tests/test_basic.py::test_boolean_conversion[f-False]",
|
| 79 |
+
"tests/test_basic.py::test_boolean_conversion[no-False]",
|
| 80 |
+
"tests/test_basic.py::test_boolean_conversion[n-False]",
|
| 81 |
+
"tests/test_basic.py::test_boolean_conversion[off-False]",
|
| 82 |
+
"tests/test_basic.py::test_file_option",
|
| 83 |
+
"tests/test_basic.py::test_file_lazy_mode",
|
| 84 |
+
"tests/test_basic.py::test_path_option",
|
| 85 |
+
"tests/test_basic.py::test_choice_option",
|
| 86 |
+
"tests/test_basic.py::test_choice_argument",
|
| 87 |
+
"tests/test_basic.py::test_datetime_option_default",
|
| 88 |
+
"tests/test_basic.py::test_datetime_option_custom",
|
| 89 |
+
"tests/test_basic.py::test_required_option",
|
| 90 |
+
"tests/test_basic.py::test_evaluation_order",
|
| 91 |
+
"tests/test_basic.py::test_hidden_option",
|
| 92 |
+
"tests/test_basic.py::test_hidden_command",
|
| 93 |
+
"tests/test_basic.py::test_hidden_group",
|
| 94 |
+
"tests/test_basic.py::test_summary_line",
|
| 95 |
+
"tests/test_chain.py::test_basic_chaining",
|
| 96 |
+
"tests/test_chain.py::test_chaining_with_options",
|
| 97 |
+
"tests/test_chain.py::test_no_command_result_callback[False-1]",
|
| 98 |
+
"tests/test_chain.py::test_no_command_result_callback[True-[]]",
|
| 99 |
+
"tests/test_chain.py::test_chaining_with_arguments",
|
| 100 |
+
"tests/test_chain.py::test_pipeline[args0-foo\\nbar-expect0]",
|
| 101 |
+
"tests/test_chain.py::test_args_and_chain",
|
| 102 |
+
"tests/test_chain.py::test_group_arg_behavior",
|
| 103 |
+
"tests/test_command_decorators.py::test_command_no_parens",
|
| 104 |
+
"tests/test_command_decorators.py::test_custom_command_no_parens",
|
| 105 |
+
"tests/test_command_decorators.py::test_group_no_parens",
|
| 106 |
+
"tests/test_command_decorators.py::test_params_argument",
|
| 107 |
+
"tests/test_command_decorators.py::test_generate_name[init_data]",
|
| 108 |
+
"tests/test_command_decorators.py::test_generate_name[init_data_command]",
|
| 109 |
+
"tests/test_command_decorators.py::test_generate_name[init_data_cmd]",
|
| 110 |
+
"tests/test_command_decorators.py::test_generate_name[init_data_group]",
|
| 111 |
+
"tests/test_command_decorators.py::test_generate_name[init_data_grp]",
|
| 112 |
+
"tests/test_commands.py::test_other_command_invoke",
|
| 113 |
+
"tests/test_commands.py::test_other_command_forward",
|
| 114 |
+
"tests/test_commands.py::test_forwarded_params_consistency",
|
| 115 |
+
"tests/test_commands.py::test_auto_shorthelp",
|
| 116 |
+
"tests/test_commands.py::test_default_maps",
|
| 117 |
+
"tests/test_commands.py::test_group_with_args[args2-0-obj=obj1\\nmove\\n]",
|
| 118 |
+
"tests/test_commands.py::test_custom_parser",
|
| 119 |
+
"tests/test_commands.py::test_object_propagation",
|
| 120 |
+
"tests/test_commands.py::test_other_command_invoke_with_defaults",
|
| 121 |
+
"tests/test_commands.py::test_invoked_subcommand",
|
| 122 |
+
"tests/test_commands.py::test_aliased_command_canonical_name",
|
| 123 |
+
"tests/test_commands.py::test_unprocessed_options",
|
| 124 |
+
"tests/test_commands.py::test_deprecated_in_help_messages[None]",
|
| 125 |
+
"tests/test_commands.py::test_deprecated_in_invocation",
|
| 126 |
+
"tests/test_commands.py::test_command_parse_args_collects_option_prefixes",
|
| 127 |
+
"tests/test_commands.py::test_group_parse_args_collects_base_option_prefixes",
|
| 128 |
+
"tests/test_commands.py::test_group_invoke_collects_used_option_prefixes",
|
| 129 |
+
"tests/test_commands.py::test_abort_exceptions_with_disabled_standalone_mode[EOFError]",
|
| 130 |
+
"tests/test_commands.py::test_abort_exceptions_with_disabled_standalone_mode[KeyboardInterrupt]",
|
| 131 |
+
"tests/test_context.py::test_ensure_context_objects",
|
| 132 |
+
"tests/test_context.py::test_get_context_objects",
|
| 133 |
+
"tests/test_context.py::test_get_context_objects_no_ensuring",
|
| 134 |
+
"tests/test_context.py::test_get_context_objects_missing",
|
| 135 |
+
"tests/test_context.py::test_multi_enter",
|
| 136 |
+
"tests/test_context.py::test_global_context_object",
|
| 137 |
+
"tests/test_context.py::test_context_meta",
|
| 138 |
+
"tests/test_context.py::test_make_pass_meta_decorator",
|
| 139 |
+
"tests/test_context.py::test_context_pushing",
|
| 140 |
+
"tests/test_context.py::test_pass_obj",
|
| 141 |
+
"tests/test_context.py::test_close_before_pop",
|
| 142 |
+
"tests/test_context.py::test_close_before_exit",
|
| 143 |
+
"tests/test_context.py::test_multiple_eager_callbacks[natural_order]",
|
| 144 |
+
"tests/test_context.py::test_multiple_eager_callbacks[eagerness_precedence]",
|
| 145 |
+
"tests/test_context.py::test_no_state_leaks",
|
| 146 |
+
"tests/test_context.py::test_make_pass_decorator_args",
|
| 147 |
+
"tests/test_context.py::test_exit_not_standalone",
|
| 148 |
+
"tests/test_context.py::test_parameter_source[default]",
|
| 149 |
+
"tests/test_context.py::test_parameter_source[default_map]",
|
| 150 |
+
"tests/test_custom_classes.py::test_context_invoke_type",
|
| 151 |
+
"tests/test_custom_classes.py::test_group_command_class",
|
| 152 |
+
"tests/test_custom_classes.py::test_group_group_class",
|
| 153 |
+
"tests/test_custom_classes.py::test_group_group_class_self",
|
| 154 |
+
"tests/test_defaults.py::test_basic_defaults",
|
| 155 |
+
"tests/test_defaults.py::test_multiple_defaults",
|
| 156 |
+
"tests/test_defaults.py::test_nargs_plus_multiple",
|
| 157 |
+
"tests/test_defaults.py::test_multiple_flag_default",
|
| 158 |
+
"tests/test_defaults.py::test_flag_default_map",
|
| 159 |
+
"tests/test_formatting.py::test_basic_functionality",
|
| 160 |
+
"tests/test_formatting.py::test_wrapping_long_options_strings",
|
| 161 |
+
"tests/test_formatting.py::test_wrapping_long_command_name",
|
| 162 |
+
"tests/test_formatting.py::test_formatting_empty_help_lines",
|
| 163 |
+
"tests/test_formatting.py::test_formatting_usage_error",
|
| 164 |
+
"tests/test_formatting.py::test_formatting_usage_error_metavar_missing_arg",
|
| 165 |
+
"tests/test_formatting.py::test_formatting_usage_error_metavar_bad_arg",
|
| 166 |
+
"tests/test_formatting.py::test_formatting_usage_error_nested",
|
| 167 |
+
"tests/test_formatting.py::test_formatting_usage_error_no_help",
|
| 168 |
+
"tests/test_formatting.py::test_formatting_usage_custom_help",
|
| 169 |
+
"tests/test_formatting.py::test_formatting_custom_type_metavar",
|
| 170 |
+
"tests/test_formatting.py::test_truncating_docstring",
|
| 171 |
+
"tests/test_formatting.py::test_truncating_docstring_no_help",
|
| 172 |
+
"tests/test_formatting.py::test_removing_multiline_marker",
|
| 173 |
+
"tests/test_formatting.py::test_global_show_default",
|
| 174 |
+
"tests/test_normalization.py::test_option_normalization",
|
| 175 |
+
"tests/test_normalization.py::test_choice_normalization",
|
| 176 |
+
"tests/test_normalization.py::test_command_normalization",
|
| 177 |
+
"tests/test_options.py::test_prefixes",
|
| 178 |
+
"tests/test_options.py::test_nargs_tup_composite_mult",
|
| 179 |
+
"tests/test_options.py::test_counting",
|
| 180 |
+
"tests/test_options.py::test_unknown_options[--foo]",
|
| 181 |
+
"tests/test_options.py::test_unknown_options[-f]",
|
| 182 |
+
"tests/test_options.py::test_multiple_required",
|
| 183 |
+
"tests/test_options.py::test_empty_envvar[MYPATH]",
|
| 184 |
+
"tests/test_options.py::test_empty_envvar[AUTO_MYPATH]",
|
| 185 |
+
"tests/test_options.py::test_multiple_envvar",
|
| 186 |
+
"tests/test_options.py::test_trailing_blanks_boolean_envvar",
|
| 187 |
+
"tests/test_options.py::test_multiple_default_help",
|
| 188 |
+
"tests/test_options.py::test_show_default_default_map",
|
| 189 |
+
"tests/test_options.py::test_parse_multiple_default_composite_type",
|
| 190 |
+
"tests/test_options.py::test_dynamic_default_help_unset",
|
| 191 |
+
"tests/test_options.py::test_dynamic_default_help_text",
|
| 192 |
+
"tests/test_options.py::test_toupper_envvar_prefix",
|
| 193 |
+
"tests/test_options.py::test_nargs_envvar",
|
| 194 |
+
"tests/test_options.py::test_show_envvar",
|
| 195 |
+
"tests/test_options.py::test_show_envvar_auto_prefix",
|
| 196 |
+
"tests/test_options.py::test_show_envvar_auto_prefix_dash_in_command",
|
| 197 |
+
"tests/test_options.py::test_custom_validation",
|
| 198 |
+
"tests/test_options.py::test_callback_validates_prompt",
|
| 199 |
+
"tests/test_options.py::test_winstyle_options",
|
| 200 |
+
"tests/test_options.py::test_legacy_options",
|
| 201 |
+
"tests/test_options.py::test_missing_choice",
|
| 202 |
+
"tests/test_options.py::test_case_insensitive_choice",
|
| 203 |
+
"tests/test_options.py::test_case_insensitive_choice_returned_exactly",
|
| 204 |
+
"tests/test_options.py::test_option_help_preserve_paragraphs",
|
| 205 |
+
"tests/test_options.py::test_argument_custom_class",
|
| 206 |
+
"tests/test_options.py::test_option_custom_class",
|
| 207 |
+
"tests/test_options.py::test_option_custom_class_reusable",
|
| 208 |
+
"tests/test_options.py::test_bool_flag_with_type",
|
| 209 |
+
"tests/test_options.py::test_aliases_for_flags",
|
| 210 |
+
"tests/test_options.py::test_option_names[option_args0-aggressive]",
|
| 211 |
+
"tests/test_options.py::test_option_names[option_args1-first]",
|
| 212 |
+
"tests/test_options.py::test_option_names[option_args2-apple]",
|
| 213 |
+
"tests/test_options.py::test_option_names[option_args3-cantaloupe]",
|
| 214 |
+
"tests/test_options.py::test_option_names[option_args4-a]",
|
| 215 |
+
"tests/test_options.py::test_option_names[option_args5-c]",
|
| 216 |
+
"tests/test_options.py::test_option_names[option_args6-apple]",
|
| 217 |
+
"tests/test_options.py::test_option_names[option_args7-cantaloupe]",
|
| 218 |
+
"tests/test_options.py::test_option_names[option_args8-_from]",
|
| 219 |
+
"tests/test_options.py::test_option_names[option_args9-_ret]",
|
| 220 |
+
"tests/test_options.py::test_option_with_optional_value[None-expect0]",
|
| 221 |
+
"tests/test_options.py::test_option_with_optional_value[args1-expect1]",
|
| 222 |
+
"tests/test_options.py::test_option_with_optional_value[args2-expect2]",
|
| 223 |
+
"tests/test_options.py::test_option_with_optional_value[args3-expect3]",
|
| 224 |
+
"tests/test_options.py::test_option_with_optional_value[args4-expect4]",
|
| 225 |
+
"tests/test_options.py::test_option_with_optional_value[args5-expect5]",
|
| 226 |
+
"tests/test_options.py::test_option_with_optional_value[args6-expect6]",
|
| 227 |
+
"tests/test_options.py::test_option_with_optional_value[args7-expect7]",
|
| 228 |
+
"tests/test_options.py::test_option_with_optional_value[args8-expect8]",
|
| 229 |
+
"tests/test_options.py::test_option_with_optional_value[args9-expect9]",
|
| 230 |
+
"tests/test_options.py::test_option_with_optional_value[args10-expect10]",
|
| 231 |
+
"tests/test_options.py::test_option_with_optional_value[args11-expect11]",
|
| 232 |
+
"tests/test_options.py::test_option_with_optional_value[args12-expect12]",
|
| 233 |
+
"tests/test_options.py::test_option_with_optional_value[args13-expect13]",
|
| 234 |
+
"tests/test_options.py::test_duplicate_names_warning[opts_one0-opts_two0]",
|
| 235 |
+
"tests/test_options.py::test_duplicate_names_warning[opts_one1-opts_two1]",
|
| 236 |
+
"tests/test_shell_completion.py::test_files_closed",
|
| 237 |
+
"tests/test_termui.py::test_progressbar_strip_regression",
|
| 238 |
+
"tests/test_termui.py::test_progressbar_length_hint",
|
| 239 |
+
"tests/test_termui.py::test_progressbar_no_tty",
|
| 240 |
+
"tests/test_termui.py::test_progressbar_hidden_manual",
|
| 241 |
+
"tests/test_termui.py::test_progressbar_is_iterator",
|
| 242 |
+
"tests/test_termui.py::test_choices_list_in_prompt",
|
| 243 |
+
"tests/test_termui.py::test_file_prompt_default_format[file_kwargs0]",
|
| 244 |
+
"tests/test_termui.py::test_file_prompt_default_format[file_kwargs1]",
|
| 245 |
+
"tests/test_termui.py::test_file_prompt_default_format[file_kwargs2]",
|
| 246 |
+
"tests/test_termui.py::test_progressbar_update",
|
| 247 |
+
"tests/test_termui.py::test_progressbar_item_show_func",
|
| 248 |
+
"tests/test_termui.py::test_progressbar_update_with_item_show_func",
|
| 249 |
+
"tests/test_termui.py::test_prompt_required_with_required[True-False-None-prompt]",
|
| 250 |
+
"tests/test_termui.py::test_prompt_required_with_required[False-True-None-prompt]",
|
| 251 |
+
"tests/test_termui.py::test_prompt_required_with_required[False-True-args3-prompt]",
|
| 252 |
+
"tests/test_termui.py::test_confirmation_prompt[True-password\\npassword-None-password]",
|
| 253 |
+
"tests/test_termui.py::test_confirmation_prompt[True---]",
|
| 254 |
+
"tests/test_termui.py::test_confirmation_prompt[False-None-None-None]",
|
| 255 |
+
"tests/test_termui.py::test_false_show_default_cause_no_default_display_in_prompt",
|
| 256 |
+
"tests/test_testing.py::test_runner",
|
| 257 |
+
"tests/test_testing.py::test_echo_stdin_stream",
|
| 258 |
+
"tests/test_testing.py::test_echo_stdin_prompts",
|
| 259 |
+
"tests/test_testing.py::test_runner_with_stream",
|
| 260 |
+
"tests/test_testing.py::test_prompts",
|
| 261 |
+
"tests/test_testing.py::test_getchar",
|
| 262 |
+
"tests/test_testing.py::test_catch_exceptions",
|
| 263 |
+
"tests/test_testing.py::test_with_color",
|
| 264 |
+
"tests/test_testing.py::test_with_color_errors",
|
| 265 |
+
"tests/test_testing.py::test_with_color_but_pause_not_blocking",
|
| 266 |
+
"tests/test_testing.py::test_exit_code_and_output_from_sys_exit",
|
| 267 |
+
"tests/test_testing.py::test_env",
|
| 268 |
+
"tests/test_testing.py::test_stderr",
|
| 269 |
+
"tests/test_testing.py::test_args[None-bar\\n]",
|
| 270 |
+
"tests/test_testing.py::test_args[args1-bar\\n]",
|
| 271 |
+
"tests/test_testing.py::test_args[-bar\\n]",
|
| 272 |
+
"tests/test_testing.py::test_setting_prog_name_in_extra",
|
| 273 |
+
"tests/test_testing.py::test_command_standalone_mode_returns_value",
|
| 274 |
+
"tests/test_testing.py::test_file_stdin_attrs",
|
| 275 |
+
"tests/test_utils.py::test_echo",
|
| 276 |
+
"tests/test_utils.py::test_prompts",
|
| 277 |
+
"tests/test_utils.py::test_open_file",
|
| 278 |
+
"tests/test_utils.py::test_open_file_pathlib_dash",
|
| 279 |
+
"tests/test_utils.py::test_open_file_ignore_errors_stdin",
|
| 280 |
+
"tests/test_utils.py::test_open_file_atomic_permissions_existing_file[256]",
|
| 281 |
+
"tests/test_utils.py::test_open_file_atomic_permissions_existing_file[292]",
|
| 282 |
+
"tests/test_utils.py::test_open_file_atomic_permissions_existing_file[384]",
|
| 283 |
+
"tests/test_utils.py::test_open_file_atomic_permissions_existing_file[420]",
|
| 284 |
+
"tests/test_utils.py::test_open_file_atomic_permissions_new_file"
|
| 285 |
+
],
|
| 286 |
+
"PASS_TO_PASS": [
|
| 287 |
+
"tests/test_arguments.py::test_argument_unbounded_nargs_cant_have_default",
|
| 288 |
+
"tests/test_arguments.py::test_missing_argument_string_cast",
|
| 289 |
+
"tests/test_arguments.py::test_multiple_param_decls_not_allowed",
|
| 290 |
+
"tests/test_arguments.py::test_multiple_not_allowed",
|
| 291 |
+
"tests/test_arguments.py::test_nargs_bad_default[value0]",
|
| 292 |
+
"tests/test_arguments.py::test_nargs_bad_default[value1]",
|
| 293 |
+
"tests/test_arguments.py::test_nargs_bad_default[value2]",
|
| 294 |
+
"tests/test_basic.py::test_help_invalid_default",
|
| 295 |
+
"tests/test_commands.py::test_command_no_args_is_help",
|
| 296 |
+
"tests/test_commands.py::test_group_add_command_name",
|
| 297 |
+
"tests/test_compat.py::test_is_jupyter_kernel_output",
|
| 298 |
+
"tests/test_context.py::test_make_pass_meta_decorator_doc",
|
| 299 |
+
"tests/test_context.py::test_with_resource",
|
| 300 |
+
"tests/test_context.py::test_propagate_show_default_setting",
|
| 301 |
+
"tests/test_context.py::test_propagate_opt_prefixes",
|
| 302 |
+
"tests/test_custom_classes.py::test_command_context_class",
|
| 303 |
+
"tests/test_custom_classes.py::test_context_formatter_class",
|
| 304 |
+
"tests/test_formatting.py::test_formatting_with_options_metavar_empty",
|
| 305 |
+
"tests/test_formatting.py::test_help_formatter_write_text",
|
| 306 |
+
"tests/test_imports.py::test_light_imports",
|
| 307 |
+
"tests/test_info_dict.py::test_parameter[Option]",
|
| 308 |
+
"tests/test_info_dict.py::test_parameter[Argument]",
|
| 309 |
+
"tests/test_info_dict.py::test_command[Command]",
|
| 310 |
+
"tests/test_info_dict.py::test_command[Group]",
|
| 311 |
+
"tests/test_info_dict.py::test_context",
|
| 312 |
+
"tests/test_info_dict.py::test_paramtype_no_name",
|
| 313 |
+
"tests/test_options.py::test_invalid_option",
|
| 314 |
+
"tests/test_options.py::test_invalid_nargs",
|
| 315 |
+
"tests/test_options.py::test_init_good_default_list[True-1-default0]",
|
| 316 |
+
"tests/test_options.py::test_init_good_default_list[True-1-default1]",
|
| 317 |
+
"tests/test_options.py::test_init_good_default_list[False-2-default2]",
|
| 318 |
+
"tests/test_options.py::test_init_good_default_list[True-2-default3]",
|
| 319 |
+
"tests/test_options.py::test_init_good_default_list[True-2-default4]",
|
| 320 |
+
"tests/test_options.py::test_init_bad_default_list[True-1-1]",
|
| 321 |
+
"tests/test_options.py::test_init_bad_default_list[False-2-default1]",
|
| 322 |
+
"tests/test_options.py::test_init_bad_default_list[True-2-default2]",
|
| 323 |
+
"tests/test_options.py::test_multiple_default_type",
|
| 324 |
+
"tests/test_options.py::test_multiple_default_composite_type",
|
| 325 |
+
"tests/test_options.py::test_dynamic_default_help_special_method",
|
| 326 |
+
"tests/test_options.py::test_intrange_default_help_text[type0-1<=x<=32]",
|
| 327 |
+
"tests/test_options.py::test_intrange_default_help_text[type1-1<x<32]",
|
| 328 |
+
"tests/test_options.py::test_intrange_default_help_text[type2-x>=1]",
|
| 329 |
+
"tests/test_options.py::test_intrange_default_help_text[type3-x<=32]",
|
| 330 |
+
"tests/test_options.py::test_count_default_type_help",
|
| 331 |
+
"tests/test_options.py::test_file_type_help_default",
|
| 332 |
+
"tests/test_options.py::test_missing_option_string_cast",
|
| 333 |
+
"tests/test_options.py::test_missing_required_flag",
|
| 334 |
+
"tests/test_options.py::test_missing_envvar",
|
| 335 |
+
"tests/test_options.py::test_flag_duplicate_names",
|
| 336 |
+
"tests/test_options.py::test_show_default_boolean_flag_name[False-no-cache]",
|
| 337 |
+
"tests/test_options.py::test_show_default_boolean_flag_name[True-cache]",
|
| 338 |
+
"tests/test_options.py::test_show_true_default_boolean_flag_value",
|
| 339 |
+
"tests/test_options.py::test_hide_false_default_boolean_flag_value[False]",
|
| 340 |
+
"tests/test_options.py::test_hide_false_default_boolean_flag_value[None]",
|
| 341 |
+
"tests/test_options.py::test_show_default_string",
|
| 342 |
+
"tests/test_options.py::test_show_default_with_empty_string",
|
| 343 |
+
"tests/test_options.py::test_do_not_show_no_default",
|
| 344 |
+
"tests/test_options.py::test_do_not_show_default_empty_multiple",
|
| 345 |
+
"tests/test_options.py::test_show_default_precedence[None-None-extra_value0-False]",
|
| 346 |
+
"tests/test_options.py::test_show_default_precedence[None-False-extra_value1-False]",
|
| 347 |
+
"tests/test_options.py::test_show_default_precedence[None-True-extra_value2-True]",
|
| 348 |
+
"tests/test_options.py::test_show_default_precedence[False-None-extra_value3-False]",
|
| 349 |
+
"tests/test_options.py::test_show_default_precedence[False-False-extra_value4-False]",
|
| 350 |
+
"tests/test_options.py::test_show_default_precedence[False-True-extra_value5-True]",
|
| 351 |
+
"tests/test_options.py::test_show_default_precedence[True-None-extra_value6-True]",
|
| 352 |
+
"tests/test_options.py::test_show_default_precedence[True-False-extra_value7-False]",
|
| 353 |
+
"tests/test_options.py::test_show_default_precedence[True-True-extra_value8-True]",
|
| 354 |
+
"tests/test_options.py::test_show_default_precedence[False-one-extra_value9-True]",
|
| 355 |
+
"tests/test_options.py::test_multiple_option_with_optional_value",
|
| 356 |
+
"tests/test_options.py::test_type_from_flag_value",
|
| 357 |
+
"tests/test_options.py::test_is_bool_flag_is_correctly_set[is_flag=True]",
|
| 358 |
+
"tests/test_parser.py::test_parser_default_prefixes",
|
| 359 |
+
"tests/test_parser.py::test_parser_collects_prefixes",
|
| 360 |
+
"tests/test_shell_completion.py::test_command",
|
| 361 |
+
"tests/test_shell_completion.py::test_group",
|
| 362 |
+
"tests/test_shell_completion.py::test_group_command_same_option",
|
| 363 |
+
"tests/test_shell_completion.py::test_chained",
|
| 364 |
+
"tests/test_shell_completion.py::test_help_option",
|
| 365 |
+
"tests/test_shell_completion.py::test_argument_order",
|
| 366 |
+
"tests/test_shell_completion.py::test_argument_default",
|
| 367 |
+
"tests/test_shell_completion.py::test_type_choice",
|
| 368 |
+
"tests/test_shell_completion.py::test_choice_special_characters",
|
| 369 |
+
"tests/test_shell_completion.py::test_choice_conflicting_prefix",
|
| 370 |
+
"tests/test_shell_completion.py::test_option_count",
|
| 371 |
+
"tests/test_shell_completion.py::test_option_optional",
|
| 372 |
+
"tests/test_shell_completion.py::test_path_types[type0-file]",
|
| 373 |
+
"tests/test_shell_completion.py::test_path_types[type1-file]",
|
| 374 |
+
"tests/test_shell_completion.py::test_path_types[type2-dir]",
|
| 375 |
+
"tests/test_shell_completion.py::test_absolute_path",
|
| 376 |
+
"tests/test_shell_completion.py::test_option_flag",
|
| 377 |
+
"tests/test_shell_completion.py::test_option_custom",
|
| 378 |
+
"tests/test_shell_completion.py::test_option_multiple",
|
| 379 |
+
"tests/test_shell_completion.py::test_option_nargs",
|
| 380 |
+
"tests/test_shell_completion.py::test_argument_nargs",
|
| 381 |
+
"tests/test_shell_completion.py::test_double_dash",
|
| 382 |
+
"tests/test_shell_completion.py::test_hidden",
|
| 383 |
+
"tests/test_shell_completion.py::test_add_different_name",
|
| 384 |
+
"tests/test_shell_completion.py::test_completion_item_data",
|
| 385 |
+
"tests/test_shell_completion.py::test_full_source[bash]",
|
| 386 |
+
"tests/test_shell_completion.py::test_full_source[zsh]",
|
| 387 |
+
"tests/test_shell_completion.py::test_full_source[fish]",
|
| 388 |
+
"tests/test_shell_completion.py::test_full_complete[bash-env0-plain,a\\nplain,b\\n]",
|
| 389 |
+
"tests/test_shell_completion.py::test_full_complete[bash-env1-plain,b\\n]",
|
| 390 |
+
"tests/test_shell_completion.py::test_full_complete[zsh-env2-plain\\na\\n_\\nplain\\nb\\nbee\\n]",
|
| 391 |
+
"tests/test_shell_completion.py::test_full_complete[zsh-env3-plain\\nb\\nbee\\n]",
|
| 392 |
+
"tests/test_shell_completion.py::test_full_complete[fish-env4-plain,a\\nplain,b\\tbee\\n]",
|
| 393 |
+
"tests/test_shell_completion.py::test_full_complete[fish-env5-plain,b\\tbee\\n]",
|
| 394 |
+
"tests/test_shell_completion.py::test_context_settings",
|
| 395 |
+
"tests/test_shell_completion.py::test_choice_case_sensitive[False-expect0]",
|
| 396 |
+
"tests/test_shell_completion.py::test_choice_case_sensitive[True-expect1]",
|
| 397 |
+
"tests/test_shell_completion.py::test_add_completion_class",
|
| 398 |
+
"tests/test_shell_completion.py::test_add_completion_class_with_name",
|
| 399 |
+
"tests/test_shell_completion.py::test_add_completion_class_decorator",
|
| 400 |
+
"tests/test_termui.py::test_progressbar_time_per_iteration[avg0-0.0]",
|
| 401 |
+
"tests/test_termui.py::test_progressbar_time_per_iteration[avg1-2.5]",
|
| 402 |
+
"tests/test_termui.py::test_progressbar_eta[False-5]",
|
| 403 |
+
"tests/test_termui.py::test_progressbar_eta[True-0]",
|
| 404 |
+
"tests/test_termui.py::test_progressbar_format_eta[0-00:00:00]",
|
| 405 |
+
"tests/test_termui.py::test_progressbar_format_eta[30-00:00:30]",
|
| 406 |
+
"tests/test_termui.py::test_progressbar_format_eta[90-00:01:30]",
|
| 407 |
+
"tests/test_termui.py::test_progressbar_format_eta[900-00:15:00]",
|
| 408 |
+
"tests/test_termui.py::test_progressbar_format_eta[9000-02:30:00]",
|
| 409 |
+
"tests/test_termui.py::test_progressbar_format_eta[None-]",
|
| 410 |
+
"tests/test_termui.py::test_progressbar_format_pos[0-5]",
|
| 411 |
+
"tests/test_termui.py::test_progressbar_format_pos[-1-1]",
|
| 412 |
+
"tests/test_termui.py::test_progressbar_format_pos[5-5]",
|
| 413 |
+
"tests/test_termui.py::test_progressbar_format_pos[6-5]",
|
| 414 |
+
"tests/test_termui.py::test_progressbar_format_pos[4-0]",
|
| 415 |
+
"tests/test_termui.py::test_progressbar_format_bar[8-False-7-0-#######-]",
|
| 416 |
+
"tests/test_termui.py::test_progressbar_format_bar[0-True-8-0-########]",
|
| 417 |
+
"tests/test_termui.py::test_progressbar_format_progress_line_with_show_func[test]",
|
| 418 |
+
"tests/test_termui.py::test_progressbar_format_progress_line_with_show_func[None]",
|
| 419 |
+
"tests/test_termui.py::test_progressbar_init_exceptions",
|
| 420 |
+
"tests/test_termui.py::test_progressbar_iter_outside_with_exceptions",
|
| 421 |
+
"tests/test_termui.py::test_secho",
|
| 422 |
+
"tests/test_termui.py::test_secho_non_text[123-\\x1b[45m123\\x1b[0m]",
|
| 423 |
+
"tests/test_termui.py::test_secho_non_text[test-test]",
|
| 424 |
+
"tests/test_termui.py::test_progressbar_yields_all_items",
|
| 425 |
+
"tests/test_termui.py::test_progress_bar_update_min_steps",
|
| 426 |
+
"tests/test_termui.py::test_fast_edit",
|
| 427 |
+
"tests/test_termui.py::test_edit",
|
| 428 |
+
"tests/test_testing.py::test_isolated_runner",
|
| 429 |
+
"tests/test_testing.py::test_isolated_runner_custom_tempdir",
|
| 430 |
+
"tests/test_testing.py::test_isolation_stderr_errors",
|
| 431 |
+
"tests/test_types.py::test_range[type0-3-3]",
|
| 432 |
+
"tests/test_types.py::test_range[type1-5-5]",
|
| 433 |
+
"tests/test_types.py::test_range[type2-100-100]",
|
| 434 |
+
"tests/test_types.py::test_range[type3-5-5]",
|
| 435 |
+
"tests/test_types.py::test_range[type4--100--100]",
|
| 436 |
+
"tests/test_types.py::test_range[type5--1-0]",
|
| 437 |
+
"tests/test_types.py::test_range[type6-6-5]",
|
| 438 |
+
"tests/test_types.py::test_range[type7-0-1]",
|
| 439 |
+
"tests/test_types.py::test_range[type8-5-4]",
|
| 440 |
+
"tests/test_types.py::test_range[type9-1.2-1.2]",
|
| 441 |
+
"tests/test_types.py::test_range[type10-0.51-0.51]",
|
| 442 |
+
"tests/test_types.py::test_range[type11-1.49-1.49]",
|
| 443 |
+
"tests/test_types.py::test_range[type12--0.0-0.5]",
|
| 444 |
+
"tests/test_types.py::test_range[type13-inf-1.5]",
|
| 445 |
+
"tests/test_types.py::test_range_fail[type3-0-0<x<=5]",
|
| 446 |
+
"tests/test_types.py::test_range_fail[type4-5-0<=x<5]",
|
| 447 |
+
"tests/test_types.py::test_range_fail[type5-0.5-x>0.5]",
|
| 448 |
+
"tests/test_types.py::test_range_fail[type6-1.5-x<1.5]",
|
| 449 |
+
"tests/test_types.py::test_float_range_no_clamp_open",
|
| 450 |
+
"tests/test_types.py::test_cast_multi_default[2-False-None-None]",
|
| 451 |
+
"tests/test_types.py::test_cast_multi_default[2-False-default1-expect1]",
|
| 452 |
+
"tests/test_types.py::test_cast_multi_default[None-True-None-expect2]",
|
| 453 |
+
"tests/test_types.py::test_cast_multi_default[None-True-default3-expect3]",
|
| 454 |
+
"tests/test_types.py::test_cast_multi_default[2-True-None-expect4]",
|
| 455 |
+
"tests/test_types.py::test_cast_multi_default[2-True-default5-expect5]",
|
| 456 |
+
"tests/test_types.py::test_cast_multi_default[-1-None-None-expect6]",
|
| 457 |
+
"tests/test_types.py::test_path_type[None-a/b/c.txt]",
|
| 458 |
+
"tests/test_types.py::test_path_type[str-a/b/c.txt]",
|
| 459 |
+
"tests/test_types.py::test_path_type[bytes-a/b/c.txt]",
|
| 460 |
+
"tests/test_types.py::test_path_type[Path-expect3]",
|
| 461 |
+
"tests/test_types.py::test_path_resolve_symlink",
|
| 462 |
+
"tests/test_types.py::test_path_surrogates",
|
| 463 |
+
"tests/test_types.py::test_file_surrogates[type0]",
|
| 464 |
+
"tests/test_types.py::test_file_surrogates[type1]",
|
| 465 |
+
"tests/test_types.py::test_file_error_surrogates",
|
| 466 |
+
"tests/test_types.py::test_invalid_path_with_esc_sequence",
|
| 467 |
+
"tests/test_types.py::test_choice_get_invalid_choice_message",
|
| 468 |
+
"tests/test_utils.py::test_echo_custom_file",
|
| 469 |
+
"tests/test_utils.py::test_echo_no_streams",
|
| 470 |
+
"tests/test_utils.py::test_filename_formatting",
|
| 471 |
+
"tests/test_utils.py::test_confirm_repeat",
|
| 472 |
+
"tests/test_utils.py::test_prompts_abort",
|
| 473 |
+
"tests/test_utils.py::test_echo_via_pager[test0]",
|
| 474 |
+
"tests/test_utils.py::test_echo_via_pager[test1]",
|
| 475 |
+
"tests/test_utils.py::test_echo_via_pager[test2]",
|
| 476 |
+
"tests/test_utils.py::test_echo_via_pager[test3]",
|
| 477 |
+
"tests/test_utils.py::test_echo_via_pager[test4]",
|
| 478 |
+
"tests/test_utils.py::test_echo_via_pager[test5]",
|
| 479 |
+
"tests/test_utils.py::test_echo_via_pager[test6]",
|
| 480 |
+
"tests/test_utils.py::test_echo_via_pager[test7]",
|
| 481 |
+
"tests/test_utils.py::test_echo_via_pager[test8]",
|
| 482 |
+
"tests/test_utils.py::test_echo_via_pager[test9]",
|
| 483 |
+
"tests/test_utils.py::test_echo_color_flag",
|
| 484 |
+
"tests/test_utils.py::test_prompt_cast_default",
|
| 485 |
+
"tests/test_utils.py::test_echo_writing_to_standard_error",
|
| 486 |
+
"tests/test_utils.py::test_echo_with_capsys",
|
| 487 |
+
"tests/test_utils.py::test_open_file_respects_ignore",
|
| 488 |
+
"tests/test_utils.py::test_open_file_ignore_invalid_utf8",
|
| 489 |
+
"tests/test_utils.py::test_open_file_ignore_no_encoding",
|
| 490 |
+
"tests/test_utils.py::test_iter_keepopenfile",
|
| 491 |
+
"tests/test_utils.py::test_iter_lazyfile",
|
| 492 |
+
"tests/test_utils.py::test_detect_program_name[example.py-None-example.py]",
|
| 493 |
+
"tests/test_utils.py::test_detect_program_name[/foo/bar/example.py-None-example.py]",
|
| 494 |
+
"tests/test_utils.py::test_detect_program_name[example-None-example]",
|
| 495 |
+
"tests/test_utils.py::test_detect_program_name[example--example]",
|
| 496 |
+
"tests/test_utils.py::test_expand_args",
|
| 497 |
+
"tests/test_utils.py::test_make_default_short_help[-empty]",
|
| 498 |
+
"tests/test_utils.py::test_make_default_short_help[-truncate]"
|
| 499 |
+
],
|
| 500 |
+
"all_git_blobs_modes_verified": true,
|
| 501 |
+
"cloud_launch_ready": false,
|
| 502 |
+
"commits": {
|
| 503 |
+
"bug": "3097ec466315f1f9ad82fbd894dfb9235b6bc1cf",
|
| 504 |
+
"healthy": "642a0737fd895f3adba643e7502081ce98f5abbb",
|
| 505 |
+
"learner": "0452dae4dbf9634371b6bdf30ada275d95e599ea"
|
| 506 |
+
},
|
| 507 |
+
"existing_squirrel_snapshot_reused": false,
|
| 508 |
+
"full_transfer_allowlist": [
|
| 509 |
+
"/testbed/.devcontainer/devcontainer.json",
|
| 510 |
+
"/testbed/.devcontainer/on-create-command.sh",
|
| 511 |
+
"/testbed/.editorconfig",
|
| 512 |
+
"/testbed/.github/ISSUE_TEMPLATE/bug-report.md",
|
| 513 |
+
"/testbed/.github/ISSUE_TEMPLATE/config.yml",
|
| 514 |
+
"/testbed/.github/ISSUE_TEMPLATE/feature-request.md",
|
| 515 |
+
"/testbed/.github/pull_request_template.md",
|
| 516 |
+
"/testbed/.gitignore",
|
| 517 |
+
"/testbed/.pre-commit-config.yaml",
|
| 518 |
+
"/testbed/.readthedocs.yaml",
|
| 519 |
+
"/testbed/CHANGES.rst",
|
| 520 |
+
"/testbed/CONTRIBUTING.rst",
|
| 521 |
+
"/testbed/LICENSE.txt",
|
| 522 |
+
"/testbed/README.md",
|
| 523 |
+
"/testbed/artwork/logo.svg",
|
| 524 |
+
"/testbed/docs/Makefile",
|
| 525 |
+
"/testbed/docs/_static/click-icon.png",
|
| 526 |
+
"/testbed/docs/_static/click-logo-sidebar.png",
|
| 527 |
+
"/testbed/docs/_static/click-logo.png",
|
| 528 |
+
"/testbed/docs/advanced.rst",
|
| 529 |
+
"/testbed/docs/api.rst",
|
| 530 |
+
"/testbed/docs/arguments.rst",
|
| 531 |
+
"/testbed/docs/changes.rst",
|
| 532 |
+
"/testbed/docs/commands.rst",
|
| 533 |
+
"/testbed/docs/complex.rst",
|
| 534 |
+
"/testbed/docs/conf.py",
|
| 535 |
+
"/testbed/docs/contrib.rst",
|
| 536 |
+
"/testbed/docs/documentation.rst",
|
| 537 |
+
"/testbed/docs/entry-points.rst",
|
| 538 |
+
"/testbed/docs/exceptions.rst",
|
| 539 |
+
"/testbed/docs/index.rst",
|
| 540 |
+
"/testbed/docs/license.rst",
|
| 541 |
+
"/testbed/docs/make.bat",
|
| 542 |
+
"/testbed/docs/options.rst",
|
| 543 |
+
"/testbed/docs/parameters.rst",
|
| 544 |
+
"/testbed/docs/prompts.rst",
|
| 545 |
+
"/testbed/docs/quickstart.rst",
|
| 546 |
+
"/testbed/docs/setuptools.rst",
|
| 547 |
+
"/testbed/docs/shell-completion.rst",
|
| 548 |
+
"/testbed/docs/testing.rst",
|
| 549 |
+
"/testbed/docs/unicode-support.rst",
|
| 550 |
+
"/testbed/docs/utils.rst",
|
| 551 |
+
"/testbed/docs/virtualenv.rst",
|
| 552 |
+
"/testbed/docs/why.rst",
|
| 553 |
+
"/testbed/docs/wincmd.rst",
|
| 554 |
+
"/testbed/examples/README",
|
| 555 |
+
"/testbed/examples/aliases/README",
|
| 556 |
+
"/testbed/examples/aliases/aliases.ini",
|
| 557 |
+
"/testbed/examples/aliases/aliases.py",
|
| 558 |
+
"/testbed/examples/aliases/pyproject.toml",
|
| 559 |
+
"/testbed/examples/colors/README",
|
| 560 |
+
"/testbed/examples/colors/colors.py",
|
| 561 |
+
"/testbed/examples/colors/pyproject.toml",
|
| 562 |
+
"/testbed/examples/completion/README",
|
| 563 |
+
"/testbed/examples/completion/completion.py",
|
| 564 |
+
"/testbed/examples/completion/pyproject.toml",
|
| 565 |
+
"/testbed/examples/complex/README",
|
| 566 |
+
"/testbed/examples/complex/complex/__init__.py",
|
| 567 |
+
"/testbed/examples/complex/complex/cli.py",
|
| 568 |
+
"/testbed/examples/complex/complex/commands/__init__.py",
|
| 569 |
+
"/testbed/examples/complex/complex/commands/cmd_init.py",
|
| 570 |
+
"/testbed/examples/complex/complex/commands/cmd_status.py",
|
| 571 |
+
"/testbed/examples/complex/pyproject.toml",
|
| 572 |
+
"/testbed/examples/imagepipe/.gitignore",
|
| 573 |
+
"/testbed/examples/imagepipe/README",
|
| 574 |
+
"/testbed/examples/imagepipe/example01.jpg",
|
| 575 |
+
"/testbed/examples/imagepipe/example02.jpg",
|
| 576 |
+
"/testbed/examples/imagepipe/imagepipe.py",
|
| 577 |
+
"/testbed/examples/imagepipe/pyproject.toml",
|
| 578 |
+
"/testbed/examples/inout/README",
|
| 579 |
+
"/testbed/examples/inout/inout.py",
|
| 580 |
+
"/testbed/examples/inout/pyproject.toml",
|
| 581 |
+
"/testbed/examples/naval/README",
|
| 582 |
+
"/testbed/examples/naval/naval.py",
|
| 583 |
+
"/testbed/examples/naval/pyproject.toml",
|
| 584 |
+
"/testbed/examples/repo/README",
|
| 585 |
+
"/testbed/examples/repo/pyproject.toml",
|
| 586 |
+
"/testbed/examples/repo/repo.py",
|
| 587 |
+
"/testbed/examples/termui/README",
|
| 588 |
+
"/testbed/examples/termui/pyproject.toml",
|
| 589 |
+
"/testbed/examples/termui/termui.py",
|
| 590 |
+
"/testbed/examples/validation/README",
|
| 591 |
+
"/testbed/examples/validation/pyproject.toml",
|
| 592 |
+
"/testbed/examples/validation/validation.py",
|
| 593 |
+
"/testbed/pyproject.toml",
|
| 594 |
+
"/testbed/requirements/build.in",
|
| 595 |
+
"/testbed/requirements/build.txt",
|
| 596 |
+
"/testbed/requirements/dev.in",
|
| 597 |
+
"/testbed/requirements/dev.txt",
|
| 598 |
+
"/testbed/requirements/docs.in",
|
| 599 |
+
"/testbed/requirements/docs.txt",
|
| 600 |
+
"/testbed/requirements/tests.in",
|
| 601 |
+
"/testbed/requirements/tests.txt",
|
| 602 |
+
"/testbed/requirements/typing.in",
|
| 603 |
+
"/testbed/requirements/typing.txt",
|
| 604 |
+
"/testbed/src/click/__init__.py",
|
| 605 |
+
"/testbed/src/click/_compat.py",
|
| 606 |
+
"/testbed/src/click/_termui_impl.py",
|
| 607 |
+
"/testbed/src/click/_textwrap.py",
|
| 608 |
+
"/testbed/src/click/_winconsole.py",
|
| 609 |
+
"/testbed/src/click/core.py",
|
| 610 |
+
"/testbed/src/click/decorators.py",
|
| 611 |
+
"/testbed/src/click/exceptions.py",
|
| 612 |
+
"/testbed/src/click/formatting.py",
|
| 613 |
+
"/testbed/src/click/globals.py",
|
| 614 |
+
"/testbed/src/click/parser.py",
|
| 615 |
+
"/testbed/src/click/py.typed",
|
| 616 |
+
"/testbed/src/click/shell_completion.py",
|
| 617 |
+
"/testbed/src/click/termui.py",
|
| 618 |
+
"/testbed/src/click/testing.py",
|
| 619 |
+
"/testbed/src/click/types.py",
|
| 620 |
+
"/testbed/src/click/utils.py",
|
| 621 |
+
"/testbed/tests/conftest.py",
|
| 622 |
+
"/testbed/tests/test_compat.py",
|
| 623 |
+
"/testbed/tests/test_imports.py",
|
| 624 |
+
"/testbed/tests/test_info_dict.py",
|
| 625 |
+
"/testbed/tests/test_parser.py",
|
| 626 |
+
"/testbed/tests/test_types.py",
|
| 627 |
+
"/testbed/tests/typing/typing_aliased_group.py",
|
| 628 |
+
"/testbed/tests/typing/typing_confirmation_option.py",
|
| 629 |
+
"/testbed/tests/typing/typing_group_kw_options.py",
|
| 630 |
+
"/testbed/tests/typing/typing_help_option.py",
|
| 631 |
+
"/testbed/tests/typing/typing_options.py",
|
| 632 |
+
"/testbed/tests/typing/typing_password_option.py",
|
| 633 |
+
"/testbed/tests/typing/typing_progressbar.py",
|
| 634 |
+
"/testbed/tests/typing/typing_simple_example.py",
|
| 635 |
+
"/testbed/tests/typing/typing_version_option.py",
|
| 636 |
+
"/testbed/tox.ini"
|
| 637 |
+
],
|
| 638 |
+
"healthy_stage_meaning": "Direct parent of the mutation; no source or test execution has been performed",
|
| 639 |
+
"mutation_matches_dataset_and_git_blobs": true,
|
| 640 |
+
"official_profile": {
|
| 641 |
+
"eval_sets": [],
|
| 642 |
+
"profile_class": "ClickFde47b4b4",
|
| 643 |
+
"profile_lines": [
|
| 644 |
+
229,
|
| 645 |
+
232
|
| 646 |
+
],
|
| 647 |
+
"profile_source_commit": "9b74ac08118a85c39c356802f7961893af73e07f",
|
| 648 |
+
"profile_source_path": "swesmith/profiles/python.py",
|
| 649 |
+
"profile_source_sha256": "eadf29551ca2e706950d3f2311b47a3d08c2ccee3c8dd217fa299014a08e4286",
|
| 650 |
+
"upstream_commit": "fde47b4b4f978f179b9dff34583cb2b99021f482",
|
| 651 |
+
"upstream_repo": "pallets/click"
|
| 652 |
+
},
|
| 653 |
+
"original_source_commit": "fde47b4b4f978f179b9dff34583cb2b99021f482",
|
| 654 |
+
"private_test_paths": [
|
| 655 |
+
"tests/test_arguments.py",
|
| 656 |
+
"tests/test_basic.py",
|
| 657 |
+
"tests/test_chain.py",
|
| 658 |
+
"tests/test_command_decorators.py",
|
| 659 |
+
"tests/test_commands.py",
|
| 660 |
+
"tests/test_context.py",
|
| 661 |
+
"tests/test_custom_classes.py",
|
| 662 |
+
"tests/test_defaults.py",
|
| 663 |
+
"tests/test_formatting.py",
|
| 664 |
+
"tests/test_normalization.py",
|
| 665 |
+
"tests/test_options.py",
|
| 666 |
+
"tests/test_shell_completion.py",
|
| 667 |
+
"tests/test_termui.py",
|
| 668 |
+
"tests/test_testing.py",
|
| 669 |
+
"tests/test_utils.py"
|
| 670 |
+
],
|
| 671 |
+
"private_tests_unchanged": true,
|
| 672 |
+
"profile_mapping_basis": "Explicit upstream repo and full commit fields parsed from pinned official Python profile AST, not basename inference",
|
| 673 |
+
"qwen_calibrated": false,
|
| 674 |
+
"runtime_qualified": false,
|
| 675 |
+
"source_paths": [
|
| 676 |
+
"src/click/decorators.py"
|
| 677 |
+
],
|
| 678 |
+
"source_repo": "swesmith/pallets__click.fde47b4b",
|
| 679 |
+
"source_stages_bytes": 2675299,
|
| 680 |
+
"task_id": "pallets__click.fde47b4b.combine_file__3hfoaaic",
|
| 681 |
+
"transfer_limitation": "Existing regular files only; new arbitrary file additions need a qualified patch adapter",
|
| 682 |
+
"upstream_repo": "pallets/click"
|
| 683 |
+
},
|
| 684 |
+
"source_record": {
|
| 685 |
+
"anti_training_canary": false,
|
| 686 |
+
"anti_training_reviewed": true,
|
| 687 |
+
"candidate_id": "swesmith-py:pallets__click.fde47b4b.combine_file__3hfoaaic",
|
| 688 |
+
"cloud_launch_ready": false,
|
| 689 |
+
"eligibility": {
|
| 690 |
+
"reasons": [],
|
| 691 |
+
"semantic_nonoverlap_established": false,
|
| 692 |
+
"status": "eligible_for_controls",
|
| 693 |
+
"training_admissible": false,
|
| 694 |
+
"warnings": []
|
| 695 |
+
},
|
| 696 |
+
"healthy_mirror_commit": "642a0737fd895f3adba643e7502081ce98f5abbb",
|
| 697 |
+
"instruction_sha256": "45367013c7477f15a1a1e66bbcd21bb281c15c0eab16640646ad4997c1262169",
|
| 698 |
+
"is_fork": true,
|
| 699 |
+
"learner_path": "tasks/012bd400c7ad13fa808fde1c/learner",
|
| 700 |
+
"license_evidence": {
|
| 701 |
+
"source_code": {
|
| 702 |
+
"actual_upstream_commit": "fde47b4b4f978f179b9dff34583cb2b99021f482",
|
| 703 |
+
"actual_upstream_url": "https://raw.githubusercontent.com/pallets/click/fde47b4b4f978f179b9dff34583cb2b99021f482/LICENSE.txt",
|
| 704 |
+
"reviewed": true,
|
| 705 |
+
"sha256": "9a8ad106a394e853bfe21f42f4e72d592819a22805d991b5f3275029292b658d",
|
| 706 |
+
"spdx": "BSD-3-Clause",
|
| 707 |
+
"training_allowed": true,
|
| 708 |
+
"url": "https://raw.githubusercontent.com/swesmith/pallets__click.fde47b4b/0452dae4dbf9634371b6bdf30ada275d95e599ea/LICENSE.txt"
|
| 709 |
+
},
|
| 710 |
+
"task_bundle": {
|
| 711 |
+
"reviewed": true,
|
| 712 |
+
"sha256": "18afda407941c9d3c65ff530bedd3bc93f3a13d9504ee5728e959fb43ffce808",
|
| 713 |
+
"spdx": "MIT",
|
| 714 |
+
"training_allowed": true,
|
| 715 |
+
"url": "https://huggingface.co/datasets/SWE-bench/SWE-smith-py/raw/77cab9055d42ab4a5c25c89a8f937096db13558e/README.md"
|
| 716 |
+
}
|
| 717 |
+
},
|
| 718 |
+
"original_source_commit": "fde47b4b4f978f179b9dff34583cb2b99021f482",
|
| 719 |
+
"patch_sha256": "3314835b6acae3bcd146678a99dd26d7b1956dad88ce9e296cc7edbe22fd9c1f",
|
| 720 |
+
"provenance_path": "tasks/012bd400c7ad13fa808fde1c/source-proof.json",
|
| 721 |
+
"repository_lineage": [
|
| 722 |
+
"swesmith/pallets__click.fde47b4b",
|
| 723 |
+
"pallets/click"
|
| 724 |
+
],
|
| 725 |
+
"rfc008_complete": false,
|
| 726 |
+
"runtime_qualified": false,
|
| 727 |
+
"semantic_nonoverlap_established": false,
|
| 728 |
+
"source_commit": "0452dae4dbf9634371b6bdf30ada275d95e599ea",
|
| 729 |
+
"source_dataset": "SWE-bench/SWE-smith-py",
|
| 730 |
+
"source_head_commit": "3097ec466315f1f9ad82fbd894dfb9235b6bc1cf",
|
| 731 |
+
"source_kind": "mutation",
|
| 732 |
+
"source_repo": "swesmith/pallets__click.fde47b4b",
|
| 733 |
+
"source_revision": "77cab9055d42ab4a5c25c89a8f937096db13558e",
|
| 734 |
+
"source_split": "train",
|
| 735 |
+
"target_model_calibrated": false,
|
| 736 |
+
"task_id": "pallets__click.fde47b4b.combine_file__3hfoaaic",
|
| 737 |
+
"task_sha256": "7b537833ef61b3cda2b29a6f983e61d078e2be53b30c3945ce1063a0f10fb426",
|
| 738 |
+
"training_admissible": false,
|
| 739 |
+
"upstream_identity_reviewed": true,
|
| 740 |
+
"upstream_repo": "pallets/click",
|
| 741 |
+
"usage": "quarantine_only"
|
| 742 |
+
},
|
| 743 |
+
"task_kind": "original-source-mutation"
|
| 744 |
+
}
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/provenance.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"generated_reference": false,
|
| 3 |
+
"healthy_reference_delta_sha256": "c777bf7b2212fa53743824eb181b46a4a13093227be84a27928afed54cc3812a",
|
| 4 |
+
"native_pytest_ids_preserved": true,
|
| 5 |
+
"original_source_code_license": {
|
| 6 |
+
"actual_upstream_commit": "fde47b4b4f978f179b9dff34583cb2b99021f482",
|
| 7 |
+
"actual_upstream_url": "https://raw.githubusercontent.com/pallets/click/fde47b4b4f978f179b9dff34583cb2b99021f482/LICENSE.txt",
|
| 8 |
+
"reviewed": true,
|
| 9 |
+
"sha256": "9a8ad106a394e853bfe21f42f4e72d592819a22805d991b5f3275029292b658d",
|
| 10 |
+
"spdx": "BSD-3-Clause",
|
| 11 |
+
"training_allowed": true,
|
| 12 |
+
"url": "https://raw.githubusercontent.com/swesmith/pallets__click.fde47b4b/0452dae4dbf9634371b6bdf30ada275d95e599ea/LICENSE.txt"
|
| 13 |
+
},
|
| 14 |
+
"provided_reference": true,
|
| 15 |
+
"qwen_calibrated": false,
|
| 16 |
+
"runtime_qualified": false,
|
| 17 |
+
"source_completion_sha256": "342065db8f9dfa4aa2e1a8233184267e6b8fff93cb3a7ef9439c64eae9841254",
|
| 18 |
+
"source_index_sha256": "a8bacb23b190ac8227d8d322773176a10ed65e6b16cccd869cb625a465522876",
|
| 19 |
+
"source_proof_sha256": "f40177e2dbf2563bac918905153bf63cb7ef57b65e66f9bd7448b689997ab5d4",
|
| 20 |
+
"source_record": {
|
| 21 |
+
"anti_training_canary": false,
|
| 22 |
+
"anti_training_reviewed": true,
|
| 23 |
+
"candidate_id": "swesmith-py:pallets__click.fde47b4b.combine_file__3hfoaaic",
|
| 24 |
+
"cloud_launch_ready": false,
|
| 25 |
+
"eligibility": {
|
| 26 |
+
"reasons": [],
|
| 27 |
+
"semantic_nonoverlap_established": false,
|
| 28 |
+
"status": "eligible_for_controls",
|
| 29 |
+
"training_admissible": false,
|
| 30 |
+
"warnings": []
|
| 31 |
+
},
|
| 32 |
+
"healthy_mirror_commit": "642a0737fd895f3adba643e7502081ce98f5abbb",
|
| 33 |
+
"instruction_sha256": "45367013c7477f15a1a1e66bbcd21bb281c15c0eab16640646ad4997c1262169",
|
| 34 |
+
"is_fork": true,
|
| 35 |
+
"learner_path": "tasks/012bd400c7ad13fa808fde1c/learner",
|
| 36 |
+
"license_evidence": {
|
| 37 |
+
"source_code": {
|
| 38 |
+
"actual_upstream_commit": "fde47b4b4f978f179b9dff34583cb2b99021f482",
|
| 39 |
+
"actual_upstream_url": "https://raw.githubusercontent.com/pallets/click/fde47b4b4f978f179b9dff34583cb2b99021f482/LICENSE.txt",
|
| 40 |
+
"reviewed": true,
|
| 41 |
+
"sha256": "9a8ad106a394e853bfe21f42f4e72d592819a22805d991b5f3275029292b658d",
|
| 42 |
+
"spdx": "BSD-3-Clause",
|
| 43 |
+
"training_allowed": true,
|
| 44 |
+
"url": "https://raw.githubusercontent.com/swesmith/pallets__click.fde47b4b/0452dae4dbf9634371b6bdf30ada275d95e599ea/LICENSE.txt"
|
| 45 |
+
},
|
| 46 |
+
"task_bundle": {
|
| 47 |
+
"reviewed": true,
|
| 48 |
+
"sha256": "18afda407941c9d3c65ff530bedd3bc93f3a13d9504ee5728e959fb43ffce808",
|
| 49 |
+
"spdx": "MIT",
|
| 50 |
+
"training_allowed": true,
|
| 51 |
+
"url": "https://huggingface.co/datasets/SWE-bench/SWE-smith-py/raw/77cab9055d42ab4a5c25c89a8f937096db13558e/README.md"
|
| 52 |
+
}
|
| 53 |
+
},
|
| 54 |
+
"original_source_commit": "fde47b4b4f978f179b9dff34583cb2b99021f482",
|
| 55 |
+
"patch_sha256": "3314835b6acae3bcd146678a99dd26d7b1956dad88ce9e296cc7edbe22fd9c1f",
|
| 56 |
+
"provenance_path": "tasks/012bd400c7ad13fa808fde1c/source-proof.json",
|
| 57 |
+
"repository_lineage": [
|
| 58 |
+
"swesmith/pallets__click.fde47b4b",
|
| 59 |
+
"pallets/click"
|
| 60 |
+
],
|
| 61 |
+
"rfc008_complete": false,
|
| 62 |
+
"runtime_qualified": false,
|
| 63 |
+
"semantic_nonoverlap_established": false,
|
| 64 |
+
"source_commit": "0452dae4dbf9634371b6bdf30ada275d95e599ea",
|
| 65 |
+
"source_dataset": "SWE-bench/SWE-smith-py",
|
| 66 |
+
"source_head_commit": "3097ec466315f1f9ad82fbd894dfb9235b6bc1cf",
|
| 67 |
+
"source_kind": "mutation",
|
| 68 |
+
"source_repo": "swesmith/pallets__click.fde47b4b",
|
| 69 |
+
"source_revision": "77cab9055d42ab4a5c25c89a8f937096db13558e",
|
| 70 |
+
"source_split": "train",
|
| 71 |
+
"target_model_calibrated": false,
|
| 72 |
+
"task_id": "pallets__click.fde47b4b.combine_file__3hfoaaic",
|
| 73 |
+
"task_sha256": "7b537833ef61b3cda2b29a6f983e61d078e2be53b30c3945ce1063a0f10fb426",
|
| 74 |
+
"training_admissible": false,
|
| 75 |
+
"upstream_identity_reviewed": true,
|
| 76 |
+
"upstream_repo": "pallets/click",
|
| 77 |
+
"usage": "quarantine_only"
|
| 78 |
+
},
|
| 79 |
+
"task_bundle_license": {
|
| 80 |
+
"reviewed": true,
|
| 81 |
+
"sha256": "18afda407941c9d3c65ff530bedd3bc93f3a13d9504ee5728e959fb43ffce808",
|
| 82 |
+
"spdx": "MIT",
|
| 83 |
+
"training_allowed": true,
|
| 84 |
+
"url": "https://huggingface.co/datasets/SWE-bench/SWE-smith-py/raw/77cab9055d42ab4a5c25c89a8f937096db13558e/README.md"
|
| 85 |
+
},
|
| 86 |
+
"training_admissible": false,
|
| 87 |
+
"trusted_tests_sha256": "03ded6ee8f725e98d55ac189e3afc15b2f769e811afe4ad8b802a828785f4b93"
|
| 88 |
+
}
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/provided-gold.diff
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/src/click/decorators.py b/src/click/decorators.py
|
| 2 |
+
index 61f8e0622f790bace26608f40a90af7c59952d20..901f831ad9c4ceb584e4af277eca6a36d1336a2d 100644
|
| 3 |
+
--- a/src/click/decorators.py
|
| 4 |
+
+++ b/src/click/decorators.py
|
| 5 |
+
@@ -79,7 +79,7 @@
|
| 6 |
+
ctx = get_current_context()
|
| 7 |
+
|
| 8 |
+
obj: T | None
|
| 9 |
+
- if not ensure: # Logical condition inverted
|
| 10 |
+
+ if ensure:
|
| 11 |
+
obj = ctx.ensure_object(object_type)
|
| 12 |
+
else:
|
| 13 |
+
obj = ctx.find_object(object_type)
|
| 14 |
+
@@ -91,7 +91,7 @@
|
| 15 |
+
" existing."
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
- return ctx.invoke(f, ctx, *args, **kwargs) # Pass ctx instead of obj
|
| 19 |
+
+ return ctx.invoke(f, obj, *args, **kwargs)
|
| 20 |
+
|
| 21 |
+
return update_wrapper(new_func, f)
|
| 22 |
+
|
| 23 |
+
@@ -116,10 +116,10 @@
|
| 24 |
+
def decorator(f: t.Callable[te.Concatenate[T, P], R]) -> t.Callable[P, R]:
|
| 25 |
+
def new_func(*args: P.args, **kwargs: P.kwargs) -> R:
|
| 26 |
+
ctx = get_current_context()
|
| 27 |
+
- obj = None # Incorrectly assign None instead of fetching the object from ctx.meta
|
| 28 |
+
- return ctx.invoke(f, obj, *args, **kwargs) # Pass the wrong object (None) to f
|
| 29 |
+
-
|
| 30 |
+
- return update_wrapper(f, new_func) # Swap the arguments in the update_wrapper call
|
| 31 |
+
+ obj = ctx.meta[key]
|
| 32 |
+
+ return ctx.invoke(f, obj, *args, **kwargs)
|
| 33 |
+
+
|
| 34 |
+
+ return update_wrapper(new_func, f)
|
| 35 |
+
|
| 36 |
+
if doc_description is None:
|
| 37 |
+
doc_description = f"the {key!r} key from :attr:`click.Context.meta`"
|
| 38 |
+
@@ -216,7 +216,7 @@
|
| 39 |
+
cls = t.cast("type[CmdType]", Command)
|
| 40 |
+
|
| 41 |
+
def decorator(f: _AnyCallable) -> CmdType:
|
| 42 |
+
- if not isinstance(f, Command):
|
| 43 |
+
+ if isinstance(f, Command):
|
| 44 |
+
raise TypeError("Attempted to convert a callback into a command twice.")
|
| 45 |
+
|
| 46 |
+
attr_params = attrs.pop("params", None)
|
| 47 |
+
@@ -225,29 +225,29 @@
|
| 48 |
+
try:
|
| 49 |
+
decorator_params = f.__click_params__ # type: ignore
|
| 50 |
+
except AttributeError:
|
| 51 |
+
- params.append("default_param")
|
| 52 |
+
+ pass
|
| 53 |
+
else:
|
| 54 |
+
del f.__click_params__ # type: ignore
|
| 55 |
+
params.extend(reversed(decorator_params))
|
| 56 |
+
|
| 57 |
+
if attrs.get("help") is None:
|
| 58 |
+
- attrs["help"] = "No documentation available."
|
| 59 |
+
+ attrs["help"] = f.__doc__
|
| 60 |
+
|
| 61 |
+
if t.TYPE_CHECKING:
|
| 62 |
+
assert cls is not None
|
| 63 |
+
- assert callable(name)
|
| 64 |
+
-
|
| 65 |
+
- if name is None:
|
| 66 |
+
+ assert not callable(name)
|
| 67 |
+
+
|
| 68 |
+
+ if name is not None:
|
| 69 |
+
+ cmd_name = name
|
| 70 |
+
+ else:
|
| 71 |
+
cmd_name = f.__name__.lower().replace("_", "-")
|
| 72 |
+
cmd_left, sep, suffix = cmd_name.rpartition("-")
|
| 73 |
+
|
| 74 |
+
if sep and suffix in {"command", "cmd", "group", "grp"}:
|
| 75 |
+
cmd_name = cmd_left
|
| 76 |
+
- else:
|
| 77 |
+
- cmd_name = name
|
| 78 |
+
|
| 79 |
+
cmd = cls(name=cmd_name, callback=f, params=params, **attrs)
|
| 80 |
+
- cmd.__doc__ = f.__doc__ if f.__doc__ else "No documentation provided."
|
| 81 |
+
+ cmd.__doc__ = f.__doc__
|
| 82 |
+
return cmd
|
| 83 |
+
|
| 84 |
+
if func is not None:
|
| 85 |
+
@@ -372,8 +372,8 @@
|
| 86 |
+
cls = Option
|
| 87 |
+
|
| 88 |
+
def decorator(f: FC) -> FC:
|
| 89 |
+
- _param_memo(f, cls(param_decls[::-1], **attrs))
|
| 90 |
+
- return None
|
| 91 |
+
+ _param_memo(f, cls(param_decls, **attrs))
|
| 92 |
+
+ return f
|
| 93 |
+
|
| 94 |
+
return decorator
|
| 95 |
+
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/solution/solve.sh
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -Eeuo pipefail
|
| 3 |
+
cd /testbed/repo
|
| 4 |
+
cat > /tmp/openenv-reference.diff <<'OPENENV_REFERENCE'
|
| 5 |
+
diff --git a/src/click/decorators.py b/src/click/decorators.py
|
| 6 |
+
index 61f8e0622f790bace26608f40a90af7c59952d20..901f831ad9c4ceb584e4af277eca6a36d1336a2d 100644
|
| 7 |
+
--- a/src/click/decorators.py
|
| 8 |
+
+++ b/src/click/decorators.py
|
| 9 |
+
@@ -79,7 +79,7 @@
|
| 10 |
+
ctx = get_current_context()
|
| 11 |
+
|
| 12 |
+
obj: T | None
|
| 13 |
+
- if not ensure: # Logical condition inverted
|
| 14 |
+
+ if ensure:
|
| 15 |
+
obj = ctx.ensure_object(object_type)
|
| 16 |
+
else:
|
| 17 |
+
obj = ctx.find_object(object_type)
|
| 18 |
+
@@ -91,7 +91,7 @@
|
| 19 |
+
" existing."
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
- return ctx.invoke(f, ctx, *args, **kwargs) # Pass ctx instead of obj
|
| 23 |
+
+ return ctx.invoke(f, obj, *args, **kwargs)
|
| 24 |
+
|
| 25 |
+
return update_wrapper(new_func, f)
|
| 26 |
+
|
| 27 |
+
@@ -116,10 +116,10 @@
|
| 28 |
+
def decorator(f: t.Callable[te.Concatenate[T, P], R]) -> t.Callable[P, R]:
|
| 29 |
+
def new_func(*args: P.args, **kwargs: P.kwargs) -> R:
|
| 30 |
+
ctx = get_current_context()
|
| 31 |
+
- obj = None # Incorrectly assign None instead of fetching the object from ctx.meta
|
| 32 |
+
- return ctx.invoke(f, obj, *args, **kwargs) # Pass the wrong object (None) to f
|
| 33 |
+
-
|
| 34 |
+
- return update_wrapper(f, new_func) # Swap the arguments in the update_wrapper call
|
| 35 |
+
+ obj = ctx.meta[key]
|
| 36 |
+
+ return ctx.invoke(f, obj, *args, **kwargs)
|
| 37 |
+
+
|
| 38 |
+
+ return update_wrapper(new_func, f)
|
| 39 |
+
|
| 40 |
+
if doc_description is None:
|
| 41 |
+
doc_description = f"the {key!r} key from :attr:`click.Context.meta`"
|
| 42 |
+
@@ -216,7 +216,7 @@
|
| 43 |
+
cls = t.cast("type[CmdType]", Command)
|
| 44 |
+
|
| 45 |
+
def decorator(f: _AnyCallable) -> CmdType:
|
| 46 |
+
- if not isinstance(f, Command):
|
| 47 |
+
+ if isinstance(f, Command):
|
| 48 |
+
raise TypeError("Attempted to convert a callback into a command twice.")
|
| 49 |
+
|
| 50 |
+
attr_params = attrs.pop("params", None)
|
| 51 |
+
@@ -225,29 +225,29 @@
|
| 52 |
+
try:
|
| 53 |
+
decorator_params = f.__click_params__ # type: ignore
|
| 54 |
+
except AttributeError:
|
| 55 |
+
- params.append("default_param")
|
| 56 |
+
+ pass
|
| 57 |
+
else:
|
| 58 |
+
del f.__click_params__ # type: ignore
|
| 59 |
+
params.extend(reversed(decorator_params))
|
| 60 |
+
|
| 61 |
+
if attrs.get("help") is None:
|
| 62 |
+
- attrs["help"] = "No documentation available."
|
| 63 |
+
+ attrs["help"] = f.__doc__
|
| 64 |
+
|
| 65 |
+
if t.TYPE_CHECKING:
|
| 66 |
+
assert cls is not None
|
| 67 |
+
- assert callable(name)
|
| 68 |
+
-
|
| 69 |
+
- if name is None:
|
| 70 |
+
+ assert not callable(name)
|
| 71 |
+
+
|
| 72 |
+
+ if name is not None:
|
| 73 |
+
+ cmd_name = name
|
| 74 |
+
+ else:
|
| 75 |
+
cmd_name = f.__name__.lower().replace("_", "-")
|
| 76 |
+
cmd_left, sep, suffix = cmd_name.rpartition("-")
|
| 77 |
+
|
| 78 |
+
if sep and suffix in {"command", "cmd", "group", "grp"}:
|
| 79 |
+
cmd_name = cmd_left
|
| 80 |
+
- else:
|
| 81 |
+
- cmd_name = name
|
| 82 |
+
|
| 83 |
+
cmd = cls(name=cmd_name, callback=f, params=params, **attrs)
|
| 84 |
+
- cmd.__doc__ = f.__doc__ if f.__doc__ else "No documentation provided."
|
| 85 |
+
+ cmd.__doc__ = f.__doc__
|
| 86 |
+
return cmd
|
| 87 |
+
|
| 88 |
+
if func is not None:
|
| 89 |
+
@@ -372,8 +372,8 @@
|
| 90 |
+
cls = Option
|
| 91 |
+
|
| 92 |
+
def decorator(f: FC) -> FC:
|
| 93 |
+
- _param_memo(f, cls(param_decls[::-1], **attrs))
|
| 94 |
+
- return None
|
| 95 |
+
+ _param_memo(f, cls(param_decls, **attrs))
|
| 96 |
+
+ return f
|
| 97 |
+
|
| 98 |
+
return decorator
|
| 99 |
+
|
| 100 |
+
OPENENV_REFERENCE
|
| 101 |
+
/usr/bin/git -c core.hooksPath=/dev/null -c core.fsmonitor=false apply --whitespace=nowarn /tmp/openenv-reference.diff
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/task.toml
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version = "1.0"
|
| 2 |
+
|
| 3 |
+
[agent]
|
| 4 |
+
timeout_sec = 1800.0
|
| 5 |
+
|
| 6 |
+
[verifier]
|
| 7 |
+
timeout_sec = 900.0
|
| 8 |
+
|
| 9 |
+
[environment]
|
| 10 |
+
build_timeout_sec = 600.0
|
| 11 |
+
cpus = 2
|
| 12 |
+
memory_mb = 8192
|
| 13 |
+
storage_mb = 16384
|
| 14 |
+
|
| 15 |
+
[metadata]
|
| 16 |
+
author_name = "SWE-smith source adapter"
|
| 17 |
+
category = "bugfix"
|
| 18 |
+
tags = ["swe", "python", "mutation-repair"]
|
| 19 |
+
|
| 20 |
+
[environment.env]
|
| 21 |
+
# The image's PATH with the testbed env first: the project and pytest are installed there, and the agent's
|
| 22 |
+
# non-interactive shells never run `conda activate`
|
| 23 |
+
PATH = "/opt/miniconda3/envs/testbed/bin:/opt/miniconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/check_pytest.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Distinguish real pytest failures from missing/setup/verifier evidence."""
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import json
|
| 5 |
+
import re
|
| 6 |
+
import xml.etree.ElementTree as ET
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def matches(case, target):
|
| 11 |
+
parts = target.split("::")
|
| 12 |
+
module = parts[0].removesuffix(".py").replace("/", ".")
|
| 13 |
+
classname = case.get("classname", "")
|
| 14 |
+
name = case.get("name", "")
|
| 15 |
+
if not (classname == module or classname.startswith(module + ".")):
|
| 16 |
+
return False
|
| 17 |
+
selector = parts[-1] if len(parts) > 1 else ""
|
| 18 |
+
classes = parts[1:-1]
|
| 19 |
+
if classes and classname != module + "." + ".".join(classes):
|
| 20 |
+
return False
|
| 21 |
+
return (
|
| 22 |
+
not selector
|
| 23 |
+
or name == selector
|
| 24 |
+
or ("[" not in selector and name.startswith(selector + "["))
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def assess(root, expected, native_exit):
|
| 29 |
+
all_cases = []
|
| 30 |
+
actual_failure = False
|
| 31 |
+
for group in ("pass-to-pass", "fail-to-pass"):
|
| 32 |
+
path = Path(root) / (group + ".xml")
|
| 33 |
+
if not path.exists():
|
| 34 |
+
if actual_failure:
|
| 35 |
+
continue
|
| 36 |
+
raise ValueError("Missing preceding pytest panel")
|
| 37 |
+
if actual_failure:
|
| 38 |
+
raise ValueError(
|
| 39 |
+
"Pytest evidence continued after the native stop-on-failure"
|
| 40 |
+
)
|
| 41 |
+
raw = path.read_bytes()
|
| 42 |
+
if not 0 < len(raw) <= 4 * 1024**2 or re.search(
|
| 43 |
+
rb"<!\s*(?:DOCTYPE|ENTITY)", raw, re.I
|
| 44 |
+
):
|
| 45 |
+
raise ValueError("Unbounded or unsafe pytest XML")
|
| 46 |
+
tree = ET.fromstring(raw)
|
| 47 |
+
cases = list(tree.iter("testcase"))
|
| 48 |
+
if len(cases) > 20000:
|
| 49 |
+
raise ValueError("Too many pytest cases")
|
| 50 |
+
identities = [(c.get("classname"), c.get("name")) for c in cases]
|
| 51 |
+
if len(identities) != len(set(identities)):
|
| 52 |
+
raise ValueError("Duplicate pytest case evidence")
|
| 53 |
+
targets = expected[group]
|
| 54 |
+
if any(not any(matches(case, t) for t in targets) for case in cases):
|
| 55 |
+
raise ValueError("Unexpected pytest case")
|
| 56 |
+
all_cases.extend(cases)
|
| 57 |
+
failures = [c for c in cases if c.find("failure") is not None]
|
| 58 |
+
if any(
|
| 59 |
+
c.find("error") is not None or c.find("skipped") is not None for c in cases
|
| 60 |
+
):
|
| 61 |
+
raise ValueError("Pytest collection/error/skip is not a completed panel")
|
| 62 |
+
actual_failure = actual_failure or bool(failures)
|
| 63 |
+
if not failures and any(
|
| 64 |
+
not any(matches(case, t) for case in cases) for t in targets
|
| 65 |
+
):
|
| 66 |
+
raise ValueError("Declared pytest target never ran")
|
| 67 |
+
if actual_failure:
|
| 68 |
+
if native_exit == 0:
|
| 69 |
+
raise ValueError("Native verifier exit disagrees with pytest failure")
|
| 70 |
+
return {"reward": 0, "valid_test_failure": True, "cases": len(all_cases)}
|
| 71 |
+
if native_exit != 0:
|
| 72 |
+
raise ValueError("Setup or native verifier failed without a real test failure")
|
| 73 |
+
for group in ("pass-to-pass", "fail-to-pass"):
|
| 74 |
+
if not (Path(root) / (group + ".xml")).is_file():
|
| 75 |
+
raise ValueError("Missing completed pytest panel")
|
| 76 |
+
return {"reward": 1, "valid_test_failure": False, "cases": len(all_cases)}
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
if __name__ == "__main__":
|
| 80 |
+
p = argparse.ArgumentParser()
|
| 81 |
+
p.add_argument("--root", required=True)
|
| 82 |
+
p.add_argument("--expected", required=True)
|
| 83 |
+
p.add_argument("--native-exit", type=int, required=True)
|
| 84 |
+
a = p.parse_args()
|
| 85 |
+
result = assess(a.root, json.loads(Path(a.expected).read_text()), a.native_exit)
|
| 86 |
+
reward = Path(a.root) / "reward.txt"
|
| 87 |
+
if reward.read_text().strip() != str(result["reward"]):
|
| 88 |
+
raise ValueError("Native raw reward disagrees with pytest evidence")
|
| 89 |
+
(Path(a.root) / "pytest-evidence.json").write_text(
|
| 90 |
+
json.dumps(result, sort_keys=True) + "\n"
|
| 91 |
+
)
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/expected-panels.json
ADDED
|
@@ -0,0 +1,485 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"fail-to-pass": [
|
| 3 |
+
"tests/test_arguments.py::test_nargs_star",
|
| 4 |
+
"tests/test_arguments.py::test_nargs_tup",
|
| 5 |
+
"tests/test_arguments.py::test_nargs_tup_composite[opts0]",
|
| 6 |
+
"tests/test_arguments.py::test_nargs_tup_composite[opts1]",
|
| 7 |
+
"tests/test_arguments.py::test_nargs_tup_composite[opts2]",
|
| 8 |
+
"tests/test_arguments.py::test_nargs_tup_composite[opts3]",
|
| 9 |
+
"tests/test_arguments.py::test_nargs_err",
|
| 10 |
+
"tests/test_arguments.py::test_bytes_args",
|
| 11 |
+
"tests/test_arguments.py::test_file_args",
|
| 12 |
+
"tests/test_arguments.py::test_path_allow_dash",
|
| 13 |
+
"tests/test_arguments.py::test_file_atomics",
|
| 14 |
+
"tests/test_arguments.py::test_stdout_default",
|
| 15 |
+
"tests/test_arguments.py::test_nargs_envvar[2--None]",
|
| 16 |
+
"tests/test_arguments.py::test_nargs_envvar[-1--expect5]",
|
| 17 |
+
"tests/test_arguments.py::test_envvar_flag_value",
|
| 18 |
+
"tests/test_arguments.py::test_nargs_envvar_only_if_values_empty",
|
| 19 |
+
"tests/test_arguments.py::test_empty_nargs",
|
| 20 |
+
"tests/test_arguments.py::test_missing_arg",
|
| 21 |
+
"tests/test_arguments.py::test_implicit_non_required",
|
| 22 |
+
"tests/test_arguments.py::test_eat_options",
|
| 23 |
+
"tests/test_arguments.py::test_nargs_star_ordering",
|
| 24 |
+
"tests/test_arguments.py::test_nargs_specified_plus_star_ordering",
|
| 25 |
+
"tests/test_arguments.py::test_defaults_for_nargs",
|
| 26 |
+
"tests/test_arguments.py::test_subcommand_help",
|
| 27 |
+
"tests/test_arguments.py::test_nested_subcommand_help",
|
| 28 |
+
"tests/test_arguments.py::test_when_argument_decorator_is_used_multiple_times_cls_is_preserved",
|
| 29 |
+
"tests/test_arguments.py::test_duplicate_names_warning[args_one0-args_two0]",
|
| 30 |
+
"tests/test_basic.py::test_basic_functionality",
|
| 31 |
+
"tests/test_basic.py::test_repr",
|
| 32 |
+
"tests/test_basic.py::test_return_values",
|
| 33 |
+
"tests/test_basic.py::test_basic_group",
|
| 34 |
+
"tests/test_basic.py::test_group_commands_dict",
|
| 35 |
+
"tests/test_basic.py::test_group_from_list",
|
| 36 |
+
"tests/test_basic.py::test_string_option[args1-S:[42]]",
|
| 37 |
+
"tests/test_basic.py::test_string_option[args3-S:[]]",
|
| 38 |
+
"tests/test_basic.py::test_string_option[args4-S:[\\u2603]]",
|
| 39 |
+
"tests/test_basic.py::test_int_option[args0-I:[84]]",
|
| 40 |
+
"tests/test_basic.py::test_int_option[args1-I:[46]]",
|
| 41 |
+
"tests/test_basic.py::test_uuid_option[args0-U:[ba122011-349f-423b-873b-9d6a79c688ab]]",
|
| 42 |
+
"tests/test_basic.py::test_uuid_option[args1-U:[821592c1-c50e-4971-9cd6-e89dc6832f86]]",
|
| 43 |
+
"tests/test_basic.py::test_float_option[args0-F:[42.0]]",
|
| 44 |
+
"tests/test_basic.py::test_float_option[--f=23.5-F:[23.5]]",
|
| 45 |
+
"tests/test_basic.py::test_boolean_switch[args0-True-True]",
|
| 46 |
+
"tests/test_basic.py::test_boolean_switch[args0-True-False]",
|
| 47 |
+
"tests/test_basic.py::test_boolean_switch[args1-False-True]",
|
| 48 |
+
"tests/test_basic.py::test_boolean_switch[args1-False-False]",
|
| 49 |
+
"tests/test_basic.py::test_boolean_switch[args2-None-True]",
|
| 50 |
+
"tests/test_basic.py::test_boolean_switch[args2-None-False]",
|
| 51 |
+
"tests/test_basic.py::test_boolean_flag[args0-True-True]",
|
| 52 |
+
"tests/test_basic.py::test_boolean_flag[args0-True-False]",
|
| 53 |
+
"tests/test_basic.py::test_boolean_flag[args1-False-True]",
|
| 54 |
+
"tests/test_basic.py::test_boolean_flag[args1-False-False]",
|
| 55 |
+
"tests/test_basic.py::test_boolean_conversion[1-True]",
|
| 56 |
+
"tests/test_basic.py::test_boolean_conversion[true-True]",
|
| 57 |
+
"tests/test_basic.py::test_boolean_conversion[t-True]",
|
| 58 |
+
"tests/test_basic.py::test_boolean_conversion[yes-True]",
|
| 59 |
+
"tests/test_basic.py::test_boolean_conversion[y-True]",
|
| 60 |
+
"tests/test_basic.py::test_boolean_conversion[on-True]",
|
| 61 |
+
"tests/test_basic.py::test_boolean_conversion[0-False]",
|
| 62 |
+
"tests/test_basic.py::test_boolean_conversion[false-False]",
|
| 63 |
+
"tests/test_basic.py::test_boolean_conversion[f-False]",
|
| 64 |
+
"tests/test_basic.py::test_boolean_conversion[no-False]",
|
| 65 |
+
"tests/test_basic.py::test_boolean_conversion[n-False]",
|
| 66 |
+
"tests/test_basic.py::test_boolean_conversion[off-False]",
|
| 67 |
+
"tests/test_basic.py::test_file_option",
|
| 68 |
+
"tests/test_basic.py::test_file_lazy_mode",
|
| 69 |
+
"tests/test_basic.py::test_path_option",
|
| 70 |
+
"tests/test_basic.py::test_choice_option",
|
| 71 |
+
"tests/test_basic.py::test_choice_argument",
|
| 72 |
+
"tests/test_basic.py::test_datetime_option_default",
|
| 73 |
+
"tests/test_basic.py::test_datetime_option_custom",
|
| 74 |
+
"tests/test_basic.py::test_required_option",
|
| 75 |
+
"tests/test_basic.py::test_evaluation_order",
|
| 76 |
+
"tests/test_basic.py::test_hidden_option",
|
| 77 |
+
"tests/test_basic.py::test_hidden_command",
|
| 78 |
+
"tests/test_basic.py::test_hidden_group",
|
| 79 |
+
"tests/test_basic.py::test_summary_line",
|
| 80 |
+
"tests/test_chain.py::test_basic_chaining",
|
| 81 |
+
"tests/test_chain.py::test_chaining_with_options",
|
| 82 |
+
"tests/test_chain.py::test_no_command_result_callback[False-1]",
|
| 83 |
+
"tests/test_chain.py::test_no_command_result_callback[True-[]]",
|
| 84 |
+
"tests/test_chain.py::test_chaining_with_arguments",
|
| 85 |
+
"tests/test_chain.py::test_pipeline[args0-foo\\nbar-expect0]",
|
| 86 |
+
"tests/test_chain.py::test_args_and_chain",
|
| 87 |
+
"tests/test_chain.py::test_group_arg_behavior",
|
| 88 |
+
"tests/test_command_decorators.py::test_command_no_parens",
|
| 89 |
+
"tests/test_command_decorators.py::test_custom_command_no_parens",
|
| 90 |
+
"tests/test_command_decorators.py::test_group_no_parens",
|
| 91 |
+
"tests/test_command_decorators.py::test_params_argument",
|
| 92 |
+
"tests/test_command_decorators.py::test_generate_name[init_data]",
|
| 93 |
+
"tests/test_command_decorators.py::test_generate_name[init_data_command]",
|
| 94 |
+
"tests/test_command_decorators.py::test_generate_name[init_data_cmd]",
|
| 95 |
+
"tests/test_command_decorators.py::test_generate_name[init_data_group]",
|
| 96 |
+
"tests/test_command_decorators.py::test_generate_name[init_data_grp]",
|
| 97 |
+
"tests/test_commands.py::test_other_command_invoke",
|
| 98 |
+
"tests/test_commands.py::test_other_command_forward",
|
| 99 |
+
"tests/test_commands.py::test_forwarded_params_consistency",
|
| 100 |
+
"tests/test_commands.py::test_auto_shorthelp",
|
| 101 |
+
"tests/test_commands.py::test_default_maps",
|
| 102 |
+
"tests/test_commands.py::test_group_with_args[args2-0-obj=obj1\\nmove\\n]",
|
| 103 |
+
"tests/test_commands.py::test_custom_parser",
|
| 104 |
+
"tests/test_commands.py::test_object_propagation",
|
| 105 |
+
"tests/test_commands.py::test_other_command_invoke_with_defaults",
|
| 106 |
+
"tests/test_commands.py::test_invoked_subcommand",
|
| 107 |
+
"tests/test_commands.py::test_aliased_command_canonical_name",
|
| 108 |
+
"tests/test_commands.py::test_unprocessed_options",
|
| 109 |
+
"tests/test_commands.py::test_deprecated_in_help_messages[None]",
|
| 110 |
+
"tests/test_commands.py::test_deprecated_in_invocation",
|
| 111 |
+
"tests/test_commands.py::test_command_parse_args_collects_option_prefixes",
|
| 112 |
+
"tests/test_commands.py::test_group_parse_args_collects_base_option_prefixes",
|
| 113 |
+
"tests/test_commands.py::test_group_invoke_collects_used_option_prefixes",
|
| 114 |
+
"tests/test_commands.py::test_abort_exceptions_with_disabled_standalone_mode[EOFError]",
|
| 115 |
+
"tests/test_commands.py::test_abort_exceptions_with_disabled_standalone_mode[KeyboardInterrupt]",
|
| 116 |
+
"tests/test_context.py::test_ensure_context_objects",
|
| 117 |
+
"tests/test_context.py::test_get_context_objects",
|
| 118 |
+
"tests/test_context.py::test_get_context_objects_no_ensuring",
|
| 119 |
+
"tests/test_context.py::test_get_context_objects_missing",
|
| 120 |
+
"tests/test_context.py::test_multi_enter",
|
| 121 |
+
"tests/test_context.py::test_global_context_object",
|
| 122 |
+
"tests/test_context.py::test_context_meta",
|
| 123 |
+
"tests/test_context.py::test_make_pass_meta_decorator",
|
| 124 |
+
"tests/test_context.py::test_context_pushing",
|
| 125 |
+
"tests/test_context.py::test_pass_obj",
|
| 126 |
+
"tests/test_context.py::test_close_before_pop",
|
| 127 |
+
"tests/test_context.py::test_close_before_exit",
|
| 128 |
+
"tests/test_context.py::test_multiple_eager_callbacks[natural_order]",
|
| 129 |
+
"tests/test_context.py::test_multiple_eager_callbacks[eagerness_precedence]",
|
| 130 |
+
"tests/test_context.py::test_no_state_leaks",
|
| 131 |
+
"tests/test_context.py::test_make_pass_decorator_args",
|
| 132 |
+
"tests/test_context.py::test_exit_not_standalone",
|
| 133 |
+
"tests/test_context.py::test_parameter_source[default]",
|
| 134 |
+
"tests/test_context.py::test_parameter_source[default_map]",
|
| 135 |
+
"tests/test_custom_classes.py::test_context_invoke_type",
|
| 136 |
+
"tests/test_custom_classes.py::test_group_command_class",
|
| 137 |
+
"tests/test_custom_classes.py::test_group_group_class",
|
| 138 |
+
"tests/test_custom_classes.py::test_group_group_class_self",
|
| 139 |
+
"tests/test_defaults.py::test_basic_defaults",
|
| 140 |
+
"tests/test_defaults.py::test_multiple_defaults",
|
| 141 |
+
"tests/test_defaults.py::test_nargs_plus_multiple",
|
| 142 |
+
"tests/test_defaults.py::test_multiple_flag_default",
|
| 143 |
+
"tests/test_defaults.py::test_flag_default_map",
|
| 144 |
+
"tests/test_formatting.py::test_basic_functionality",
|
| 145 |
+
"tests/test_formatting.py::test_wrapping_long_options_strings",
|
| 146 |
+
"tests/test_formatting.py::test_wrapping_long_command_name",
|
| 147 |
+
"tests/test_formatting.py::test_formatting_empty_help_lines",
|
| 148 |
+
"tests/test_formatting.py::test_formatting_usage_error",
|
| 149 |
+
"tests/test_formatting.py::test_formatting_usage_error_metavar_missing_arg",
|
| 150 |
+
"tests/test_formatting.py::test_formatting_usage_error_metavar_bad_arg",
|
| 151 |
+
"tests/test_formatting.py::test_formatting_usage_error_nested",
|
| 152 |
+
"tests/test_formatting.py::test_formatting_usage_error_no_help",
|
| 153 |
+
"tests/test_formatting.py::test_formatting_usage_custom_help",
|
| 154 |
+
"tests/test_formatting.py::test_formatting_custom_type_metavar",
|
| 155 |
+
"tests/test_formatting.py::test_truncating_docstring",
|
| 156 |
+
"tests/test_formatting.py::test_truncating_docstring_no_help",
|
| 157 |
+
"tests/test_formatting.py::test_removing_multiline_marker",
|
| 158 |
+
"tests/test_formatting.py::test_global_show_default",
|
| 159 |
+
"tests/test_normalization.py::test_option_normalization",
|
| 160 |
+
"tests/test_normalization.py::test_choice_normalization",
|
| 161 |
+
"tests/test_normalization.py::test_command_normalization",
|
| 162 |
+
"tests/test_options.py::test_prefixes",
|
| 163 |
+
"tests/test_options.py::test_nargs_tup_composite_mult",
|
| 164 |
+
"tests/test_options.py::test_counting",
|
| 165 |
+
"tests/test_options.py::test_unknown_options[--foo]",
|
| 166 |
+
"tests/test_options.py::test_unknown_options[-f]",
|
| 167 |
+
"tests/test_options.py::test_multiple_required",
|
| 168 |
+
"tests/test_options.py::test_empty_envvar[MYPATH]",
|
| 169 |
+
"tests/test_options.py::test_empty_envvar[AUTO_MYPATH]",
|
| 170 |
+
"tests/test_options.py::test_multiple_envvar",
|
| 171 |
+
"tests/test_options.py::test_trailing_blanks_boolean_envvar",
|
| 172 |
+
"tests/test_options.py::test_multiple_default_help",
|
| 173 |
+
"tests/test_options.py::test_show_default_default_map",
|
| 174 |
+
"tests/test_options.py::test_parse_multiple_default_composite_type",
|
| 175 |
+
"tests/test_options.py::test_dynamic_default_help_unset",
|
| 176 |
+
"tests/test_options.py::test_dynamic_default_help_text",
|
| 177 |
+
"tests/test_options.py::test_toupper_envvar_prefix",
|
| 178 |
+
"tests/test_options.py::test_nargs_envvar",
|
| 179 |
+
"tests/test_options.py::test_show_envvar",
|
| 180 |
+
"tests/test_options.py::test_show_envvar_auto_prefix",
|
| 181 |
+
"tests/test_options.py::test_show_envvar_auto_prefix_dash_in_command",
|
| 182 |
+
"tests/test_options.py::test_custom_validation",
|
| 183 |
+
"tests/test_options.py::test_callback_validates_prompt",
|
| 184 |
+
"tests/test_options.py::test_winstyle_options",
|
| 185 |
+
"tests/test_options.py::test_legacy_options",
|
| 186 |
+
"tests/test_options.py::test_missing_choice",
|
| 187 |
+
"tests/test_options.py::test_case_insensitive_choice",
|
| 188 |
+
"tests/test_options.py::test_case_insensitive_choice_returned_exactly",
|
| 189 |
+
"tests/test_options.py::test_option_help_preserve_paragraphs",
|
| 190 |
+
"tests/test_options.py::test_argument_custom_class",
|
| 191 |
+
"tests/test_options.py::test_option_custom_class",
|
| 192 |
+
"tests/test_options.py::test_option_custom_class_reusable",
|
| 193 |
+
"tests/test_options.py::test_bool_flag_with_type",
|
| 194 |
+
"tests/test_options.py::test_aliases_for_flags",
|
| 195 |
+
"tests/test_options.py::test_option_names[option_args0-aggressive]",
|
| 196 |
+
"tests/test_options.py::test_option_names[option_args1-first]",
|
| 197 |
+
"tests/test_options.py::test_option_names[option_args2-apple]",
|
| 198 |
+
"tests/test_options.py::test_option_names[option_args3-cantaloupe]",
|
| 199 |
+
"tests/test_options.py::test_option_names[option_args4-a]",
|
| 200 |
+
"tests/test_options.py::test_option_names[option_args5-c]",
|
| 201 |
+
"tests/test_options.py::test_option_names[option_args6-apple]",
|
| 202 |
+
"tests/test_options.py::test_option_names[option_args7-cantaloupe]",
|
| 203 |
+
"tests/test_options.py::test_option_names[option_args8-_from]",
|
| 204 |
+
"tests/test_options.py::test_option_names[option_args9-_ret]",
|
| 205 |
+
"tests/test_options.py::test_option_with_optional_value[None-expect0]",
|
| 206 |
+
"tests/test_options.py::test_option_with_optional_value[args1-expect1]",
|
| 207 |
+
"tests/test_options.py::test_option_with_optional_value[args2-expect2]",
|
| 208 |
+
"tests/test_options.py::test_option_with_optional_value[args3-expect3]",
|
| 209 |
+
"tests/test_options.py::test_option_with_optional_value[args4-expect4]",
|
| 210 |
+
"tests/test_options.py::test_option_with_optional_value[args5-expect5]",
|
| 211 |
+
"tests/test_options.py::test_option_with_optional_value[args6-expect6]",
|
| 212 |
+
"tests/test_options.py::test_option_with_optional_value[args7-expect7]",
|
| 213 |
+
"tests/test_options.py::test_option_with_optional_value[args8-expect8]",
|
| 214 |
+
"tests/test_options.py::test_option_with_optional_value[args9-expect9]",
|
| 215 |
+
"tests/test_options.py::test_option_with_optional_value[args10-expect10]",
|
| 216 |
+
"tests/test_options.py::test_option_with_optional_value[args11-expect11]",
|
| 217 |
+
"tests/test_options.py::test_option_with_optional_value[args12-expect12]",
|
| 218 |
+
"tests/test_options.py::test_option_with_optional_value[args13-expect13]",
|
| 219 |
+
"tests/test_options.py::test_duplicate_names_warning[opts_one0-opts_two0]",
|
| 220 |
+
"tests/test_options.py::test_duplicate_names_warning[opts_one1-opts_two1]",
|
| 221 |
+
"tests/test_shell_completion.py::test_files_closed",
|
| 222 |
+
"tests/test_termui.py::test_progressbar_strip_regression",
|
| 223 |
+
"tests/test_termui.py::test_progressbar_length_hint",
|
| 224 |
+
"tests/test_termui.py::test_progressbar_no_tty",
|
| 225 |
+
"tests/test_termui.py::test_progressbar_hidden_manual",
|
| 226 |
+
"tests/test_termui.py::test_progressbar_is_iterator",
|
| 227 |
+
"tests/test_termui.py::test_choices_list_in_prompt",
|
| 228 |
+
"tests/test_termui.py::test_file_prompt_default_format[file_kwargs0]",
|
| 229 |
+
"tests/test_termui.py::test_file_prompt_default_format[file_kwargs1]",
|
| 230 |
+
"tests/test_termui.py::test_file_prompt_default_format[file_kwargs2]",
|
| 231 |
+
"tests/test_termui.py::test_progressbar_update",
|
| 232 |
+
"tests/test_termui.py::test_progressbar_item_show_func",
|
| 233 |
+
"tests/test_termui.py::test_progressbar_update_with_item_show_func",
|
| 234 |
+
"tests/test_termui.py::test_prompt_required_with_required[True-False-None-prompt]",
|
| 235 |
+
"tests/test_termui.py::test_prompt_required_with_required[False-True-None-prompt]",
|
| 236 |
+
"tests/test_termui.py::test_prompt_required_with_required[False-True-args3-prompt]",
|
| 237 |
+
"tests/test_termui.py::test_confirmation_prompt[True-password\\npassword-None-password]",
|
| 238 |
+
"tests/test_termui.py::test_confirmation_prompt[True---]",
|
| 239 |
+
"tests/test_termui.py::test_confirmation_prompt[False-None-None-None]",
|
| 240 |
+
"tests/test_termui.py::test_false_show_default_cause_no_default_display_in_prompt",
|
| 241 |
+
"tests/test_testing.py::test_runner",
|
| 242 |
+
"tests/test_testing.py::test_echo_stdin_stream",
|
| 243 |
+
"tests/test_testing.py::test_echo_stdin_prompts",
|
| 244 |
+
"tests/test_testing.py::test_runner_with_stream",
|
| 245 |
+
"tests/test_testing.py::test_prompts",
|
| 246 |
+
"tests/test_testing.py::test_getchar",
|
| 247 |
+
"tests/test_testing.py::test_catch_exceptions",
|
| 248 |
+
"tests/test_testing.py::test_with_color",
|
| 249 |
+
"tests/test_testing.py::test_with_color_errors",
|
| 250 |
+
"tests/test_testing.py::test_with_color_but_pause_not_blocking",
|
| 251 |
+
"tests/test_testing.py::test_exit_code_and_output_from_sys_exit",
|
| 252 |
+
"tests/test_testing.py::test_env",
|
| 253 |
+
"tests/test_testing.py::test_stderr",
|
| 254 |
+
"tests/test_testing.py::test_args[None-bar\\n]",
|
| 255 |
+
"tests/test_testing.py::test_args[args1-bar\\n]",
|
| 256 |
+
"tests/test_testing.py::test_args[-bar\\n]",
|
| 257 |
+
"tests/test_testing.py::test_setting_prog_name_in_extra",
|
| 258 |
+
"tests/test_testing.py::test_command_standalone_mode_returns_value",
|
| 259 |
+
"tests/test_testing.py::test_file_stdin_attrs",
|
| 260 |
+
"tests/test_utils.py::test_echo",
|
| 261 |
+
"tests/test_utils.py::test_prompts",
|
| 262 |
+
"tests/test_utils.py::test_open_file",
|
| 263 |
+
"tests/test_utils.py::test_open_file_pathlib_dash",
|
| 264 |
+
"tests/test_utils.py::test_open_file_ignore_errors_stdin",
|
| 265 |
+
"tests/test_utils.py::test_open_file_atomic_permissions_existing_file[256]",
|
| 266 |
+
"tests/test_utils.py::test_open_file_atomic_permissions_existing_file[292]",
|
| 267 |
+
"tests/test_utils.py::test_open_file_atomic_permissions_existing_file[384]",
|
| 268 |
+
"tests/test_utils.py::test_open_file_atomic_permissions_existing_file[420]",
|
| 269 |
+
"tests/test_utils.py::test_open_file_atomic_permissions_new_file"
|
| 270 |
+
],
|
| 271 |
+
"pass-to-pass": [
|
| 272 |
+
"tests/test_arguments.py::test_argument_unbounded_nargs_cant_have_default",
|
| 273 |
+
"tests/test_arguments.py::test_missing_argument_string_cast",
|
| 274 |
+
"tests/test_arguments.py::test_multiple_param_decls_not_allowed",
|
| 275 |
+
"tests/test_arguments.py::test_multiple_not_allowed",
|
| 276 |
+
"tests/test_arguments.py::test_nargs_bad_default[value0]",
|
| 277 |
+
"tests/test_arguments.py::test_nargs_bad_default[value1]",
|
| 278 |
+
"tests/test_arguments.py::test_nargs_bad_default[value2]",
|
| 279 |
+
"tests/test_basic.py::test_help_invalid_default",
|
| 280 |
+
"tests/test_commands.py::test_command_no_args_is_help",
|
| 281 |
+
"tests/test_commands.py::test_group_add_command_name",
|
| 282 |
+
"tests/test_compat.py::test_is_jupyter_kernel_output",
|
| 283 |
+
"tests/test_context.py::test_make_pass_meta_decorator_doc",
|
| 284 |
+
"tests/test_context.py::test_with_resource",
|
| 285 |
+
"tests/test_context.py::test_propagate_show_default_setting",
|
| 286 |
+
"tests/test_context.py::test_propagate_opt_prefixes",
|
| 287 |
+
"tests/test_custom_classes.py::test_command_context_class",
|
| 288 |
+
"tests/test_custom_classes.py::test_context_formatter_class",
|
| 289 |
+
"tests/test_formatting.py::test_formatting_with_options_metavar_empty",
|
| 290 |
+
"tests/test_formatting.py::test_help_formatter_write_text",
|
| 291 |
+
"tests/test_imports.py::test_light_imports",
|
| 292 |
+
"tests/test_info_dict.py::test_parameter[Option]",
|
| 293 |
+
"tests/test_info_dict.py::test_parameter[Argument]",
|
| 294 |
+
"tests/test_info_dict.py::test_command[Command]",
|
| 295 |
+
"tests/test_info_dict.py::test_command[Group]",
|
| 296 |
+
"tests/test_info_dict.py::test_context",
|
| 297 |
+
"tests/test_info_dict.py::test_paramtype_no_name",
|
| 298 |
+
"tests/test_options.py::test_invalid_option",
|
| 299 |
+
"tests/test_options.py::test_invalid_nargs",
|
| 300 |
+
"tests/test_options.py::test_init_good_default_list[True-1-default0]",
|
| 301 |
+
"tests/test_options.py::test_init_good_default_list[True-1-default1]",
|
| 302 |
+
"tests/test_options.py::test_init_good_default_list[False-2-default2]",
|
| 303 |
+
"tests/test_options.py::test_init_good_default_list[True-2-default3]",
|
| 304 |
+
"tests/test_options.py::test_init_good_default_list[True-2-default4]",
|
| 305 |
+
"tests/test_options.py::test_init_bad_default_list[True-1-1]",
|
| 306 |
+
"tests/test_options.py::test_init_bad_default_list[False-2-default1]",
|
| 307 |
+
"tests/test_options.py::test_init_bad_default_list[True-2-default2]",
|
| 308 |
+
"tests/test_options.py::test_multiple_default_type",
|
| 309 |
+
"tests/test_options.py::test_multiple_default_composite_type",
|
| 310 |
+
"tests/test_options.py::test_dynamic_default_help_special_method",
|
| 311 |
+
"tests/test_options.py::test_intrange_default_help_text[type0-1<=x<=32]",
|
| 312 |
+
"tests/test_options.py::test_intrange_default_help_text[type1-1<x<32]",
|
| 313 |
+
"tests/test_options.py::test_intrange_default_help_text[type2-x>=1]",
|
| 314 |
+
"tests/test_options.py::test_intrange_default_help_text[type3-x<=32]",
|
| 315 |
+
"tests/test_options.py::test_count_default_type_help",
|
| 316 |
+
"tests/test_options.py::test_file_type_help_default",
|
| 317 |
+
"tests/test_options.py::test_missing_option_string_cast",
|
| 318 |
+
"tests/test_options.py::test_missing_required_flag",
|
| 319 |
+
"tests/test_options.py::test_missing_envvar",
|
| 320 |
+
"tests/test_options.py::test_flag_duplicate_names",
|
| 321 |
+
"tests/test_options.py::test_show_default_boolean_flag_name[False-no-cache]",
|
| 322 |
+
"tests/test_options.py::test_show_default_boolean_flag_name[True-cache]",
|
| 323 |
+
"tests/test_options.py::test_show_true_default_boolean_flag_value",
|
| 324 |
+
"tests/test_options.py::test_hide_false_default_boolean_flag_value[False]",
|
| 325 |
+
"tests/test_options.py::test_hide_false_default_boolean_flag_value[None]",
|
| 326 |
+
"tests/test_options.py::test_show_default_string",
|
| 327 |
+
"tests/test_options.py::test_show_default_with_empty_string",
|
| 328 |
+
"tests/test_options.py::test_do_not_show_no_default",
|
| 329 |
+
"tests/test_options.py::test_do_not_show_default_empty_multiple",
|
| 330 |
+
"tests/test_options.py::test_show_default_precedence[None-None-extra_value0-False]",
|
| 331 |
+
"tests/test_options.py::test_show_default_precedence[None-False-extra_value1-False]",
|
| 332 |
+
"tests/test_options.py::test_show_default_precedence[None-True-extra_value2-True]",
|
| 333 |
+
"tests/test_options.py::test_show_default_precedence[False-None-extra_value3-False]",
|
| 334 |
+
"tests/test_options.py::test_show_default_precedence[False-False-extra_value4-False]",
|
| 335 |
+
"tests/test_options.py::test_show_default_precedence[False-True-extra_value5-True]",
|
| 336 |
+
"tests/test_options.py::test_show_default_precedence[True-None-extra_value6-True]",
|
| 337 |
+
"tests/test_options.py::test_show_default_precedence[True-False-extra_value7-False]",
|
| 338 |
+
"tests/test_options.py::test_show_default_precedence[True-True-extra_value8-True]",
|
| 339 |
+
"tests/test_options.py::test_show_default_precedence[False-one-extra_value9-True]",
|
| 340 |
+
"tests/test_options.py::test_multiple_option_with_optional_value",
|
| 341 |
+
"tests/test_options.py::test_type_from_flag_value",
|
| 342 |
+
"tests/test_options.py::test_is_bool_flag_is_correctly_set[is_flag=True]",
|
| 343 |
+
"tests/test_parser.py::test_parser_default_prefixes",
|
| 344 |
+
"tests/test_parser.py::test_parser_collects_prefixes",
|
| 345 |
+
"tests/test_shell_completion.py::test_command",
|
| 346 |
+
"tests/test_shell_completion.py::test_group",
|
| 347 |
+
"tests/test_shell_completion.py::test_group_command_same_option",
|
| 348 |
+
"tests/test_shell_completion.py::test_chained",
|
| 349 |
+
"tests/test_shell_completion.py::test_help_option",
|
| 350 |
+
"tests/test_shell_completion.py::test_argument_order",
|
| 351 |
+
"tests/test_shell_completion.py::test_argument_default",
|
| 352 |
+
"tests/test_shell_completion.py::test_type_choice",
|
| 353 |
+
"tests/test_shell_completion.py::test_choice_special_characters",
|
| 354 |
+
"tests/test_shell_completion.py::test_choice_conflicting_prefix",
|
| 355 |
+
"tests/test_shell_completion.py::test_option_count",
|
| 356 |
+
"tests/test_shell_completion.py::test_option_optional",
|
| 357 |
+
"tests/test_shell_completion.py::test_path_types[type0-file]",
|
| 358 |
+
"tests/test_shell_completion.py::test_path_types[type1-file]",
|
| 359 |
+
"tests/test_shell_completion.py::test_path_types[type2-dir]",
|
| 360 |
+
"tests/test_shell_completion.py::test_absolute_path",
|
| 361 |
+
"tests/test_shell_completion.py::test_option_flag",
|
| 362 |
+
"tests/test_shell_completion.py::test_option_custom",
|
| 363 |
+
"tests/test_shell_completion.py::test_option_multiple",
|
| 364 |
+
"tests/test_shell_completion.py::test_option_nargs",
|
| 365 |
+
"tests/test_shell_completion.py::test_argument_nargs",
|
| 366 |
+
"tests/test_shell_completion.py::test_double_dash",
|
| 367 |
+
"tests/test_shell_completion.py::test_hidden",
|
| 368 |
+
"tests/test_shell_completion.py::test_add_different_name",
|
| 369 |
+
"tests/test_shell_completion.py::test_completion_item_data",
|
| 370 |
+
"tests/test_shell_completion.py::test_full_source[bash]",
|
| 371 |
+
"tests/test_shell_completion.py::test_full_source[zsh]",
|
| 372 |
+
"tests/test_shell_completion.py::test_full_source[fish]",
|
| 373 |
+
"tests/test_shell_completion.py::test_full_complete[bash-env0-plain,a\\nplain,b\\n]",
|
| 374 |
+
"tests/test_shell_completion.py::test_full_complete[bash-env1-plain,b\\n]",
|
| 375 |
+
"tests/test_shell_completion.py::test_full_complete[zsh-env2-plain\\na\\n_\\nplain\\nb\\nbee\\n]",
|
| 376 |
+
"tests/test_shell_completion.py::test_full_complete[zsh-env3-plain\\nb\\nbee\\n]",
|
| 377 |
+
"tests/test_shell_completion.py::test_full_complete[fish-env4-plain,a\\nplain,b\\tbee\\n]",
|
| 378 |
+
"tests/test_shell_completion.py::test_full_complete[fish-env5-plain,b\\tbee\\n]",
|
| 379 |
+
"tests/test_shell_completion.py::test_context_settings",
|
| 380 |
+
"tests/test_shell_completion.py::test_choice_case_sensitive[False-expect0]",
|
| 381 |
+
"tests/test_shell_completion.py::test_choice_case_sensitive[True-expect1]",
|
| 382 |
+
"tests/test_shell_completion.py::test_add_completion_class",
|
| 383 |
+
"tests/test_shell_completion.py::test_add_completion_class_with_name",
|
| 384 |
+
"tests/test_shell_completion.py::test_add_completion_class_decorator",
|
| 385 |
+
"tests/test_termui.py::test_progressbar_time_per_iteration[avg0-0.0]",
|
| 386 |
+
"tests/test_termui.py::test_progressbar_time_per_iteration[avg1-2.5]",
|
| 387 |
+
"tests/test_termui.py::test_progressbar_eta[False-5]",
|
| 388 |
+
"tests/test_termui.py::test_progressbar_eta[True-0]",
|
| 389 |
+
"tests/test_termui.py::test_progressbar_format_eta[0-00:00:00]",
|
| 390 |
+
"tests/test_termui.py::test_progressbar_format_eta[30-00:00:30]",
|
| 391 |
+
"tests/test_termui.py::test_progressbar_format_eta[90-00:01:30]",
|
| 392 |
+
"tests/test_termui.py::test_progressbar_format_eta[900-00:15:00]",
|
| 393 |
+
"tests/test_termui.py::test_progressbar_format_eta[9000-02:30:00]",
|
| 394 |
+
"tests/test_termui.py::test_progressbar_format_eta[None-]",
|
| 395 |
+
"tests/test_termui.py::test_progressbar_format_pos[0-5]",
|
| 396 |
+
"tests/test_termui.py::test_progressbar_format_pos[-1-1]",
|
| 397 |
+
"tests/test_termui.py::test_progressbar_format_pos[5-5]",
|
| 398 |
+
"tests/test_termui.py::test_progressbar_format_pos[6-5]",
|
| 399 |
+
"tests/test_termui.py::test_progressbar_format_pos[4-0]",
|
| 400 |
+
"tests/test_termui.py::test_progressbar_format_bar[8-False-7-0-#######-]",
|
| 401 |
+
"tests/test_termui.py::test_progressbar_format_bar[0-True-8-0-########]",
|
| 402 |
+
"tests/test_termui.py::test_progressbar_format_progress_line_with_show_func[test]",
|
| 403 |
+
"tests/test_termui.py::test_progressbar_format_progress_line_with_show_func[None]",
|
| 404 |
+
"tests/test_termui.py::test_progressbar_init_exceptions",
|
| 405 |
+
"tests/test_termui.py::test_progressbar_iter_outside_with_exceptions",
|
| 406 |
+
"tests/test_termui.py::test_secho",
|
| 407 |
+
"tests/test_termui.py::test_secho_non_text[123-\\x1b[45m123\\x1b[0m]",
|
| 408 |
+
"tests/test_termui.py::test_secho_non_text[test-test]",
|
| 409 |
+
"tests/test_termui.py::test_progressbar_yields_all_items",
|
| 410 |
+
"tests/test_termui.py::test_progress_bar_update_min_steps",
|
| 411 |
+
"tests/test_termui.py::test_fast_edit",
|
| 412 |
+
"tests/test_termui.py::test_edit",
|
| 413 |
+
"tests/test_testing.py::test_isolated_runner",
|
| 414 |
+
"tests/test_testing.py::test_isolated_runner_custom_tempdir",
|
| 415 |
+
"tests/test_testing.py::test_isolation_stderr_errors",
|
| 416 |
+
"tests/test_types.py::test_range[type0-3-3]",
|
| 417 |
+
"tests/test_types.py::test_range[type1-5-5]",
|
| 418 |
+
"tests/test_types.py::test_range[type2-100-100]",
|
| 419 |
+
"tests/test_types.py::test_range[type3-5-5]",
|
| 420 |
+
"tests/test_types.py::test_range[type4--100--100]",
|
| 421 |
+
"tests/test_types.py::test_range[type5--1-0]",
|
| 422 |
+
"tests/test_types.py::test_range[type6-6-5]",
|
| 423 |
+
"tests/test_types.py::test_range[type7-0-1]",
|
| 424 |
+
"tests/test_types.py::test_range[type8-5-4]",
|
| 425 |
+
"tests/test_types.py::test_range[type9-1.2-1.2]",
|
| 426 |
+
"tests/test_types.py::test_range[type10-0.51-0.51]",
|
| 427 |
+
"tests/test_types.py::test_range[type11-1.49-1.49]",
|
| 428 |
+
"tests/test_types.py::test_range[type12--0.0-0.5]",
|
| 429 |
+
"tests/test_types.py::test_range[type13-inf-1.5]",
|
| 430 |
+
"tests/test_types.py::test_range_fail[type3-0-0<x<=5]",
|
| 431 |
+
"tests/test_types.py::test_range_fail[type4-5-0<=x<5]",
|
| 432 |
+
"tests/test_types.py::test_range_fail[type5-0.5-x>0.5]",
|
| 433 |
+
"tests/test_types.py::test_range_fail[type6-1.5-x<1.5]",
|
| 434 |
+
"tests/test_types.py::test_float_range_no_clamp_open",
|
| 435 |
+
"tests/test_types.py::test_cast_multi_default[2-False-None-None]",
|
| 436 |
+
"tests/test_types.py::test_cast_multi_default[2-False-default1-expect1]",
|
| 437 |
+
"tests/test_types.py::test_cast_multi_default[None-True-None-expect2]",
|
| 438 |
+
"tests/test_types.py::test_cast_multi_default[None-True-default3-expect3]",
|
| 439 |
+
"tests/test_types.py::test_cast_multi_default[2-True-None-expect4]",
|
| 440 |
+
"tests/test_types.py::test_cast_multi_default[2-True-default5-expect5]",
|
| 441 |
+
"tests/test_types.py::test_cast_multi_default[-1-None-None-expect6]",
|
| 442 |
+
"tests/test_types.py::test_path_type[None-a/b/c.txt]",
|
| 443 |
+
"tests/test_types.py::test_path_type[str-a/b/c.txt]",
|
| 444 |
+
"tests/test_types.py::test_path_type[bytes-a/b/c.txt]",
|
| 445 |
+
"tests/test_types.py::test_path_type[Path-expect3]",
|
| 446 |
+
"tests/test_types.py::test_path_resolve_symlink",
|
| 447 |
+
"tests/test_types.py::test_path_surrogates",
|
| 448 |
+
"tests/test_types.py::test_file_surrogates[type0]",
|
| 449 |
+
"tests/test_types.py::test_file_surrogates[type1]",
|
| 450 |
+
"tests/test_types.py::test_file_error_surrogates",
|
| 451 |
+
"tests/test_types.py::test_invalid_path_with_esc_sequence",
|
| 452 |
+
"tests/test_types.py::test_choice_get_invalid_choice_message",
|
| 453 |
+
"tests/test_utils.py::test_echo_custom_file",
|
| 454 |
+
"tests/test_utils.py::test_echo_no_streams",
|
| 455 |
+
"tests/test_utils.py::test_filename_formatting",
|
| 456 |
+
"tests/test_utils.py::test_confirm_repeat",
|
| 457 |
+
"tests/test_utils.py::test_prompts_abort",
|
| 458 |
+
"tests/test_utils.py::test_echo_via_pager[test0]",
|
| 459 |
+
"tests/test_utils.py::test_echo_via_pager[test1]",
|
| 460 |
+
"tests/test_utils.py::test_echo_via_pager[test2]",
|
| 461 |
+
"tests/test_utils.py::test_echo_via_pager[test3]",
|
| 462 |
+
"tests/test_utils.py::test_echo_via_pager[test4]",
|
| 463 |
+
"tests/test_utils.py::test_echo_via_pager[test5]",
|
| 464 |
+
"tests/test_utils.py::test_echo_via_pager[test6]",
|
| 465 |
+
"tests/test_utils.py::test_echo_via_pager[test7]",
|
| 466 |
+
"tests/test_utils.py::test_echo_via_pager[test8]",
|
| 467 |
+
"tests/test_utils.py::test_echo_via_pager[test9]",
|
| 468 |
+
"tests/test_utils.py::test_echo_color_flag",
|
| 469 |
+
"tests/test_utils.py::test_prompt_cast_default",
|
| 470 |
+
"tests/test_utils.py::test_echo_writing_to_standard_error",
|
| 471 |
+
"tests/test_utils.py::test_echo_with_capsys",
|
| 472 |
+
"tests/test_utils.py::test_open_file_respects_ignore",
|
| 473 |
+
"tests/test_utils.py::test_open_file_ignore_invalid_utf8",
|
| 474 |
+
"tests/test_utils.py::test_open_file_ignore_no_encoding",
|
| 475 |
+
"tests/test_utils.py::test_iter_keepopenfile",
|
| 476 |
+
"tests/test_utils.py::test_iter_lazyfile",
|
| 477 |
+
"tests/test_utils.py::test_detect_program_name[example.py-None-example.py]",
|
| 478 |
+
"tests/test_utils.py::test_detect_program_name[/foo/bar/example.py-None-example.py]",
|
| 479 |
+
"tests/test_utils.py::test_detect_program_name[example-None-example]",
|
| 480 |
+
"tests/test_utils.py::test_detect_program_name[example--example]",
|
| 481 |
+
"tests/test_utils.py::test_expand_args",
|
| 482 |
+
"tests/test_utils.py::test_make_default_short_help[-empty]",
|
| 483 |
+
"tests/test_utils.py::test_make_default_short_help[-truncate]"
|
| 484 |
+
]
|
| 485 |
+
}
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/grade.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Trusted private pytest panel runner. Installed only in a fresh grader Job."""
|
| 2 |
+
|
| 3 |
+
import hashlib
|
| 4 |
+
import importlib.util
|
| 5 |
+
import json
|
| 6 |
+
import os
|
| 7 |
+
import shutil
|
| 8 |
+
import stat
|
| 9 |
+
import subprocess
|
| 10 |
+
from pathlib import Path, PurePosixPath
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def sha(raw):
|
| 14 |
+
return hashlib.sha256(raw).hexdigest()
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def safe(value):
|
| 18 |
+
path = PurePosixPath(value)
|
| 19 |
+
if (
|
| 20 |
+
path.is_absolute()
|
| 21 |
+
or path.as_posix() != value
|
| 22 |
+
or not path.parts
|
| 23 |
+
or any(part in {".", "..", ".git"} for part in path.parts)
|
| 24 |
+
):
|
| 25 |
+
raise ValueError("Unsafe trusted test path")
|
| 26 |
+
return path
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def restore(worktree, private, manifest):
|
| 30 |
+
worktree, private = Path(worktree), Path(private)
|
| 31 |
+
captured = {}
|
| 32 |
+
for name, expected in manifest["files"].items():
|
| 33 |
+
path = private / safe(name)
|
| 34 |
+
info = path.lstat()
|
| 35 |
+
raw = path.read_bytes() if stat.S_ISREG(info.st_mode) else b""
|
| 36 |
+
if (
|
| 37 |
+
not stat.S_ISREG(info.st_mode)
|
| 38 |
+
or len(raw) != expected["bytes"]
|
| 39 |
+
or sha(raw) != expected["sha256"]
|
| 40 |
+
or stat.S_IMODE(info.st_mode) != expected["mode"]
|
| 41 |
+
):
|
| 42 |
+
raise ValueError("Trusted private test bytes or modes drifted")
|
| 43 |
+
captured[name] = (raw, expected["mode"])
|
| 44 |
+
# Capture and verify every private byte before changing the submitted tree.
|
| 45 |
+
for name in manifest["directory_roots"]:
|
| 46 |
+
destination = worktree / safe(name)
|
| 47 |
+
if destination.is_symlink():
|
| 48 |
+
raise ValueError("Submitted test directory is a symlink")
|
| 49 |
+
for parent in destination.parents:
|
| 50 |
+
if parent == worktree:
|
| 51 |
+
break
|
| 52 |
+
if parent.is_symlink():
|
| 53 |
+
raise ValueError("Submitted test parent is a symlink")
|
| 54 |
+
if destination.exists():
|
| 55 |
+
if not destination.is_dir():
|
| 56 |
+
raise ValueError("Submitted test directory is not a directory")
|
| 57 |
+
shutil.rmtree(destination)
|
| 58 |
+
for name, (raw, mode) in captured.items():
|
| 59 |
+
destination = worktree / safe(name)
|
| 60 |
+
for parent in destination.parents:
|
| 61 |
+
if parent == worktree:
|
| 62 |
+
break
|
| 63 |
+
if parent.is_symlink():
|
| 64 |
+
raise ValueError("Submitted test parent is a symlink")
|
| 65 |
+
if destination.is_symlink():
|
| 66 |
+
raise ValueError("Submitted trusted file is a symlink")
|
| 67 |
+
destination.parent.mkdir(parents=True, exist_ok=True)
|
| 68 |
+
destination.write_bytes(raw)
|
| 69 |
+
destination.chmod(mode)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def run(worktree, private_root, output, invoke=None):
|
| 73 |
+
private_root, output, worktree = Path(private_root), Path(output), Path(worktree)
|
| 74 |
+
expected = json.loads((private_root / "expected-panels.json").read_bytes())
|
| 75 |
+
config = json.loads((private_root / "panel-config.json").read_bytes())
|
| 76 |
+
manifest = json.loads((private_root / "trusted-inventory.json").read_bytes())
|
| 77 |
+
restore(worktree, private_root / "trusted", manifest)
|
| 78 |
+
output.mkdir(parents=True, exist_ok=True)
|
| 79 |
+
for name in (
|
| 80 |
+
"reward.txt",
|
| 81 |
+
"pass-to-pass.xml",
|
| 82 |
+
"fail-to-pass.xml",
|
| 83 |
+
"pytest-evidence.json",
|
| 84 |
+
):
|
| 85 |
+
(output / name).unlink(missing_ok=True)
|
| 86 |
+
environment = dict(os.environ)
|
| 87 |
+
for key in ("PYTEST_ADDOPTS", "PYTEST_DISABLE_PLUGIN_AUTOLOAD", "PYTHONPATH"):
|
| 88 |
+
environment.pop(key, None)
|
| 89 |
+
commands, native_exit = [], 0
|
| 90 |
+
invoke = invoke or subprocess.run
|
| 91 |
+
for group in ("pass-to-pass", "fail-to-pass"):
|
| 92 |
+
if (
|
| 93 |
+
not isinstance(expected[group], list)
|
| 94 |
+
or not expected[group]
|
| 95 |
+
or any(
|
| 96 |
+
not isinstance(target, str) or not target for target in expected[group]
|
| 97 |
+
)
|
| 98 |
+
):
|
| 99 |
+
raise ValueError("Frozen native pytest selectors are incomplete")
|
| 100 |
+
command = [
|
| 101 |
+
*config["official_pytest_argv"],
|
| 102 |
+
"--override-ini=addopts=",
|
| 103 |
+
"--junitxml=" + str(output / (group + ".xml")),
|
| 104 |
+
*expected[group],
|
| 105 |
+
]
|
| 106 |
+
result = invoke(command, cwd=worktree, env=environment, check=False)
|
| 107 |
+
native_exit = result.returncode
|
| 108 |
+
commands.append({"group": group, "argv": command, "exit_code": native_exit})
|
| 109 |
+
if native_exit != 0:
|
| 110 |
+
break
|
| 111 |
+
(output / "pytest-commands.json").write_text(
|
| 112 |
+
json.dumps(commands, sort_keys=True) + "\n"
|
| 113 |
+
)
|
| 114 |
+
spec = importlib.util.spec_from_file_location(
|
| 115 |
+
"trusted_pytest_result", private_root / "check_pytest.py"
|
| 116 |
+
)
|
| 117 |
+
checker = importlib.util.module_from_spec(spec)
|
| 118 |
+
spec.loader.exec_module(checker)
|
| 119 |
+
result = checker.assess(output, expected, native_exit)
|
| 120 |
+
(output / "reward.txt").write_text(str(result["reward"]) + "\n")
|
| 121 |
+
(output / "pytest-evidence.json").write_text(
|
| 122 |
+
json.dumps(result, sort_keys=True) + "\n"
|
| 123 |
+
)
|
| 124 |
+
return result
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
if __name__ == "__main__":
|
| 128 |
+
run("/testbed/repo", "/tests", "/logs/verifier")
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/panel-config.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"dependency_installation_pinned": false,
|
| 3 |
+
"official_install_cmds": [
|
| 4 |
+
"python -m pip install -e ."
|
| 5 |
+
],
|
| 6 |
+
"official_pytest_argv": [
|
| 7 |
+
"pytest",
|
| 8 |
+
"--disable-warnings",
|
| 9 |
+
"--color=no",
|
| 10 |
+
"--tb=no",
|
| 11 |
+
"--verbose"
|
| 12 |
+
],
|
| 13 |
+
"official_test_command": "source /opt/miniconda3/bin/activate; conda activate testbed; pytest --disable-warnings --color=no --tb=no --verbose",
|
| 14 |
+
"panel_normalization": "Override project addopts only to execute the exact frozen native panels; add JUnit output, preserve official pytest options and all selectors.",
|
| 15 |
+
"python_version": "3.10",
|
| 16 |
+
"source_bound_test_dependency_cmds": [
|
| 17 |
+
"python -m pip install -r requirements/tests.txt"
|
| 18 |
+
],
|
| 19 |
+
"test_dependency_source_sha256": {
|
| 20 |
+
"requirements/tests.txt": "35f217825acd2a107dfb2c7b848d8a963e8d2eba6d7bd50e9fb34f3912e68658",
|
| 21 |
+
"tox.ini": "34183c21fb749d74f9a8299feaf931dcf01679634e3e9367923770cf83bb2838"
|
| 22 |
+
}
|
| 23 |
+
}
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/test.sh
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -Eeuo pipefail
|
| 3 |
+
source /opt/miniconda3/bin/activate
|
| 4 |
+
conda activate testbed
|
| 5 |
+
cd /testbed/repo
|
| 6 |
+
exec python -I /tests/grade.py
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted-inventory.json
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"directory_roots": [
|
| 3 |
+
"tests"
|
| 4 |
+
],
|
| 5 |
+
"files": {
|
| 6 |
+
"pyproject.toml": {
|
| 7 |
+
"bytes": 2059,
|
| 8 |
+
"mode": 420,
|
| 9 |
+
"sha256": "9613cb0037dd9c13abedfa097793fd78f78560ac605a995852caa3be5cb1d6ae"
|
| 10 |
+
},
|
| 11 |
+
"tests/conftest.py": {
|
| 12 |
+
"bytes": 131,
|
| 13 |
+
"mode": 420,
|
| 14 |
+
"sha256": "192be82444d6048fd222e2d73cd5c3bec768d65c6e10c0ffc230f307f363590b"
|
| 15 |
+
},
|
| 16 |
+
"tests/test_arguments.py": {
|
| 17 |
+
"bytes": 11929,
|
| 18 |
+
"mode": 420,
|
| 19 |
+
"sha256": "f8ebd354ffba0e644bf3516d379955ff4894d63137a8fd2b491f2478c48382bd"
|
| 20 |
+
},
|
| 21 |
+
"tests/test_basic.py": {
|
| 22 |
+
"bytes": 15452,
|
| 23 |
+
"mode": 420,
|
| 24 |
+
"sha256": "a22bb35be13097b31e48a9f352019c0319d88dc8e5c62bf8031f9a92d8408bb3"
|
| 25 |
+
},
|
| 26 |
+
"tests/test_chain.py": {
|
| 27 |
+
"bytes": 5786,
|
| 28 |
+
"mode": 420,
|
| 29 |
+
"sha256": "32247d8a208c84e571a89e87cbce389cc9aac08e98ece741c7d53fca0c63d881"
|
| 30 |
+
},
|
| 31 |
+
"tests/test_command_decorators.py": {
|
| 32 |
+
"bytes": 1880,
|
| 33 |
+
"mode": 420,
|
| 34 |
+
"sha256": "234ede359da2839923af2436056680bab68bdba622bf596452bbfbe1e1cfd6fa"
|
| 35 |
+
},
|
| 36 |
+
"tests/test_commands.py": {
|
| 37 |
+
"bytes": 11043,
|
| 38 |
+
"mode": 420,
|
| 39 |
+
"sha256": "9775d56ac9b373b3c6a1e92705b13f4ed5fc43a0bf984becd988437e815d2119"
|
| 40 |
+
},
|
| 41 |
+
"tests/test_compat.py": {
|
| 42 |
+
"bytes": 307,
|
| 43 |
+
"mode": 420,
|
| 44 |
+
"sha256": "5373454ca4b0718b079d1f49f1d153b0535686d6cf1f25291253b2dff1b5e748"
|
| 45 |
+
},
|
| 46 |
+
"tests/test_context.py": {
|
| 47 |
+
"bytes": 14294,
|
| 48 |
+
"mode": 420,
|
| 49 |
+
"sha256": "e7ab67acb6d3d413b8ecc1ad6d1ef64ac4ce49173b805b2f7d5851c81d680e54"
|
| 50 |
+
},
|
| 51 |
+
"tests/test_custom_classes.py": {
|
| 52 |
+
"bytes": 3022,
|
| 53 |
+
"mode": 420,
|
| 54 |
+
"sha256": "9d403c3b960ca927170645dcb144db33eb42c705208b6fa3b235c54889eee8e0"
|
| 55 |
+
},
|
| 56 |
+
"tests/test_defaults.py": {
|
| 57 |
+
"bytes": 2531,
|
| 58 |
+
"mode": 420,
|
| 59 |
+
"sha256": "1f835d0531beaaaa0fe99dcfa57635fa5e2cc9edd85d279a3f854a85551c8e45"
|
| 60 |
+
},
|
| 61 |
+
"tests/test_formatting.py": {
|
| 62 |
+
"bytes": 9413,
|
| 63 |
+
"mode": 420,
|
| 64 |
+
"sha256": "79c8ed50dd4507ef491a49dc7a69f2db65ee740f07fad31a09ff03b568141192"
|
| 65 |
+
},
|
| 66 |
+
"tests/test_imports.py": {
|
| 67 |
+
"bytes": 1414,
|
| 68 |
+
"mode": 420,
|
| 69 |
+
"sha256": "60310370edf02e88a94bb7f63c5a73eee7386b0b7adf6aa3e52633c073d7f929"
|
| 70 |
+
},
|
| 71 |
+
"tests/test_info_dict.py": {
|
| 72 |
+
"bytes": 7932,
|
| 73 |
+
"mode": 420,
|
| 74 |
+
"sha256": "544256b586fb50143e795b2f8023f5799e84ffdb57e34dcef31e386e6537098c"
|
| 75 |
+
},
|
| 76 |
+
"tests/test_normalization.py": {
|
| 77 |
+
"bytes": 955,
|
| 78 |
+
"mode": 420,
|
| 79 |
+
"sha256": "fab82963f1fe5a747429e324186e7fd34f7ef08a7ac20092c1899db3263f2376"
|
| 80 |
+
},
|
| 81 |
+
"tests/test_options.py": {
|
| 82 |
+
"bytes": 31807,
|
| 83 |
+
"mode": 420,
|
| 84 |
+
"sha256": "e18616e6a0a2e6f2bd9d8cb612c6ab0b36eafb1b6b3ac28fd374ffde3b4bfad3"
|
| 85 |
+
},
|
| 86 |
+
"tests/test_parser.py": {
|
| 87 |
+
"bytes": 915,
|
| 88 |
+
"mode": 420,
|
| 89 |
+
"sha256": "9e3a95fb896166e23bb8070de55a7d81a72a95c0b4909da659e54274b1615069"
|
| 90 |
+
},
|
| 91 |
+
"tests/test_shell_completion.py": {
|
| 92 |
+
"bytes": 14917,
|
| 93 |
+
"mode": 420,
|
| 94 |
+
"sha256": "faec10970de514a4a78abafb81573876f4ff383754969ef75954a6b850bf0f9e"
|
| 95 |
+
},
|
| 96 |
+
"tests/test_termui.py": {
|
| 97 |
+
"bytes": 15248,
|
| 98 |
+
"mode": 420,
|
| 99 |
+
"sha256": "14788f5acdeb49f9d3f8fefe2144bfad501a4519a2b42eec246c95746256fcf6"
|
| 100 |
+
},
|
| 101 |
+
"tests/test_testing.py": {
|
| 102 |
+
"bytes": 11102,
|
| 103 |
+
"mode": 420,
|
| 104 |
+
"sha256": "c63512960c836d493f11c143df8e35d43aa94b8b34af3516f97ca68bf348e369"
|
| 105 |
+
},
|
| 106 |
+
"tests/test_types.py": {
|
| 107 |
+
"bytes": 7807,
|
| 108 |
+
"mode": 420,
|
| 109 |
+
"sha256": "1d48de1f111b92b78153377db2286f6f37c306ded4b6b8c76111037743d7c8a1"
|
| 110 |
+
},
|
| 111 |
+
"tests/test_utils.py": {
|
| 112 |
+
"bytes": 21175,
|
| 113 |
+
"mode": 420,
|
| 114 |
+
"sha256": "424dee62b698503934682408d9aa28fe5be890f27ae4c92c7ab666ea9d2060f1"
|
| 115 |
+
},
|
| 116 |
+
"tests/typing/typing_aliased_group.py": {
|
| 117 |
+
"bytes": 1191,
|
| 118 |
+
"mode": 420,
|
| 119 |
+
"sha256": "0908243a61416433ff835ad517abf2a0f95275686dbb2fdb965579115a1f3189"
|
| 120 |
+
},
|
| 121 |
+
"tests/typing/typing_confirmation_option.py": {
|
| 122 |
+
"bytes": 326,
|
| 123 |
+
"mode": 420,
|
| 124 |
+
"sha256": "b25f68dfcef2a29c707aba78b722e46abe53a8e384e925f051e90e9e1e9d97c5"
|
| 125 |
+
},
|
| 126 |
+
"tests/typing/typing_group_kw_options.py": {
|
| 127 |
+
"bytes": 156,
|
| 128 |
+
"mode": 420,
|
| 129 |
+
"sha256": "53cb7ef7d78a9bbb1cd82e2e841a2b43efd1bf6b235ae002398eaf3272ecc87e"
|
| 130 |
+
},
|
| 131 |
+
"tests/typing/typing_help_option.py": {
|
| 132 |
+
"bytes": 262,
|
| 133 |
+
"mode": 420,
|
| 134 |
+
"sha256": "5dc1e21f7d8f4328f9c050294e1fc5964dd6b5ec01964b0f371fc2750721e545"
|
| 135 |
+
},
|
| 136 |
+
"tests/typing/typing_options.py": {
|
| 137 |
+
"bytes": 390,
|
| 138 |
+
"mode": 420,
|
| 139 |
+
"sha256": "a6579a3777cd63a27b030be925dcc1f38acbb46daf22f4092a3aee50b18ba043"
|
| 140 |
+
},
|
| 141 |
+
"tests/typing/typing_password_option.py": {
|
| 142 |
+
"bytes": 255,
|
| 143 |
+
"mode": 420,
|
| 144 |
+
"sha256": "71b7ae0e53bdde145628cbcb5f7a06a21e88ae58b438abfe99a8f0685549f4b6"
|
| 145 |
+
},
|
| 146 |
+
"tests/typing/typing_progressbar.py": {
|
| 147 |
+
"bytes": 559,
|
| 148 |
+
"mode": 420,
|
| 149 |
+
"sha256": "ba0529f20aa25016ffe36176db14437030b1fc7805a083b11742c5e03b3ba59c"
|
| 150 |
+
},
|
| 151 |
+
"tests/typing/typing_simple_example.py": {
|
| 152 |
+
"bytes": 508,
|
| 153 |
+
"mode": 420,
|
| 154 |
+
"sha256": "82c6a9d71dad51af7ce9f3c3cba5a9f9fc89184592d17d9385c14f330b81c64f"
|
| 155 |
+
},
|
| 156 |
+
"tests/typing/typing_version_option.py": {
|
| 157 |
+
"bytes": 287,
|
| 158 |
+
"mode": 420,
|
| 159 |
+
"sha256": "668cfdf7b197f178e519034ac8bce9f3901786ba6a9db0d1f2a9ef3c4b2d1ada"
|
| 160 |
+
},
|
| 161 |
+
"tox.ini": {
|
| 162 |
+
"bytes": 1203,
|
| 163 |
+
"mode": 420,
|
| 164 |
+
"sha256": "34183c21fb749d74f9a8299feaf931dcf01679634e3e9367923770cf83bb2838"
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
}
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/pyproject.toml
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[project]
|
| 2 |
+
name = "click"
|
| 3 |
+
version = "8.2.0.dev"
|
| 4 |
+
description = "Composable command line interface toolkit"
|
| 5 |
+
readme = "README.md"
|
| 6 |
+
license = {file = "LICENSE.txt"}
|
| 7 |
+
maintainers = [{name = "Pallets", email = "contact@palletsprojects.com"}]
|
| 8 |
+
classifiers = [
|
| 9 |
+
"Development Status :: 5 - Production/Stable",
|
| 10 |
+
"Intended Audience :: Developers",
|
| 11 |
+
"License :: OSI Approved :: BSD License",
|
| 12 |
+
"Operating System :: OS Independent",
|
| 13 |
+
"Programming Language :: Python",
|
| 14 |
+
"Typing :: Typed",
|
| 15 |
+
]
|
| 16 |
+
requires-python = ">=3.8"
|
| 17 |
+
dependencies = [
|
| 18 |
+
"colorama; platform_system == 'Windows'",
|
| 19 |
+
]
|
| 20 |
+
|
| 21 |
+
[project.urls]
|
| 22 |
+
Donate = "https://palletsprojects.com/donate"
|
| 23 |
+
Documentation = "https://click.palletsprojects.com/"
|
| 24 |
+
Changes = "https://click.palletsprojects.com/changes/"
|
| 25 |
+
Source = "https://github.com/pallets/click/"
|
| 26 |
+
Chat = "https://discord.gg/pallets"
|
| 27 |
+
|
| 28 |
+
[build-system]
|
| 29 |
+
requires = ["flit_core<4"]
|
| 30 |
+
build-backend = "flit_core.buildapi"
|
| 31 |
+
|
| 32 |
+
[tool.flit.module]
|
| 33 |
+
name = "click"
|
| 34 |
+
|
| 35 |
+
[tool.flit.sdist]
|
| 36 |
+
include = [
|
| 37 |
+
"docs/",
|
| 38 |
+
"requirements/",
|
| 39 |
+
"tests/",
|
| 40 |
+
"CHANGES.rst",
|
| 41 |
+
"tox.ini",
|
| 42 |
+
]
|
| 43 |
+
exclude = [
|
| 44 |
+
"docs/_build/",
|
| 45 |
+
]
|
| 46 |
+
|
| 47 |
+
[tool.pytest.ini_options]
|
| 48 |
+
testpaths = ["tests"]
|
| 49 |
+
filterwarnings = [
|
| 50 |
+
"error",
|
| 51 |
+
]
|
| 52 |
+
|
| 53 |
+
[tool.coverage.run]
|
| 54 |
+
branch = true
|
| 55 |
+
source = ["click", "tests"]
|
| 56 |
+
|
| 57 |
+
[tool.coverage.paths]
|
| 58 |
+
source = ["src", "*/site-packages"]
|
| 59 |
+
|
| 60 |
+
[tool.mypy]
|
| 61 |
+
python_version = "3.8"
|
| 62 |
+
files = ["src/click", "tests/typing"]
|
| 63 |
+
show_error_codes = true
|
| 64 |
+
pretty = true
|
| 65 |
+
strict = true
|
| 66 |
+
|
| 67 |
+
[[tool.mypy.overrides]]
|
| 68 |
+
module = [
|
| 69 |
+
"colorama.*",
|
| 70 |
+
]
|
| 71 |
+
ignore_missing_imports = true
|
| 72 |
+
|
| 73 |
+
[tool.pyright]
|
| 74 |
+
pythonVersion = "3.8"
|
| 75 |
+
include = ["src/click", "tests/typing"]
|
| 76 |
+
typeCheckingMode = "basic"
|
| 77 |
+
|
| 78 |
+
[tool.ruff]
|
| 79 |
+
extend-exclude = ["examples/"]
|
| 80 |
+
src = ["src"]
|
| 81 |
+
fix = true
|
| 82 |
+
show-fixes = true
|
| 83 |
+
output-format = "full"
|
| 84 |
+
|
| 85 |
+
[tool.ruff.lint]
|
| 86 |
+
select = [
|
| 87 |
+
"B", # flake8-bugbear
|
| 88 |
+
"E", # pycodestyle error
|
| 89 |
+
"F", # pyflakes
|
| 90 |
+
"I", # isort
|
| 91 |
+
"UP", # pyupgrade
|
| 92 |
+
"W", # pycodestyle warning
|
| 93 |
+
]
|
| 94 |
+
|
| 95 |
+
[tool.ruff.lint.isort]
|
| 96 |
+
force-single-line = true
|
| 97 |
+
order-by-type = false
|
| 98 |
+
|
| 99 |
+
[tool.gha-update]
|
| 100 |
+
tag-only = [
|
| 101 |
+
"slsa-framework/slsa-github-generator",
|
| 102 |
+
]
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/conftest.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
|
| 3 |
+
from click.testing import CliRunner
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
@pytest.fixture(scope="function")
|
| 7 |
+
def runner(request):
|
| 8 |
+
return CliRunner()
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_arguments.py
ADDED
|
@@ -0,0 +1,436 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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| 10 |
+
@click.command()
|
| 11 |
+
@click.argument("src", nargs=-1)
|
| 12 |
+
@click.argument("dst")
|
| 13 |
+
def copy(src, dst):
|
| 14 |
+
click.echo(f"src={'|'.join(src)}")
|
| 15 |
+
click.echo(f"dst={dst}")
|
| 16 |
+
|
| 17 |
+
result = runner.invoke(copy, ["foo.txt", "bar.txt", "dir"])
|
| 18 |
+
assert not result.exception
|
| 19 |
+
assert result.output.splitlines() == ["src=foo.txt|bar.txt", "dst=dir"]
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def test_argument_unbounded_nargs_cant_have_default(runner):
|
| 23 |
+
with pytest.raises(TypeError, match="nargs=-1"):
|
| 24 |
+
|
| 25 |
+
@click.command()
|
| 26 |
+
@click.argument("src", nargs=-1, default=["42"])
|
| 27 |
+
def copy(src):
|
| 28 |
+
pass
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def test_nargs_tup(runner):
|
| 32 |
+
@click.command()
|
| 33 |
+
@click.argument("name", nargs=1)
|
| 34 |
+
@click.argument("point", nargs=2, type=click.INT)
|
| 35 |
+
def copy(name, point):
|
| 36 |
+
click.echo(f"name={name}")
|
| 37 |
+
x, y = point
|
| 38 |
+
click.echo(f"point={x}/{y}")
|
| 39 |
+
|
| 40 |
+
result = runner.invoke(copy, ["peter", "1", "2"])
|
| 41 |
+
assert not result.exception
|
| 42 |
+
assert result.output.splitlines() == ["name=peter", "point=1/2"]
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
@pytest.mark.parametrize(
|
| 46 |
+
"opts",
|
| 47 |
+
[
|
| 48 |
+
dict(type=(str, int)),
|
| 49 |
+
dict(type=click.Tuple([str, int])),
|
| 50 |
+
dict(nargs=2, type=click.Tuple([str, int])),
|
| 51 |
+
dict(nargs=2, type=(str, int)),
|
| 52 |
+
],
|
| 53 |
+
)
|
| 54 |
+
def test_nargs_tup_composite(runner, opts):
|
| 55 |
+
@click.command()
|
| 56 |
+
@click.argument("item", **opts)
|
| 57 |
+
def copy(item):
|
| 58 |
+
name, id = item
|
| 59 |
+
click.echo(f"name={name} id={id:d}")
|
| 60 |
+
|
| 61 |
+
result = runner.invoke(copy, ["peter", "1"])
|
| 62 |
+
assert result.exception is None
|
| 63 |
+
assert result.output.splitlines() == ["name=peter id=1"]
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def test_nargs_err(runner):
|
| 67 |
+
@click.command()
|
| 68 |
+
@click.argument("x")
|
| 69 |
+
def copy(x):
|
| 70 |
+
click.echo(x)
|
| 71 |
+
|
| 72 |
+
result = runner.invoke(copy, ["foo"])
|
| 73 |
+
assert not result.exception
|
| 74 |
+
assert result.output == "foo\n"
|
| 75 |
+
|
| 76 |
+
result = runner.invoke(copy, ["foo", "bar"])
|
| 77 |
+
assert result.exit_code == 2
|
| 78 |
+
assert "Got unexpected extra argument (bar)" in result.output
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def test_bytes_args(runner, monkeypatch):
|
| 82 |
+
@click.command()
|
| 83 |
+
@click.argument("arg")
|
| 84 |
+
def from_bytes(arg):
|
| 85 |
+
assert isinstance(
|
| 86 |
+
arg, str
|
| 87 |
+
), "UTF-8 encoded argument should be implicitly converted to Unicode"
|
| 88 |
+
|
| 89 |
+
# Simulate empty locale environment variables
|
| 90 |
+
monkeypatch.setattr(sys, "getfilesystemencoding", lambda: "utf-8")
|
| 91 |
+
monkeypatch.setattr(sys, "getdefaultencoding", lambda: "utf-8")
|
| 92 |
+
# sys.stdin.encoding is readonly, needs some extra effort to patch.
|
| 93 |
+
stdin = mock.Mock(wraps=sys.stdin)
|
| 94 |
+
stdin.encoding = "utf-8"
|
| 95 |
+
monkeypatch.setattr(sys, "stdin", stdin)
|
| 96 |
+
|
| 97 |
+
runner.invoke(
|
| 98 |
+
from_bytes,
|
| 99 |
+
["Something outside of ASCII range: 林".encode()],
|
| 100 |
+
catch_exceptions=False,
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def test_file_args(runner):
|
| 105 |
+
@click.command()
|
| 106 |
+
@click.argument("input", type=click.File("rb"))
|
| 107 |
+
@click.argument("output", type=click.File("wb"))
|
| 108 |
+
def inout(input, output):
|
| 109 |
+
while True:
|
| 110 |
+
chunk = input.read(1024)
|
| 111 |
+
if not chunk:
|
| 112 |
+
break
|
| 113 |
+
output.write(chunk)
|
| 114 |
+
|
| 115 |
+
with runner.isolated_filesystem():
|
| 116 |
+
result = runner.invoke(inout, ["-", "hello.txt"], input="Hey!")
|
| 117 |
+
assert result.output == ""
|
| 118 |
+
assert result.exit_code == 0
|
| 119 |
+
with open("hello.txt", "rb") as f:
|
| 120 |
+
assert f.read() == b"Hey!"
|
| 121 |
+
|
| 122 |
+
result = runner.invoke(inout, ["hello.txt", "-"])
|
| 123 |
+
assert result.output == "Hey!"
|
| 124 |
+
assert result.exit_code == 0
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def test_path_allow_dash(runner):
|
| 128 |
+
@click.command()
|
| 129 |
+
@click.argument("input", type=click.Path(allow_dash=True))
|
| 130 |
+
def foo(input):
|
| 131 |
+
click.echo(input)
|
| 132 |
+
|
| 133 |
+
result = runner.invoke(foo, ["-"])
|
| 134 |
+
assert result.output == "-\n"
|
| 135 |
+
assert result.exit_code == 0
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def test_file_atomics(runner):
|
| 139 |
+
@click.command()
|
| 140 |
+
@click.argument("output", type=click.File("wb", atomic=True))
|
| 141 |
+
def inout(output):
|
| 142 |
+
output.write(b"Foo bar baz\n")
|
| 143 |
+
output.flush()
|
| 144 |
+
with open(output.name, "rb") as f:
|
| 145 |
+
old_content = f.read()
|
| 146 |
+
assert old_content == b"OLD\n"
|
| 147 |
+
|
| 148 |
+
with runner.isolated_filesystem():
|
| 149 |
+
with open("foo.txt", "wb") as f:
|
| 150 |
+
f.write(b"OLD\n")
|
| 151 |
+
result = runner.invoke(inout, ["foo.txt"], input="Hey!", catch_exceptions=False)
|
| 152 |
+
assert result.output == ""
|
| 153 |
+
assert result.exit_code == 0
|
| 154 |
+
with open("foo.txt", "rb") as f:
|
| 155 |
+
assert f.read() == b"Foo bar baz\n"
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
def test_stdout_default(runner):
|
| 159 |
+
@click.command()
|
| 160 |
+
@click.argument("output", type=click.File("w"), default="-")
|
| 161 |
+
def inout(output):
|
| 162 |
+
output.write("Foo bar baz\n")
|
| 163 |
+
output.flush()
|
| 164 |
+
|
| 165 |
+
result = runner.invoke(inout, [])
|
| 166 |
+
assert not result.exception
|
| 167 |
+
assert result.output == "Foo bar baz\n"
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
@pytest.mark.parametrize(
|
| 171 |
+
("nargs", "value", "expect"),
|
| 172 |
+
[
|
| 173 |
+
(2, "", None),
|
| 174 |
+
(2, "a", "Takes 2 values but 1 was given."),
|
| 175 |
+
(2, "a b", ("a", "b")),
|
| 176 |
+
(2, "a b c", "Takes 2 values but 3 were given."),
|
| 177 |
+
(-1, "a b c", ("a", "b", "c")),
|
| 178 |
+
(-1, "", ()),
|
| 179 |
+
],
|
| 180 |
+
)
|
| 181 |
+
def test_nargs_envvar(runner, nargs, value, expect):
|
| 182 |
+
if nargs == -1:
|
| 183 |
+
param = click.argument("arg", envvar="X", nargs=nargs)
|
| 184 |
+
else:
|
| 185 |
+
param = click.option("--arg", envvar="X", nargs=nargs)
|
| 186 |
+
|
| 187 |
+
@click.command()
|
| 188 |
+
@param
|
| 189 |
+
def cmd(arg):
|
| 190 |
+
return arg
|
| 191 |
+
|
| 192 |
+
result = runner.invoke(cmd, env={"X": value}, standalone_mode=False)
|
| 193 |
+
|
| 194 |
+
if isinstance(expect, str):
|
| 195 |
+
assert isinstance(result.exception, click.BadParameter)
|
| 196 |
+
assert expect in result.exception.format_message()
|
| 197 |
+
else:
|
| 198 |
+
assert result.return_value == expect
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def test_envvar_flag_value(runner):
|
| 202 |
+
@click.command()
|
| 203 |
+
# is_flag is implicitly true
|
| 204 |
+
@click.option("--upper", flag_value="upper", envvar="UPPER")
|
| 205 |
+
def cmd(upper):
|
| 206 |
+
click.echo(upper)
|
| 207 |
+
return upper
|
| 208 |
+
|
| 209 |
+
# For whatever value of the `env` variable, if it exists, the flag should be `upper`
|
| 210 |
+
result = runner.invoke(cmd, env={"UPPER": "whatever"})
|
| 211 |
+
assert result.output.strip() == "upper"
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
def test_nargs_envvar_only_if_values_empty(runner):
|
| 215 |
+
@click.command()
|
| 216 |
+
@click.argument("arg", envvar="X", nargs=-1)
|
| 217 |
+
def cli(arg):
|
| 218 |
+
return arg
|
| 219 |
+
|
| 220 |
+
result = runner.invoke(cli, ["a", "b"], standalone_mode=False)
|
| 221 |
+
assert result.return_value == ("a", "b")
|
| 222 |
+
|
| 223 |
+
result = runner.invoke(cli, env={"X": "a"}, standalone_mode=False)
|
| 224 |
+
assert result.return_value == ("a",)
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
def test_empty_nargs(runner):
|
| 228 |
+
@click.command()
|
| 229 |
+
@click.argument("arg", nargs=-1)
|
| 230 |
+
def cmd(arg):
|
| 231 |
+
click.echo(f"arg:{'|'.join(arg)}")
|
| 232 |
+
|
| 233 |
+
result = runner.invoke(cmd, [])
|
| 234 |
+
assert result.exit_code == 0
|
| 235 |
+
assert result.output == "arg:\n"
|
| 236 |
+
|
| 237 |
+
@click.command()
|
| 238 |
+
@click.argument("arg", nargs=-1, required=True)
|
| 239 |
+
def cmd2(arg):
|
| 240 |
+
click.echo(f"arg:{'|'.join(arg)}")
|
| 241 |
+
|
| 242 |
+
result = runner.invoke(cmd2, [])
|
| 243 |
+
assert result.exit_code == 2
|
| 244 |
+
assert "Missing argument 'ARG...'" in result.output
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
def test_missing_arg(runner):
|
| 248 |
+
@click.command()
|
| 249 |
+
@click.argument("arg")
|
| 250 |
+
def cmd(arg):
|
| 251 |
+
click.echo(f"arg:{arg}")
|
| 252 |
+
|
| 253 |
+
result = runner.invoke(cmd, [])
|
| 254 |
+
assert result.exit_code == 2
|
| 255 |
+
assert "Missing argument 'ARG'." in result.output
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
def test_missing_argument_string_cast():
|
| 259 |
+
ctx = click.Context(click.Command(""))
|
| 260 |
+
|
| 261 |
+
with pytest.raises(click.MissingParameter) as excinfo:
|
| 262 |
+
click.Argument(["a"], required=True).process_value(ctx, None)
|
| 263 |
+
|
| 264 |
+
assert str(excinfo.value) == "Missing parameter: a"
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def test_implicit_non_required(runner):
|
| 268 |
+
@click.command()
|
| 269 |
+
@click.argument("f", default="test")
|
| 270 |
+
def cli(f):
|
| 271 |
+
click.echo(f)
|
| 272 |
+
|
| 273 |
+
result = runner.invoke(cli, [])
|
| 274 |
+
assert result.exit_code == 0
|
| 275 |
+
assert result.output == "test\n"
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
def test_eat_options(runner):
|
| 279 |
+
@click.command()
|
| 280 |
+
@click.option("-f")
|
| 281 |
+
@click.argument("files", nargs=-1)
|
| 282 |
+
def cmd(f, files):
|
| 283 |
+
for filename in files:
|
| 284 |
+
click.echo(filename)
|
| 285 |
+
click.echo(f)
|
| 286 |
+
|
| 287 |
+
result = runner.invoke(cmd, ["--", "-foo", "bar"])
|
| 288 |
+
assert result.output.splitlines() == ["-foo", "bar", ""]
|
| 289 |
+
|
| 290 |
+
result = runner.invoke(cmd, ["-f", "-x", "--", "-foo", "bar"])
|
| 291 |
+
assert result.output.splitlines() == ["-foo", "bar", "-x"]
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
def test_nargs_star_ordering(runner):
|
| 295 |
+
@click.command()
|
| 296 |
+
@click.argument("a", nargs=-1)
|
| 297 |
+
@click.argument("b")
|
| 298 |
+
@click.argument("c")
|
| 299 |
+
def cmd(a, b, c):
|
| 300 |
+
for arg in (a, b, c):
|
| 301 |
+
click.echo(arg)
|
| 302 |
+
|
| 303 |
+
result = runner.invoke(cmd, ["a", "b", "c"])
|
| 304 |
+
assert result.output.splitlines() == ["('a',)", "b", "c"]
|
| 305 |
+
|
| 306 |
+
|
| 307 |
+
def test_nargs_specified_plus_star_ordering(runner):
|
| 308 |
+
@click.command()
|
| 309 |
+
@click.argument("a", nargs=-1)
|
| 310 |
+
@click.argument("b")
|
| 311 |
+
@click.argument("c", nargs=2)
|
| 312 |
+
def cmd(a, b, c):
|
| 313 |
+
for arg in (a, b, c):
|
| 314 |
+
click.echo(arg)
|
| 315 |
+
|
| 316 |
+
result = runner.invoke(cmd, ["a", "b", "c", "d", "e", "f"])
|
| 317 |
+
assert result.output.splitlines() == ["('a', 'b', 'c')", "d", "('e', 'f')"]
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
def test_defaults_for_nargs(runner):
|
| 321 |
+
@click.command()
|
| 322 |
+
@click.argument("a", nargs=2, type=int, default=(1, 2))
|
| 323 |
+
def cmd(a):
|
| 324 |
+
x, y = a
|
| 325 |
+
click.echo(x + y)
|
| 326 |
+
|
| 327 |
+
result = runner.invoke(cmd, [])
|
| 328 |
+
assert result.output.strip() == "3"
|
| 329 |
+
|
| 330 |
+
result = runner.invoke(cmd, ["3", "4"])
|
| 331 |
+
assert result.output.strip() == "7"
|
| 332 |
+
|
| 333 |
+
result = runner.invoke(cmd, ["3"])
|
| 334 |
+
assert result.exception is not None
|
| 335 |
+
assert "Argument 'a' takes 2 values." in result.output
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
def test_multiple_param_decls_not_allowed(runner):
|
| 339 |
+
with pytest.raises(TypeError):
|
| 340 |
+
|
| 341 |
+
@click.command()
|
| 342 |
+
@click.argument("x", click.Choice(["a", "b"]))
|
| 343 |
+
def copy(x):
|
| 344 |
+
click.echo(x)
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
def test_multiple_not_allowed():
|
| 348 |
+
with pytest.raises(TypeError, match="multiple"):
|
| 349 |
+
click.Argument(["a"], multiple=True)
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
@pytest.mark.parametrize("value", [(), ("a",), ("a", "b", "c")])
|
| 353 |
+
def test_nargs_bad_default(runner, value):
|
| 354 |
+
with pytest.raises(ValueError, match="nargs=2"):
|
| 355 |
+
click.Argument(["a"], nargs=2, default=value)
|
| 356 |
+
|
| 357 |
+
|
| 358 |
+
def test_subcommand_help(runner):
|
| 359 |
+
@click.group()
|
| 360 |
+
@click.argument("name")
|
| 361 |
+
@click.argument("val")
|
| 362 |
+
@click.option("--opt")
|
| 363 |
+
@click.pass_context
|
| 364 |
+
def cli(ctx, name, val, opt):
|
| 365 |
+
ctx.obj = dict(name=name, val=val)
|
| 366 |
+
|
| 367 |
+
@cli.command()
|
| 368 |
+
@click.pass_obj
|
| 369 |
+
def cmd(obj):
|
| 370 |
+
click.echo(f"CMD for {obj['name']} with value {obj['val']}")
|
| 371 |
+
|
| 372 |
+
result = runner.invoke(cli, ["foo", "bar", "cmd", "--help"])
|
| 373 |
+
assert not result.exception
|
| 374 |
+
assert "Usage: cli NAME VAL cmd [OPTIONS]" in result.output
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
def test_nested_subcommand_help(runner):
|
| 378 |
+
@click.group()
|
| 379 |
+
@click.argument("arg1")
|
| 380 |
+
@click.option("--opt1")
|
| 381 |
+
def cli(arg1, opt1):
|
| 382 |
+
pass
|
| 383 |
+
|
| 384 |
+
@cli.group()
|
| 385 |
+
@click.argument("arg2")
|
| 386 |
+
@click.option("--opt2")
|
| 387 |
+
def cmd(arg2, opt2):
|
| 388 |
+
pass
|
| 389 |
+
|
| 390 |
+
@cmd.command()
|
| 391 |
+
def subcmd():
|
| 392 |
+
click.echo("subcommand")
|
| 393 |
+
|
| 394 |
+
result = runner.invoke(cli, ["arg1", "cmd", "arg2", "subcmd", "--help"])
|
| 395 |
+
assert not result.exception
|
| 396 |
+
assert "Usage: cli ARG1 cmd ARG2 subcmd [OPTIONS]" in result.output
|
| 397 |
+
|
| 398 |
+
|
| 399 |
+
def test_when_argument_decorator_is_used_multiple_times_cls_is_preserved():
|
| 400 |
+
class CustomArgument(click.Argument):
|
| 401 |
+
pass
|
| 402 |
+
|
| 403 |
+
reusable_argument = click.argument("art", cls=CustomArgument)
|
| 404 |
+
|
| 405 |
+
@click.command()
|
| 406 |
+
@reusable_argument
|
| 407 |
+
def foo(arg):
|
| 408 |
+
pass
|
| 409 |
+
|
| 410 |
+
@click.command()
|
| 411 |
+
@reusable_argument
|
| 412 |
+
def bar(arg):
|
| 413 |
+
pass
|
| 414 |
+
|
| 415 |
+
assert isinstance(foo.params[0], CustomArgument)
|
| 416 |
+
assert isinstance(bar.params[0], CustomArgument)
|
| 417 |
+
|
| 418 |
+
|
| 419 |
+
@pytest.mark.parametrize(
|
| 420 |
+
"args_one,args_two",
|
| 421 |
+
[
|
| 422 |
+
(
|
| 423 |
+
("aardvark",),
|
| 424 |
+
("aardvark",),
|
| 425 |
+
),
|
| 426 |
+
],
|
| 427 |
+
)
|
| 428 |
+
def test_duplicate_names_warning(runner, args_one, args_two):
|
| 429 |
+
@click.command()
|
| 430 |
+
@click.argument(*args_one)
|
| 431 |
+
@click.argument(*args_two)
|
| 432 |
+
def cli(one, two):
|
| 433 |
+
pass
|
| 434 |
+
|
| 435 |
+
with pytest.warns(UserWarning):
|
| 436 |
+
runner.invoke(cli, [])
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_basic.py
ADDED
|
@@ -0,0 +1,575 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from itertools import chain
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
import click
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def test_basic_functionality(runner):
|
| 10 |
+
@click.command()
|
| 11 |
+
def cli():
|
| 12 |
+
"""Hello World!"""
|
| 13 |
+
click.echo("I EXECUTED")
|
| 14 |
+
|
| 15 |
+
result = runner.invoke(cli, ["--help"])
|
| 16 |
+
assert not result.exception
|
| 17 |
+
assert "Hello World!" in result.output
|
| 18 |
+
assert "Show this message and exit." in result.output
|
| 19 |
+
assert result.exit_code == 0
|
| 20 |
+
assert "I EXECUTED" not in result.output
|
| 21 |
+
|
| 22 |
+
result = runner.invoke(cli, [])
|
| 23 |
+
assert not result.exception
|
| 24 |
+
assert "I EXECUTED" in result.output
|
| 25 |
+
assert result.exit_code == 0
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def test_repr():
|
| 29 |
+
@click.command()
|
| 30 |
+
def command():
|
| 31 |
+
pass
|
| 32 |
+
|
| 33 |
+
@click.group()
|
| 34 |
+
def group():
|
| 35 |
+
pass
|
| 36 |
+
|
| 37 |
+
@group.command()
|
| 38 |
+
def subcommand():
|
| 39 |
+
pass
|
| 40 |
+
|
| 41 |
+
assert repr(command) == "<Command command>"
|
| 42 |
+
assert repr(group) == "<Group group>"
|
| 43 |
+
assert repr(subcommand) == "<Command subcommand>"
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def test_return_values():
|
| 47 |
+
@click.command()
|
| 48 |
+
def cli():
|
| 49 |
+
return 42
|
| 50 |
+
|
| 51 |
+
with cli.make_context("foo", []) as ctx:
|
| 52 |
+
rv = cli.invoke(ctx)
|
| 53 |
+
assert rv == 42
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def test_basic_group(runner):
|
| 57 |
+
@click.group()
|
| 58 |
+
def cli():
|
| 59 |
+
"""This is the root."""
|
| 60 |
+
click.echo("ROOT EXECUTED")
|
| 61 |
+
|
| 62 |
+
@cli.command()
|
| 63 |
+
def subcommand():
|
| 64 |
+
"""This is a subcommand."""
|
| 65 |
+
click.echo("SUBCOMMAND EXECUTED")
|
| 66 |
+
|
| 67 |
+
result = runner.invoke(cli, ["--help"])
|
| 68 |
+
assert not result.exception
|
| 69 |
+
assert "COMMAND [ARGS]..." in result.output
|
| 70 |
+
assert "This is the root" in result.output
|
| 71 |
+
assert "This is a subcommand." in result.output
|
| 72 |
+
assert result.exit_code == 0
|
| 73 |
+
assert "ROOT EXECUTED" not in result.output
|
| 74 |
+
|
| 75 |
+
result = runner.invoke(cli, ["subcommand"])
|
| 76 |
+
assert not result.exception
|
| 77 |
+
assert result.exit_code == 0
|
| 78 |
+
assert "ROOT EXECUTED" in result.output
|
| 79 |
+
assert "SUBCOMMAND EXECUTED" in result.output
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def test_group_commands_dict(runner):
|
| 83 |
+
"""A Group can be built with a dict of commands."""
|
| 84 |
+
|
| 85 |
+
@click.command()
|
| 86 |
+
def sub():
|
| 87 |
+
click.echo("sub", nl=False)
|
| 88 |
+
|
| 89 |
+
cli = click.Group(commands={"other": sub})
|
| 90 |
+
result = runner.invoke(cli, ["other"])
|
| 91 |
+
assert result.output == "sub"
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def test_group_from_list(runner):
|
| 95 |
+
"""A Group can be built with a list of commands."""
|
| 96 |
+
|
| 97 |
+
@click.command()
|
| 98 |
+
def sub():
|
| 99 |
+
click.echo("sub", nl=False)
|
| 100 |
+
|
| 101 |
+
cli = click.Group(commands=[sub])
|
| 102 |
+
result = runner.invoke(cli, ["sub"])
|
| 103 |
+
assert result.output == "sub"
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
@pytest.mark.parametrize(
|
| 107 |
+
("args", "expect"),
|
| 108 |
+
[
|
| 109 |
+
([], "S:[no value]"),
|
| 110 |
+
(["--s=42"], "S:[42]"),
|
| 111 |
+
(["--s"], "Error: Option '--s' requires an argument."),
|
| 112 |
+
(["--s="], "S:[]"),
|
| 113 |
+
(["--s=\N{SNOWMAN}"], "S:[\N{SNOWMAN}]"),
|
| 114 |
+
],
|
| 115 |
+
)
|
| 116 |
+
def test_string_option(runner, args, expect):
|
| 117 |
+
@click.command()
|
| 118 |
+
@click.option("--s", default="no value")
|
| 119 |
+
def cli(s):
|
| 120 |
+
click.echo(f"S:[{s}]")
|
| 121 |
+
|
| 122 |
+
result = runner.invoke(cli, args)
|
| 123 |
+
assert expect in result.output
|
| 124 |
+
|
| 125 |
+
if expect.startswith("Error:"):
|
| 126 |
+
assert result.exception is not None
|
| 127 |
+
else:
|
| 128 |
+
assert result.exception is None
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
@pytest.mark.parametrize(
|
| 132 |
+
("args", "expect"),
|
| 133 |
+
[
|
| 134 |
+
([], "I:[84]"),
|
| 135 |
+
(["--i=23"], "I:[46]"),
|
| 136 |
+
(["--i=x"], "Error: Invalid value for '--i': 'x' is not a valid integer."),
|
| 137 |
+
],
|
| 138 |
+
)
|
| 139 |
+
def test_int_option(runner, args, expect):
|
| 140 |
+
@click.command()
|
| 141 |
+
@click.option("--i", default=42)
|
| 142 |
+
def cli(i):
|
| 143 |
+
click.echo(f"I:[{i * 2}]")
|
| 144 |
+
|
| 145 |
+
result = runner.invoke(cli, args)
|
| 146 |
+
assert expect in result.output
|
| 147 |
+
|
| 148 |
+
if expect.startswith("Error:"):
|
| 149 |
+
assert result.exception is not None
|
| 150 |
+
else:
|
| 151 |
+
assert result.exception is None
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
@pytest.mark.parametrize(
|
| 155 |
+
("args", "expect"),
|
| 156 |
+
[
|
| 157 |
+
([], "U:[ba122011-349f-423b-873b-9d6a79c688ab]"),
|
| 158 |
+
(
|
| 159 |
+
["--u=821592c1-c50e-4971-9cd6-e89dc6832f86"],
|
| 160 |
+
"U:[821592c1-c50e-4971-9cd6-e89dc6832f86]",
|
| 161 |
+
),
|
| 162 |
+
(["--u=x"], "Error: Invalid value for '--u': 'x' is not a valid UUID."),
|
| 163 |
+
],
|
| 164 |
+
)
|
| 165 |
+
def test_uuid_option(runner, args, expect):
|
| 166 |
+
@click.command()
|
| 167 |
+
@click.option(
|
| 168 |
+
"--u", default="ba122011-349f-423b-873b-9d6a79c688ab", type=click.UUID
|
| 169 |
+
)
|
| 170 |
+
def cli(u):
|
| 171 |
+
click.echo(f"U:[{u}]")
|
| 172 |
+
|
| 173 |
+
result = runner.invoke(cli, args)
|
| 174 |
+
assert expect in result.output
|
| 175 |
+
|
| 176 |
+
if expect.startswith("Error:"):
|
| 177 |
+
assert result.exception is not None
|
| 178 |
+
else:
|
| 179 |
+
assert result.exception is None
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
@pytest.mark.parametrize(
|
| 183 |
+
("args", "expect"),
|
| 184 |
+
[
|
| 185 |
+
([], "F:[42.0]"),
|
| 186 |
+
("--f=23.5", "F:[23.5]"),
|
| 187 |
+
("--f=x", "Error: Invalid value for '--f': 'x' is not a valid float."),
|
| 188 |
+
],
|
| 189 |
+
)
|
| 190 |
+
def test_float_option(runner, args, expect):
|
| 191 |
+
@click.command()
|
| 192 |
+
@click.option("--f", default=42.0)
|
| 193 |
+
def cli(f):
|
| 194 |
+
click.echo(f"F:[{f}]")
|
| 195 |
+
|
| 196 |
+
result = runner.invoke(cli, args)
|
| 197 |
+
assert expect in result.output
|
| 198 |
+
|
| 199 |
+
if expect.startswith("Error:"):
|
| 200 |
+
assert result.exception is not None
|
| 201 |
+
else:
|
| 202 |
+
assert result.exception is None
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
@pytest.mark.parametrize("default", [True, False])
|
| 206 |
+
@pytest.mark.parametrize(
|
| 207 |
+
("args", "expect"), [(["--on"], True), (["--off"], False), ([], None)]
|
| 208 |
+
)
|
| 209 |
+
def test_boolean_switch(runner, default, args, expect):
|
| 210 |
+
@click.command()
|
| 211 |
+
@click.option("--on/--off", default=default)
|
| 212 |
+
def cli(on):
|
| 213 |
+
return on
|
| 214 |
+
|
| 215 |
+
if expect is None:
|
| 216 |
+
expect = default
|
| 217 |
+
|
| 218 |
+
result = runner.invoke(cli, args, standalone_mode=False)
|
| 219 |
+
assert result.return_value is expect
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
@pytest.mark.parametrize("default", [True, False])
|
| 223 |
+
@pytest.mark.parametrize(("args", "expect"), [(["--f"], True), ([], False)])
|
| 224 |
+
def test_boolean_flag(runner, default, args, expect):
|
| 225 |
+
@click.command()
|
| 226 |
+
@click.option("--f", is_flag=True, default=default)
|
| 227 |
+
def cli(f):
|
| 228 |
+
return f
|
| 229 |
+
|
| 230 |
+
if default:
|
| 231 |
+
expect = not expect
|
| 232 |
+
|
| 233 |
+
result = runner.invoke(cli, args, standalone_mode=False)
|
| 234 |
+
assert result.return_value is expect
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
@pytest.mark.parametrize(
|
| 238 |
+
("value", "expect"),
|
| 239 |
+
chain(
|
| 240 |
+
((x, "True") for x in ("1", "true", "t", "yes", "y", "on")),
|
| 241 |
+
((x, "False") for x in ("0", "false", "f", "no", "n", "off")),
|
| 242 |
+
),
|
| 243 |
+
)
|
| 244 |
+
def test_boolean_conversion(runner, value, expect):
|
| 245 |
+
@click.command()
|
| 246 |
+
@click.option("--flag", type=bool)
|
| 247 |
+
def cli(flag):
|
| 248 |
+
click.echo(flag, nl=False)
|
| 249 |
+
|
| 250 |
+
result = runner.invoke(cli, ["--flag", value])
|
| 251 |
+
assert result.output == expect
|
| 252 |
+
|
| 253 |
+
result = runner.invoke(cli, ["--flag", value.title()])
|
| 254 |
+
assert result.output == expect
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
def test_file_option(runner):
|
| 258 |
+
@click.command()
|
| 259 |
+
@click.option("--file", type=click.File("w"))
|
| 260 |
+
def input(file):
|
| 261 |
+
file.write("Hello World!\n")
|
| 262 |
+
|
| 263 |
+
@click.command()
|
| 264 |
+
@click.option("--file", type=click.File("r"))
|
| 265 |
+
def output(file):
|
| 266 |
+
click.echo(file.read())
|
| 267 |
+
|
| 268 |
+
with runner.isolated_filesystem():
|
| 269 |
+
result_in = runner.invoke(input, ["--file=example.txt"])
|
| 270 |
+
result_out = runner.invoke(output, ["--file=example.txt"])
|
| 271 |
+
|
| 272 |
+
assert not result_in.exception
|
| 273 |
+
assert result_in.output == ""
|
| 274 |
+
assert not result_out.exception
|
| 275 |
+
assert result_out.output == "Hello World!\n\n"
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
def test_file_lazy_mode(runner):
|
| 279 |
+
do_io = False
|
| 280 |
+
|
| 281 |
+
@click.command()
|
| 282 |
+
@click.option("--file", type=click.File("w"))
|
| 283 |
+
def input(file):
|
| 284 |
+
if do_io:
|
| 285 |
+
file.write("Hello World!\n")
|
| 286 |
+
|
| 287 |
+
@click.command()
|
| 288 |
+
@click.option("--file", type=click.File("r"))
|
| 289 |
+
def output(file):
|
| 290 |
+
pass
|
| 291 |
+
|
| 292 |
+
with runner.isolated_filesystem():
|
| 293 |
+
os.mkdir("example.txt")
|
| 294 |
+
|
| 295 |
+
do_io = True
|
| 296 |
+
result_in = runner.invoke(input, ["--file=example.txt"])
|
| 297 |
+
assert result_in.exit_code == 1
|
| 298 |
+
|
| 299 |
+
do_io = False
|
| 300 |
+
result_in = runner.invoke(input, ["--file=example.txt"])
|
| 301 |
+
assert result_in.exit_code == 0
|
| 302 |
+
|
| 303 |
+
result_out = runner.invoke(output, ["--file=example.txt"])
|
| 304 |
+
assert result_out.exception
|
| 305 |
+
|
| 306 |
+
@click.command()
|
| 307 |
+
@click.option("--file", type=click.File("w", lazy=False))
|
| 308 |
+
def input_non_lazy(file):
|
| 309 |
+
file.write("Hello World!\n")
|
| 310 |
+
|
| 311 |
+
with runner.isolated_filesystem():
|
| 312 |
+
os.mkdir("example.txt")
|
| 313 |
+
result_in = runner.invoke(input_non_lazy, ["--file=example.txt"])
|
| 314 |
+
assert result_in.exit_code == 2
|
| 315 |
+
assert "Invalid value for '--file': 'example.txt'" in result_in.output
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
def test_path_option(runner):
|
| 319 |
+
@click.command()
|
| 320 |
+
@click.option("-O", type=click.Path(file_okay=False, exists=True, writable=True))
|
| 321 |
+
def write_to_dir(o):
|
| 322 |
+
with open(os.path.join(o, "foo.txt"), "wb") as f:
|
| 323 |
+
f.write(b"meh\n")
|
| 324 |
+
|
| 325 |
+
with runner.isolated_filesystem():
|
| 326 |
+
os.mkdir("test")
|
| 327 |
+
|
| 328 |
+
result = runner.invoke(write_to_dir, ["-O", "test"])
|
| 329 |
+
assert not result.exception
|
| 330 |
+
|
| 331 |
+
with open("test/foo.txt", "rb") as f:
|
| 332 |
+
assert f.read() == b"meh\n"
|
| 333 |
+
|
| 334 |
+
result = runner.invoke(write_to_dir, ["-O", "test/foo.txt"])
|
| 335 |
+
assert "is a file" in result.output
|
| 336 |
+
|
| 337 |
+
@click.command()
|
| 338 |
+
@click.option("-f", type=click.Path(exists=True))
|
| 339 |
+
def showtype(f):
|
| 340 |
+
click.echo(f"is_file={os.path.isfile(f)}")
|
| 341 |
+
click.echo(f"is_dir={os.path.isdir(f)}")
|
| 342 |
+
|
| 343 |
+
with runner.isolated_filesystem():
|
| 344 |
+
result = runner.invoke(showtype, ["-f", "xxx"])
|
| 345 |
+
assert "does not exist" in result.output
|
| 346 |
+
|
| 347 |
+
result = runner.invoke(showtype, ["-f", "."])
|
| 348 |
+
assert "is_file=False" in result.output
|
| 349 |
+
assert "is_dir=True" in result.output
|
| 350 |
+
|
| 351 |
+
@click.command()
|
| 352 |
+
@click.option("-f", type=click.Path())
|
| 353 |
+
def exists(f):
|
| 354 |
+
click.echo(f"exists={os.path.exists(f)}")
|
| 355 |
+
|
| 356 |
+
with runner.isolated_filesystem():
|
| 357 |
+
result = runner.invoke(exists, ["-f", "xxx"])
|
| 358 |
+
assert "exists=False" in result.output
|
| 359 |
+
|
| 360 |
+
result = runner.invoke(exists, ["-f", "."])
|
| 361 |
+
assert "exists=True" in result.output
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
def test_choice_option(runner):
|
| 365 |
+
@click.command()
|
| 366 |
+
@click.option("--method", type=click.Choice(["foo", "bar", "baz"]))
|
| 367 |
+
def cli(method):
|
| 368 |
+
click.echo(method)
|
| 369 |
+
|
| 370 |
+
result = runner.invoke(cli, ["--method=foo"])
|
| 371 |
+
assert not result.exception
|
| 372 |
+
assert result.output == "foo\n"
|
| 373 |
+
|
| 374 |
+
result = runner.invoke(cli, ["--method=meh"])
|
| 375 |
+
assert result.exit_code == 2
|
| 376 |
+
assert (
|
| 377 |
+
"Invalid value for '--method': 'meh' is not one of 'foo', 'bar', 'baz'."
|
| 378 |
+
in result.output
|
| 379 |
+
)
|
| 380 |
+
|
| 381 |
+
result = runner.invoke(cli, ["--help"])
|
| 382 |
+
assert "--method [foo|bar|baz]" in result.output
|
| 383 |
+
|
| 384 |
+
|
| 385 |
+
def test_choice_argument(runner):
|
| 386 |
+
@click.command()
|
| 387 |
+
@click.argument("method", type=click.Choice(["foo", "bar", "baz"]))
|
| 388 |
+
def cli(method):
|
| 389 |
+
click.echo(method)
|
| 390 |
+
|
| 391 |
+
result = runner.invoke(cli, ["foo"])
|
| 392 |
+
assert not result.exception
|
| 393 |
+
assert result.output == "foo\n"
|
| 394 |
+
|
| 395 |
+
result = runner.invoke(cli, ["meh"])
|
| 396 |
+
assert result.exit_code == 2
|
| 397 |
+
assert (
|
| 398 |
+
"Invalid value for '{foo|bar|baz}': 'meh' is not one of 'foo',"
|
| 399 |
+
" 'bar', 'baz'." in result.output
|
| 400 |
+
)
|
| 401 |
+
|
| 402 |
+
result = runner.invoke(cli, ["--help"])
|
| 403 |
+
assert "{foo|bar|baz}" in result.output
|
| 404 |
+
|
| 405 |
+
|
| 406 |
+
def test_datetime_option_default(runner):
|
| 407 |
+
@click.command()
|
| 408 |
+
@click.option("--start_date", type=click.DateTime())
|
| 409 |
+
def cli(start_date):
|
| 410 |
+
click.echo(start_date.strftime("%Y-%m-%dT%H:%M:%S"))
|
| 411 |
+
|
| 412 |
+
result = runner.invoke(cli, ["--start_date=2015-09-29"])
|
| 413 |
+
assert not result.exception
|
| 414 |
+
assert result.output == "2015-09-29T00:00:00\n"
|
| 415 |
+
|
| 416 |
+
result = runner.invoke(cli, ["--start_date=2015-09-29T09:11:22"])
|
| 417 |
+
assert not result.exception
|
| 418 |
+
assert result.output == "2015-09-29T09:11:22\n"
|
| 419 |
+
|
| 420 |
+
result = runner.invoke(cli, ["--start_date=2015-09"])
|
| 421 |
+
assert result.exit_code == 2
|
| 422 |
+
assert (
|
| 423 |
+
"Invalid value for '--start_date': '2015-09' does not match the formats"
|
| 424 |
+
" '%Y-%m-%d', '%Y-%m-%dT%H:%M:%S', '%Y-%m-%d %H:%M:%S'."
|
| 425 |
+
) in result.output
|
| 426 |
+
|
| 427 |
+
result = runner.invoke(cli, ["--help"])
|
| 428 |
+
assert (
|
| 429 |
+
"--start_date [%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]" in result.output
|
| 430 |
+
)
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
def test_datetime_option_custom(runner):
|
| 434 |
+
@click.command()
|
| 435 |
+
@click.option("--start_date", type=click.DateTime(formats=["%A %B %d, %Y"]))
|
| 436 |
+
def cli(start_date):
|
| 437 |
+
click.echo(start_date.strftime("%Y-%m-%dT%H:%M:%S"))
|
| 438 |
+
|
| 439 |
+
result = runner.invoke(cli, ["--start_date=Wednesday June 05, 2010"])
|
| 440 |
+
assert not result.exception
|
| 441 |
+
assert result.output == "2010-06-05T00:00:00\n"
|
| 442 |
+
|
| 443 |
+
|
| 444 |
+
def test_required_option(runner):
|
| 445 |
+
@click.command()
|
| 446 |
+
@click.option("--foo", required=True)
|
| 447 |
+
def cli(foo):
|
| 448 |
+
click.echo(foo)
|
| 449 |
+
|
| 450 |
+
result = runner.invoke(cli, [])
|
| 451 |
+
assert result.exit_code == 2
|
| 452 |
+
assert "Missing option '--foo'" in result.output
|
| 453 |
+
|
| 454 |
+
|
| 455 |
+
def test_evaluation_order(runner):
|
| 456 |
+
called = []
|
| 457 |
+
|
| 458 |
+
def memo(ctx, param, value):
|
| 459 |
+
called.append(value)
|
| 460 |
+
return value
|
| 461 |
+
|
| 462 |
+
@click.command()
|
| 463 |
+
@click.option("--missing", default="missing", is_eager=False, callback=memo)
|
| 464 |
+
@click.option("--eager-flag1", flag_value="eager1", is_eager=True, callback=memo)
|
| 465 |
+
@click.option("--eager-flag2", flag_value="eager2", is_eager=True, callback=memo)
|
| 466 |
+
@click.option("--eager-flag3", flag_value="eager3", is_eager=True, callback=memo)
|
| 467 |
+
@click.option("--normal-flag1", flag_value="normal1", is_eager=False, callback=memo)
|
| 468 |
+
@click.option("--normal-flag2", flag_value="normal2", is_eager=False, callback=memo)
|
| 469 |
+
@click.option("--normal-flag3", flag_value="normal3", is_eager=False, callback=memo)
|
| 470 |
+
def cli(**x):
|
| 471 |
+
pass
|
| 472 |
+
|
| 473 |
+
result = runner.invoke(
|
| 474 |
+
cli,
|
| 475 |
+
[
|
| 476 |
+
"--eager-flag2",
|
| 477 |
+
"--eager-flag1",
|
| 478 |
+
"--normal-flag2",
|
| 479 |
+
"--eager-flag3",
|
| 480 |
+
"--normal-flag3",
|
| 481 |
+
"--normal-flag3",
|
| 482 |
+
"--normal-flag1",
|
| 483 |
+
"--normal-flag1",
|
| 484 |
+
],
|
| 485 |
+
)
|
| 486 |
+
assert not result.exception
|
| 487 |
+
assert called == [
|
| 488 |
+
"eager2",
|
| 489 |
+
"eager1",
|
| 490 |
+
"eager3",
|
| 491 |
+
"normal2",
|
| 492 |
+
"normal3",
|
| 493 |
+
"normal1",
|
| 494 |
+
"missing",
|
| 495 |
+
]
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
def test_hidden_option(runner):
|
| 499 |
+
@click.command()
|
| 500 |
+
@click.option("--nope", hidden=True)
|
| 501 |
+
def cli(nope):
|
| 502 |
+
click.echo(nope)
|
| 503 |
+
|
| 504 |
+
result = runner.invoke(cli, ["--help"])
|
| 505 |
+
assert result.exit_code == 0
|
| 506 |
+
assert "--nope" not in result.output
|
| 507 |
+
|
| 508 |
+
|
| 509 |
+
def test_hidden_command(runner):
|
| 510 |
+
@click.group()
|
| 511 |
+
def cli():
|
| 512 |
+
pass
|
| 513 |
+
|
| 514 |
+
@cli.command(hidden=True)
|
| 515 |
+
def nope():
|
| 516 |
+
pass
|
| 517 |
+
|
| 518 |
+
result = runner.invoke(cli, ["--help"])
|
| 519 |
+
assert result.exit_code == 0
|
| 520 |
+
assert "nope" not in result.output
|
| 521 |
+
|
| 522 |
+
|
| 523 |
+
def test_hidden_group(runner):
|
| 524 |
+
@click.group()
|
| 525 |
+
def cli():
|
| 526 |
+
pass
|
| 527 |
+
|
| 528 |
+
@cli.group(hidden=True)
|
| 529 |
+
def subgroup():
|
| 530 |
+
pass
|
| 531 |
+
|
| 532 |
+
@subgroup.command()
|
| 533 |
+
def nope():
|
| 534 |
+
pass
|
| 535 |
+
|
| 536 |
+
result = runner.invoke(cli, ["--help"])
|
| 537 |
+
assert result.exit_code == 0
|
| 538 |
+
assert "subgroup" not in result.output
|
| 539 |
+
assert "nope" not in result.output
|
| 540 |
+
|
| 541 |
+
|
| 542 |
+
def test_summary_line(runner):
|
| 543 |
+
@click.group()
|
| 544 |
+
def cli():
|
| 545 |
+
pass
|
| 546 |
+
|
| 547 |
+
@cli.command()
|
| 548 |
+
def cmd():
|
| 549 |
+
"""
|
| 550 |
+
Summary line without period
|
| 551 |
+
|
| 552 |
+
Here is a sentence. And here too.
|
| 553 |
+
"""
|
| 554 |
+
pass
|
| 555 |
+
|
| 556 |
+
result = runner.invoke(cli, ["--help"])
|
| 557 |
+
assert "Summary line without period" in result.output
|
| 558 |
+
assert "Here is a sentence." not in result.output
|
| 559 |
+
|
| 560 |
+
|
| 561 |
+
def test_help_invalid_default(runner):
|
| 562 |
+
cli = click.Command(
|
| 563 |
+
"cli",
|
| 564 |
+
params=[
|
| 565 |
+
click.Option(
|
| 566 |
+
["-a"],
|
| 567 |
+
type=click.Path(exists=True),
|
| 568 |
+
default="not found",
|
| 569 |
+
show_default=True,
|
| 570 |
+
),
|
| 571 |
+
],
|
| 572 |
+
)
|
| 573 |
+
result = runner.invoke(cli, ["--help"])
|
| 574 |
+
assert result.exit_code == 0
|
| 575 |
+
assert "default: not found" in result.output
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_chain.py
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
f"{sys._getframe(1).f_code.co_name}"
|
| 11 |
+
f"={'|'.join(click.get_current_context().args)}"
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def test_basic_chaining(runner):
|
| 16 |
+
@click.group(chain=True)
|
| 17 |
+
def cli():
|
| 18 |
+
pass
|
| 19 |
+
|
| 20 |
+
@cli.command("sdist")
|
| 21 |
+
def sdist():
|
| 22 |
+
click.echo("sdist called")
|
| 23 |
+
|
| 24 |
+
@cli.command("bdist")
|
| 25 |
+
def bdist():
|
| 26 |
+
click.echo("bdist called")
|
| 27 |
+
|
| 28 |
+
result = runner.invoke(cli, ["bdist", "sdist", "bdist"])
|
| 29 |
+
assert not result.exception
|
| 30 |
+
assert result.output.splitlines() == [
|
| 31 |
+
"bdist called",
|
| 32 |
+
"sdist called",
|
| 33 |
+
"bdist called",
|
| 34 |
+
]
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
@pytest.mark.parametrize(
|
| 38 |
+
("args", "expect"),
|
| 39 |
+
[
|
| 40 |
+
(["--help"], "COMMAND1 [ARGS]... [COMMAND2 [ARGS]...]..."),
|
| 41 |
+
(["--help"], "ROOT HELP"),
|
| 42 |
+
(["sdist", "--help"], "SDIST HELP"),
|
| 43 |
+
(["bdist", "--help"], "BDIST HELP"),
|
| 44 |
+
(["bdist", "sdist", "--help"], "SDIST HELP"),
|
| 45 |
+
],
|
| 46 |
+
)
|
| 47 |
+
def test_chaining_help(runner, args, expect):
|
| 48 |
+
@click.group(chain=True)
|
| 49 |
+
def cli():
|
| 50 |
+
"""ROOT HELP"""
|
| 51 |
+
pass
|
| 52 |
+
|
| 53 |
+
@cli.command("sdist")
|
| 54 |
+
def sdist():
|
| 55 |
+
"""SDIST HELP"""
|
| 56 |
+
click.echo("sdist called")
|
| 57 |
+
|
| 58 |
+
@cli.command("bdist")
|
| 59 |
+
def bdist():
|
| 60 |
+
"""BDIST HELP"""
|
| 61 |
+
click.echo("bdist called")
|
| 62 |
+
|
| 63 |
+
result = runner.invoke(cli, args)
|
| 64 |
+
assert not result.exception
|
| 65 |
+
assert expect in result.output
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def test_chaining_with_options(runner):
|
| 69 |
+
@click.group(chain=True)
|
| 70 |
+
def cli():
|
| 71 |
+
pass
|
| 72 |
+
|
| 73 |
+
@cli.command("sdist")
|
| 74 |
+
@click.option("--format")
|
| 75 |
+
def sdist(format):
|
| 76 |
+
click.echo(f"sdist called {format}")
|
| 77 |
+
|
| 78 |
+
@cli.command("bdist")
|
| 79 |
+
@click.option("--format")
|
| 80 |
+
def bdist(format):
|
| 81 |
+
click.echo(f"bdist called {format}")
|
| 82 |
+
|
| 83 |
+
result = runner.invoke(cli, ["bdist", "--format=1", "sdist", "--format=2"])
|
| 84 |
+
assert not result.exception
|
| 85 |
+
assert result.output.splitlines() == ["bdist called 1", "sdist called 2"]
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
@pytest.mark.parametrize(("chain", "expect"), [(False, "1"), (True, "[]")])
|
| 89 |
+
def test_no_command_result_callback(runner, chain, expect):
|
| 90 |
+
"""When a group has ``invoke_without_command=True``, the result
|
| 91 |
+
callback is always invoked. A regular group invokes it with
|
| 92 |
+
its return value, a chained group with ``[]``.
|
| 93 |
+
"""
|
| 94 |
+
|
| 95 |
+
@click.group(invoke_without_command=True, chain=chain)
|
| 96 |
+
def cli():
|
| 97 |
+
return 1
|
| 98 |
+
|
| 99 |
+
@cli.result_callback()
|
| 100 |
+
def process_result(result):
|
| 101 |
+
click.echo(result, nl=False)
|
| 102 |
+
|
| 103 |
+
result = runner.invoke(cli, [])
|
| 104 |
+
assert result.output == expect
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def test_chaining_with_arguments(runner):
|
| 108 |
+
@click.group(chain=True)
|
| 109 |
+
def cli():
|
| 110 |
+
pass
|
| 111 |
+
|
| 112 |
+
@cli.command("sdist")
|
| 113 |
+
@click.argument("format")
|
| 114 |
+
def sdist(format):
|
| 115 |
+
click.echo(f"sdist called {format}")
|
| 116 |
+
|
| 117 |
+
@cli.command("bdist")
|
| 118 |
+
@click.argument("format")
|
| 119 |
+
def bdist(format):
|
| 120 |
+
click.echo(f"bdist called {format}")
|
| 121 |
+
|
| 122 |
+
result = runner.invoke(cli, ["bdist", "1", "sdist", "2"])
|
| 123 |
+
assert not result.exception
|
| 124 |
+
assert result.output.splitlines() == ["bdist called 1", "sdist called 2"]
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
@pytest.mark.parametrize(
|
| 128 |
+
("args", "input", "expect"),
|
| 129 |
+
[
|
| 130 |
+
(["-f", "-"], "foo\nbar", ["foo", "bar"]),
|
| 131 |
+
(["-f", "-", "strip"], "foo \n bar", ["foo", "bar"]),
|
| 132 |
+
(["-f", "-", "strip", "uppercase"], "foo \n bar", ["FOO", "BAR"]),
|
| 133 |
+
],
|
| 134 |
+
)
|
| 135 |
+
def test_pipeline(runner, args, input, expect):
|
| 136 |
+
@click.group(chain=True, invoke_without_command=True)
|
| 137 |
+
@click.option("-f", type=click.File("r"))
|
| 138 |
+
def cli(f):
|
| 139 |
+
pass
|
| 140 |
+
|
| 141 |
+
@cli.result_callback()
|
| 142 |
+
def process_pipeline(processors, f):
|
| 143 |
+
iterator = (x.rstrip("\r\n") for x in f)
|
| 144 |
+
for processor in processors:
|
| 145 |
+
iterator = processor(iterator)
|
| 146 |
+
for item in iterator:
|
| 147 |
+
click.echo(item)
|
| 148 |
+
|
| 149 |
+
@cli.command("uppercase")
|
| 150 |
+
def make_uppercase():
|
| 151 |
+
def processor(iterator):
|
| 152 |
+
for line in iterator:
|
| 153 |
+
yield line.upper()
|
| 154 |
+
|
| 155 |
+
return processor
|
| 156 |
+
|
| 157 |
+
@cli.command("strip")
|
| 158 |
+
def make_strip():
|
| 159 |
+
def processor(iterator):
|
| 160 |
+
for line in iterator:
|
| 161 |
+
yield line.strip()
|
| 162 |
+
|
| 163 |
+
return processor
|
| 164 |
+
|
| 165 |
+
result = runner.invoke(cli, args, input=input)
|
| 166 |
+
assert not result.exception
|
| 167 |
+
assert result.output.splitlines() == expect
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def test_args_and_chain(runner):
|
| 171 |
+
@click.group(chain=True)
|
| 172 |
+
def cli():
|
| 173 |
+
debug()
|
| 174 |
+
|
| 175 |
+
@cli.command()
|
| 176 |
+
def a():
|
| 177 |
+
debug()
|
| 178 |
+
|
| 179 |
+
@cli.command()
|
| 180 |
+
def b():
|
| 181 |
+
debug()
|
| 182 |
+
|
| 183 |
+
@cli.command()
|
| 184 |
+
def c():
|
| 185 |
+
debug()
|
| 186 |
+
|
| 187 |
+
result = runner.invoke(cli, ["a", "b", "c"])
|
| 188 |
+
assert not result.exception
|
| 189 |
+
assert result.output.splitlines() == ["cli=", "a=", "b=", "c="]
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
def test_group_arg_behavior(runner):
|
| 193 |
+
with pytest.raises(RuntimeError):
|
| 194 |
+
|
| 195 |
+
@click.group(chain=True)
|
| 196 |
+
@click.argument("forbidden", required=False)
|
| 197 |
+
def bad_cli():
|
| 198 |
+
pass
|
| 199 |
+
|
| 200 |
+
with pytest.raises(RuntimeError):
|
| 201 |
+
|
| 202 |
+
@click.group(chain=True)
|
| 203 |
+
@click.argument("forbidden", nargs=-1)
|
| 204 |
+
def bad_cli2():
|
| 205 |
+
pass
|
| 206 |
+
|
| 207 |
+
@click.group(chain=True)
|
| 208 |
+
@click.argument("arg")
|
| 209 |
+
def cli(arg):
|
| 210 |
+
click.echo(f"cli:{arg}")
|
| 211 |
+
|
| 212 |
+
@cli.command()
|
| 213 |
+
def a():
|
| 214 |
+
click.echo("a")
|
| 215 |
+
|
| 216 |
+
result = runner.invoke(cli, ["foo", "a"])
|
| 217 |
+
assert not result.exception
|
| 218 |
+
assert result.output.splitlines() == ["cli:foo", "a"]
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
@pytest.mark.xfail
|
| 222 |
+
def test_group_chaining(runner):
|
| 223 |
+
@click.group(chain=True)
|
| 224 |
+
def cli():
|
| 225 |
+
debug()
|
| 226 |
+
|
| 227 |
+
@cli.group()
|
| 228 |
+
def l1a():
|
| 229 |
+
debug()
|
| 230 |
+
|
| 231 |
+
@l1a.command()
|
| 232 |
+
def l2a():
|
| 233 |
+
debug()
|
| 234 |
+
|
| 235 |
+
@l1a.command()
|
| 236 |
+
def l2b():
|
| 237 |
+
debug()
|
| 238 |
+
|
| 239 |
+
@cli.command()
|
| 240 |
+
def l1b():
|
| 241 |
+
debug()
|
| 242 |
+
|
| 243 |
+
result = runner.invoke(cli, ["l1a", "l2a", "l1b"])
|
| 244 |
+
assert not result.exception
|
| 245 |
+
assert result.output.splitlines() == ["cli=", "l1a=", "l2a=", "l1b="]
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_command_decorators.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
|
| 3 |
+
import click
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def test_command_no_parens(runner):
|
| 7 |
+
@click.command
|
| 8 |
+
def cli():
|
| 9 |
+
click.echo("hello")
|
| 10 |
+
|
| 11 |
+
result = runner.invoke(cli)
|
| 12 |
+
assert result.exception is None
|
| 13 |
+
assert result.output == "hello\n"
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def test_custom_command_no_parens(runner):
|
| 17 |
+
class CustomCommand(click.Command):
|
| 18 |
+
pass
|
| 19 |
+
|
| 20 |
+
class CustomGroup(click.Group):
|
| 21 |
+
command_class = CustomCommand
|
| 22 |
+
|
| 23 |
+
@click.group(cls=CustomGroup)
|
| 24 |
+
def grp():
|
| 25 |
+
pass
|
| 26 |
+
|
| 27 |
+
@grp.command
|
| 28 |
+
def cli():
|
| 29 |
+
click.echo("hello custom command class")
|
| 30 |
+
|
| 31 |
+
result = runner.invoke(cli)
|
| 32 |
+
assert result.exception is None
|
| 33 |
+
assert result.output == "hello custom command class\n"
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def test_group_no_parens(runner):
|
| 37 |
+
@click.group
|
| 38 |
+
def grp():
|
| 39 |
+
click.echo("grp1")
|
| 40 |
+
|
| 41 |
+
@grp.command
|
| 42 |
+
def cmd1():
|
| 43 |
+
click.echo("cmd1")
|
| 44 |
+
|
| 45 |
+
@grp.group
|
| 46 |
+
def grp2():
|
| 47 |
+
click.echo("grp2")
|
| 48 |
+
|
| 49 |
+
@grp2.command
|
| 50 |
+
def cmd2():
|
| 51 |
+
click.echo("cmd2")
|
| 52 |
+
|
| 53 |
+
result = runner.invoke(grp, ["cmd1"])
|
| 54 |
+
assert result.exception is None
|
| 55 |
+
assert result.output == "grp1\ncmd1\n"
|
| 56 |
+
|
| 57 |
+
result = runner.invoke(grp, ["grp2", "cmd2"])
|
| 58 |
+
assert result.exception is None
|
| 59 |
+
assert result.output == "grp1\ngrp2\ncmd2\n"
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def test_params_argument(runner):
|
| 63 |
+
opt = click.Argument(["a"])
|
| 64 |
+
|
| 65 |
+
@click.command(params=[opt])
|
| 66 |
+
@click.argument("b")
|
| 67 |
+
def cli(a, b):
|
| 68 |
+
click.echo(f"{a} {b}")
|
| 69 |
+
|
| 70 |
+
assert cli.params[0].name == "a"
|
| 71 |
+
assert cli.params[1].name == "b"
|
| 72 |
+
result = runner.invoke(cli, ["1", "2"])
|
| 73 |
+
assert result.output == "1 2\n"
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
@pytest.mark.parametrize(
|
| 77 |
+
"name",
|
| 78 |
+
[
|
| 79 |
+
"init_data",
|
| 80 |
+
"init_data_command",
|
| 81 |
+
"init_data_cmd",
|
| 82 |
+
"init_data_group",
|
| 83 |
+
"init_data_grp",
|
| 84 |
+
],
|
| 85 |
+
)
|
| 86 |
+
def test_generate_name(name: str) -> None:
|
| 87 |
+
def f():
|
| 88 |
+
pass
|
| 89 |
+
|
| 90 |
+
f.__name__ = name
|
| 91 |
+
f = click.command(f)
|
| 92 |
+
assert f.name == "init-data"
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_commands.py
ADDED
|
@@ -0,0 +1,407 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
|
| 3 |
+
import pytest
|
| 4 |
+
|
| 5 |
+
import click
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def test_other_command_invoke(runner):
|
| 9 |
+
@click.command()
|
| 10 |
+
@click.pass_context
|
| 11 |
+
def cli(ctx):
|
| 12 |
+
return ctx.invoke(other_cmd, arg=42)
|
| 13 |
+
|
| 14 |
+
@click.command()
|
| 15 |
+
@click.argument("arg", type=click.INT)
|
| 16 |
+
def other_cmd(arg):
|
| 17 |
+
click.echo(arg)
|
| 18 |
+
|
| 19 |
+
result = runner.invoke(cli, [])
|
| 20 |
+
assert not result.exception
|
| 21 |
+
assert result.output == "42\n"
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def test_other_command_forward(runner):
|
| 25 |
+
cli = click.Group()
|
| 26 |
+
|
| 27 |
+
@cli.command()
|
| 28 |
+
@click.option("--count", default=1)
|
| 29 |
+
def test(count):
|
| 30 |
+
click.echo(f"Count: {count:d}")
|
| 31 |
+
|
| 32 |
+
@cli.command()
|
| 33 |
+
@click.option("--count", default=1)
|
| 34 |
+
@click.pass_context
|
| 35 |
+
def dist(ctx, count):
|
| 36 |
+
ctx.forward(test)
|
| 37 |
+
ctx.invoke(test, count=42)
|
| 38 |
+
|
| 39 |
+
result = runner.invoke(cli, ["dist"])
|
| 40 |
+
assert not result.exception
|
| 41 |
+
assert result.output == "Count: 1\nCount: 42\n"
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def test_forwarded_params_consistency(runner):
|
| 45 |
+
cli = click.Group()
|
| 46 |
+
|
| 47 |
+
@cli.command()
|
| 48 |
+
@click.option("-a")
|
| 49 |
+
@click.pass_context
|
| 50 |
+
def first(ctx, **kwargs):
|
| 51 |
+
click.echo(f"{ctx.params}")
|
| 52 |
+
|
| 53 |
+
@cli.command()
|
| 54 |
+
@click.option("-a")
|
| 55 |
+
@click.option("-b")
|
| 56 |
+
@click.pass_context
|
| 57 |
+
def second(ctx, **kwargs):
|
| 58 |
+
click.echo(f"{ctx.params}")
|
| 59 |
+
ctx.forward(first)
|
| 60 |
+
|
| 61 |
+
result = runner.invoke(cli, ["second", "-a", "foo", "-b", "bar"])
|
| 62 |
+
assert not result.exception
|
| 63 |
+
assert result.output == "{'a': 'foo', 'b': 'bar'}\n{'a': 'foo', 'b': 'bar'}\n"
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def test_auto_shorthelp(runner):
|
| 67 |
+
@click.group()
|
| 68 |
+
def cli():
|
| 69 |
+
pass
|
| 70 |
+
|
| 71 |
+
@cli.command()
|
| 72 |
+
def short():
|
| 73 |
+
"""This is a short text."""
|
| 74 |
+
|
| 75 |
+
@cli.command()
|
| 76 |
+
def special_chars():
|
| 77 |
+
"""Login and store the token in ~/.netrc."""
|
| 78 |
+
|
| 79 |
+
@cli.command()
|
| 80 |
+
def long():
|
| 81 |
+
"""This is a long text that is too long to show as short help
|
| 82 |
+
and will be truncated instead."""
|
| 83 |
+
|
| 84 |
+
result = runner.invoke(cli, ["--help"])
|
| 85 |
+
assert (
|
| 86 |
+
re.search(
|
| 87 |
+
r"Commands:\n\s+"
|
| 88 |
+
r"long\s+This is a long text that is too long to show as short help"
|
| 89 |
+
r"\.\.\.\n\s+"
|
| 90 |
+
r"short\s+This is a short text\.\n\s+"
|
| 91 |
+
r"special-chars\s+Login and store the token in ~/.netrc\.\s*",
|
| 92 |
+
result.output,
|
| 93 |
+
)
|
| 94 |
+
is not None
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def test_command_no_args_is_help(runner):
|
| 99 |
+
result = runner.invoke(click.Command("test", no_args_is_help=True))
|
| 100 |
+
assert result.exit_code == 2
|
| 101 |
+
assert "Show this message and exit." in result.output
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def test_default_maps(runner):
|
| 105 |
+
@click.group()
|
| 106 |
+
def cli():
|
| 107 |
+
pass
|
| 108 |
+
|
| 109 |
+
@cli.command()
|
| 110 |
+
@click.option("--name", default="normal")
|
| 111 |
+
def foo(name):
|
| 112 |
+
click.echo(name)
|
| 113 |
+
|
| 114 |
+
result = runner.invoke(cli, ["foo"], default_map={"foo": {"name": "changed"}})
|
| 115 |
+
|
| 116 |
+
assert not result.exception
|
| 117 |
+
assert result.output == "changed\n"
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
@pytest.mark.parametrize(
|
| 121 |
+
("args", "exit_code", "expect"),
|
| 122 |
+
[
|
| 123 |
+
(["obj1"], 2, "Error: Missing command."),
|
| 124 |
+
(["obj1", "--help"], 0, "Show this message and exit."),
|
| 125 |
+
(["obj1", "move"], 0, "obj=obj1\nmove\n"),
|
| 126 |
+
([], 2, "Show this message and exit."),
|
| 127 |
+
],
|
| 128 |
+
)
|
| 129 |
+
def test_group_with_args(runner, args, exit_code, expect):
|
| 130 |
+
@click.group()
|
| 131 |
+
@click.argument("obj")
|
| 132 |
+
def cli(obj):
|
| 133 |
+
click.echo(f"obj={obj}")
|
| 134 |
+
|
| 135 |
+
@cli.command()
|
| 136 |
+
def move():
|
| 137 |
+
click.echo("move")
|
| 138 |
+
|
| 139 |
+
result = runner.invoke(cli, args)
|
| 140 |
+
assert result.exit_code == exit_code
|
| 141 |
+
assert expect in result.output
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def test_custom_parser(runner):
|
| 145 |
+
import optparse
|
| 146 |
+
|
| 147 |
+
@click.group()
|
| 148 |
+
def cli():
|
| 149 |
+
pass
|
| 150 |
+
|
| 151 |
+
class OptParseCommand(click.Command):
|
| 152 |
+
def __init__(self, name, parser, callback):
|
| 153 |
+
super().__init__(name)
|
| 154 |
+
self.parser = parser
|
| 155 |
+
self.callback = callback
|
| 156 |
+
|
| 157 |
+
def parse_args(self, ctx, args):
|
| 158 |
+
try:
|
| 159 |
+
opts, args = parser.parse_args(args)
|
| 160 |
+
except Exception as e:
|
| 161 |
+
ctx.fail(str(e))
|
| 162 |
+
ctx.args = args
|
| 163 |
+
ctx.params = vars(opts)
|
| 164 |
+
|
| 165 |
+
def get_usage(self, ctx):
|
| 166 |
+
return self.parser.get_usage()
|
| 167 |
+
|
| 168 |
+
def get_help(self, ctx):
|
| 169 |
+
return self.parser.format_help()
|
| 170 |
+
|
| 171 |
+
def invoke(self, ctx):
|
| 172 |
+
ctx.invoke(self.callback, ctx.args, **ctx.params)
|
| 173 |
+
|
| 174 |
+
parser = optparse.OptionParser(usage="Usage: foo test [OPTIONS]")
|
| 175 |
+
parser.add_option(
|
| 176 |
+
"-f", "--file", dest="filename", help="write report to FILE", metavar="FILE"
|
| 177 |
+
)
|
| 178 |
+
parser.add_option(
|
| 179 |
+
"-q",
|
| 180 |
+
"--quiet",
|
| 181 |
+
action="store_false",
|
| 182 |
+
dest="verbose",
|
| 183 |
+
default=True,
|
| 184 |
+
help="don't print status messages to stdout",
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
+
def test_callback(args, filename, verbose):
|
| 188 |
+
click.echo(" ".join(args))
|
| 189 |
+
click.echo(filename)
|
| 190 |
+
click.echo(verbose)
|
| 191 |
+
|
| 192 |
+
cli.add_command(OptParseCommand("test", parser, test_callback))
|
| 193 |
+
|
| 194 |
+
result = runner.invoke(cli, ["test", "-f", "f.txt", "-q", "q1.txt", "q2.txt"])
|
| 195 |
+
assert result.exception is None
|
| 196 |
+
assert result.output.splitlines() == ["q1.txt q2.txt", "f.txt", "False"]
|
| 197 |
+
|
| 198 |
+
result = runner.invoke(cli, ["test", "--help"])
|
| 199 |
+
assert result.exception is None
|
| 200 |
+
assert result.output.splitlines() == [
|
| 201 |
+
"Usage: foo test [OPTIONS]",
|
| 202 |
+
"",
|
| 203 |
+
"Options:",
|
| 204 |
+
" -h, --help show this help message and exit",
|
| 205 |
+
" -f FILE, --file=FILE write report to FILE",
|
| 206 |
+
" -q, --quiet don't print status messages to stdout",
|
| 207 |
+
]
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
def test_object_propagation(runner):
|
| 211 |
+
for chain in False, True:
|
| 212 |
+
|
| 213 |
+
@click.group(chain=chain)
|
| 214 |
+
@click.option("--debug/--no-debug", default=False)
|
| 215 |
+
@click.pass_context
|
| 216 |
+
def cli(ctx, debug):
|
| 217 |
+
if ctx.obj is None:
|
| 218 |
+
ctx.obj = {}
|
| 219 |
+
ctx.obj["DEBUG"] = debug
|
| 220 |
+
|
| 221 |
+
@cli.command()
|
| 222 |
+
@click.pass_context
|
| 223 |
+
def sync(ctx):
|
| 224 |
+
click.echo(f"Debug is {'on' if ctx.obj['DEBUG'] else 'off'}")
|
| 225 |
+
|
| 226 |
+
result = runner.invoke(cli, ["sync"])
|
| 227 |
+
assert result.exception is None
|
| 228 |
+
assert result.output == "Debug is off\n"
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
def test_other_command_invoke_with_defaults(runner):
|
| 232 |
+
@click.command()
|
| 233 |
+
@click.pass_context
|
| 234 |
+
def cli(ctx):
|
| 235 |
+
return ctx.invoke(other_cmd)
|
| 236 |
+
|
| 237 |
+
@click.command()
|
| 238 |
+
@click.option("-a", type=click.INT, default=42)
|
| 239 |
+
@click.option("-b", type=click.INT, default="15")
|
| 240 |
+
@click.option("-c", multiple=True)
|
| 241 |
+
@click.pass_context
|
| 242 |
+
def other_cmd(ctx, a, b, c):
|
| 243 |
+
return ctx.info_name, a, b, c
|
| 244 |
+
|
| 245 |
+
result = runner.invoke(cli, standalone_mode=False)
|
| 246 |
+
# invoke should type cast default values, str becomes int, empty
|
| 247 |
+
# multiple should be empty tuple instead of None
|
| 248 |
+
assert result.return_value == ("other", 42, 15, ())
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
def test_invoked_subcommand(runner):
|
| 252 |
+
@click.group(invoke_without_command=True)
|
| 253 |
+
@click.pass_context
|
| 254 |
+
def cli(ctx):
|
| 255 |
+
if ctx.invoked_subcommand is None:
|
| 256 |
+
click.echo("no subcommand, use default")
|
| 257 |
+
ctx.invoke(sync)
|
| 258 |
+
else:
|
| 259 |
+
click.echo("invoke subcommand")
|
| 260 |
+
|
| 261 |
+
@cli.command()
|
| 262 |
+
def sync():
|
| 263 |
+
click.echo("in subcommand")
|
| 264 |
+
|
| 265 |
+
result = runner.invoke(cli, ["sync"])
|
| 266 |
+
assert not result.exception
|
| 267 |
+
assert result.output == "invoke subcommand\nin subcommand\n"
|
| 268 |
+
|
| 269 |
+
result = runner.invoke(cli)
|
| 270 |
+
assert not result.exception
|
| 271 |
+
assert result.output == "no subcommand, use default\nin subcommand\n"
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
def test_aliased_command_canonical_name(runner):
|
| 275 |
+
class AliasedGroup(click.Group):
|
| 276 |
+
def get_command(self, ctx, cmd_name):
|
| 277 |
+
return push
|
| 278 |
+
|
| 279 |
+
def resolve_command(self, ctx, args):
|
| 280 |
+
_, command, args = super().resolve_command(ctx, args)
|
| 281 |
+
return command.name, command, args
|
| 282 |
+
|
| 283 |
+
cli = AliasedGroup()
|
| 284 |
+
|
| 285 |
+
@cli.command()
|
| 286 |
+
def push():
|
| 287 |
+
click.echo("push command")
|
| 288 |
+
|
| 289 |
+
result = runner.invoke(cli, ["pu", "--help"])
|
| 290 |
+
assert not result.exception
|
| 291 |
+
assert result.output.startswith("Usage: root push [OPTIONS]")
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
def test_group_add_command_name(runner):
|
| 295 |
+
cli = click.Group("cli")
|
| 296 |
+
cmd = click.Command("a", params=[click.Option(["-x"], required=True)])
|
| 297 |
+
cli.add_command(cmd, "b")
|
| 298 |
+
# Check that the command is accessed through the registered name,
|
| 299 |
+
# not the original name.
|
| 300 |
+
result = runner.invoke(cli, ["b"], default_map={"b": {"x": 3}})
|
| 301 |
+
assert result.exit_code == 0
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
def test_unprocessed_options(runner):
|
| 305 |
+
@click.command(context_settings=dict(ignore_unknown_options=True))
|
| 306 |
+
@click.argument("args", nargs=-1, type=click.UNPROCESSED)
|
| 307 |
+
@click.option("--verbose", "-v", count=True)
|
| 308 |
+
def cli(verbose, args):
|
| 309 |
+
click.echo(f"Verbosity: {verbose}")
|
| 310 |
+
click.echo(f"Args: {'|'.join(args)}")
|
| 311 |
+
|
| 312 |
+
result = runner.invoke(cli, ["-foo", "-vvvvx", "--muhaha", "x", "y", "-x"])
|
| 313 |
+
assert not result.exception
|
| 314 |
+
assert result.output.splitlines() == [
|
| 315 |
+
"Verbosity: 4",
|
| 316 |
+
"Args: -foo|-x|--muhaha|x|y|-x",
|
| 317 |
+
]
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
@pytest.mark.parametrize("doc", ["CLI HELP", None])
|
| 321 |
+
def test_deprecated_in_help_messages(runner, doc):
|
| 322 |
+
@click.command(deprecated=True, help=doc)
|
| 323 |
+
def cli():
|
| 324 |
+
pass
|
| 325 |
+
|
| 326 |
+
result = runner.invoke(cli, ["--help"])
|
| 327 |
+
assert "(Deprecated)" in result.output
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
def test_deprecated_in_invocation(runner):
|
| 331 |
+
@click.command(deprecated=True)
|
| 332 |
+
def deprecated_cmd():
|
| 333 |
+
pass
|
| 334 |
+
|
| 335 |
+
result = runner.invoke(deprecated_cmd)
|
| 336 |
+
assert "DeprecationWarning:" in result.output
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
def test_command_parse_args_collects_option_prefixes():
|
| 340 |
+
@click.command()
|
| 341 |
+
@click.option("+p", is_flag=True)
|
| 342 |
+
@click.option("!e", is_flag=True)
|
| 343 |
+
def test(p, e):
|
| 344 |
+
pass
|
| 345 |
+
|
| 346 |
+
ctx = click.Context(test)
|
| 347 |
+
test.parse_args(ctx, [])
|
| 348 |
+
|
| 349 |
+
assert ctx._opt_prefixes == {"-", "--", "+", "!"}
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
def test_group_parse_args_collects_base_option_prefixes():
|
| 353 |
+
@click.group()
|
| 354 |
+
@click.option("~t", is_flag=True)
|
| 355 |
+
def group(t):
|
| 356 |
+
pass
|
| 357 |
+
|
| 358 |
+
@group.command()
|
| 359 |
+
@click.option("+p", is_flag=True)
|
| 360 |
+
def command1(p):
|
| 361 |
+
pass
|
| 362 |
+
|
| 363 |
+
@group.command()
|
| 364 |
+
@click.option("!e", is_flag=True)
|
| 365 |
+
def command2(e):
|
| 366 |
+
pass
|
| 367 |
+
|
| 368 |
+
ctx = click.Context(group)
|
| 369 |
+
group.parse_args(ctx, ["command1", "+p"])
|
| 370 |
+
|
| 371 |
+
assert ctx._opt_prefixes == {"-", "--", "~"}
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
def test_group_invoke_collects_used_option_prefixes(runner):
|
| 375 |
+
opt_prefixes = set()
|
| 376 |
+
|
| 377 |
+
@click.group()
|
| 378 |
+
@click.option("~t", is_flag=True)
|
| 379 |
+
def group(t):
|
| 380 |
+
pass
|
| 381 |
+
|
| 382 |
+
@group.command()
|
| 383 |
+
@click.option("+p", is_flag=True)
|
| 384 |
+
@click.pass_context
|
| 385 |
+
def command1(ctx, p):
|
| 386 |
+
nonlocal opt_prefixes
|
| 387 |
+
opt_prefixes = ctx._opt_prefixes
|
| 388 |
+
|
| 389 |
+
@group.command()
|
| 390 |
+
@click.option("!e", is_flag=True)
|
| 391 |
+
def command2(e):
|
| 392 |
+
pass
|
| 393 |
+
|
| 394 |
+
runner.invoke(group, ["command1"])
|
| 395 |
+
assert opt_prefixes == {"-", "--", "~", "+"}
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
@pytest.mark.parametrize("exc", (EOFError, KeyboardInterrupt))
|
| 399 |
+
def test_abort_exceptions_with_disabled_standalone_mode(runner, exc):
|
| 400 |
+
@click.command()
|
| 401 |
+
def cli():
|
| 402 |
+
raise exc("catch me!")
|
| 403 |
+
|
| 404 |
+
rv = runner.invoke(cli, standalone_mode=False)
|
| 405 |
+
assert rv.exit_code == 1
|
| 406 |
+
assert isinstance(rv.exception.__cause__, exc)
|
| 407 |
+
assert rv.exception.__cause__.args == ("catch me!",)
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_compat.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from click._compat import should_strip_ansi
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def test_is_jupyter_kernel_output():
|
| 5 |
+
class JupyterKernelFakeStream:
|
| 6 |
+
pass
|
| 7 |
+
|
| 8 |
+
# implementation detail, aka cheapskate test
|
| 9 |
+
JupyterKernelFakeStream.__module__ = "ipykernel.faked"
|
| 10 |
+
assert not should_strip_ansi(stream=JupyterKernelFakeStream())
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_context.py
ADDED
|
@@ -0,0 +1,545 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
from contextlib import contextmanager
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
import click
|
| 7 |
+
from click import Context
|
| 8 |
+
from click import Option
|
| 9 |
+
from click import Parameter
|
| 10 |
+
from click.core import ParameterSource
|
| 11 |
+
from click.decorators import help_option
|
| 12 |
+
from click.decorators import pass_meta_key
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def test_ensure_context_objects(runner):
|
| 16 |
+
class Foo:
|
| 17 |
+
def __init__(self):
|
| 18 |
+
self.title = "default"
|
| 19 |
+
|
| 20 |
+
pass_foo = click.make_pass_decorator(Foo, ensure=True)
|
| 21 |
+
|
| 22 |
+
@click.group()
|
| 23 |
+
@pass_foo
|
| 24 |
+
def cli(foo):
|
| 25 |
+
pass
|
| 26 |
+
|
| 27 |
+
@cli.command()
|
| 28 |
+
@pass_foo
|
| 29 |
+
def test(foo):
|
| 30 |
+
click.echo(foo.title)
|
| 31 |
+
|
| 32 |
+
result = runner.invoke(cli, ["test"])
|
| 33 |
+
assert not result.exception
|
| 34 |
+
assert result.output == "default\n"
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def test_get_context_objects(runner):
|
| 38 |
+
class Foo:
|
| 39 |
+
def __init__(self):
|
| 40 |
+
self.title = "default"
|
| 41 |
+
|
| 42 |
+
pass_foo = click.make_pass_decorator(Foo, ensure=True)
|
| 43 |
+
|
| 44 |
+
@click.group()
|
| 45 |
+
@click.pass_context
|
| 46 |
+
def cli(ctx):
|
| 47 |
+
ctx.obj = Foo()
|
| 48 |
+
ctx.obj.title = "test"
|
| 49 |
+
|
| 50 |
+
@cli.command()
|
| 51 |
+
@pass_foo
|
| 52 |
+
def test(foo):
|
| 53 |
+
click.echo(foo.title)
|
| 54 |
+
|
| 55 |
+
result = runner.invoke(cli, ["test"])
|
| 56 |
+
assert not result.exception
|
| 57 |
+
assert result.output == "test\n"
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def test_get_context_objects_no_ensuring(runner):
|
| 61 |
+
class Foo:
|
| 62 |
+
def __init__(self):
|
| 63 |
+
self.title = "default"
|
| 64 |
+
|
| 65 |
+
pass_foo = click.make_pass_decorator(Foo)
|
| 66 |
+
|
| 67 |
+
@click.group()
|
| 68 |
+
@click.pass_context
|
| 69 |
+
def cli(ctx):
|
| 70 |
+
ctx.obj = Foo()
|
| 71 |
+
ctx.obj.title = "test"
|
| 72 |
+
|
| 73 |
+
@cli.command()
|
| 74 |
+
@pass_foo
|
| 75 |
+
def test(foo):
|
| 76 |
+
click.echo(foo.title)
|
| 77 |
+
|
| 78 |
+
result = runner.invoke(cli, ["test"])
|
| 79 |
+
assert not result.exception
|
| 80 |
+
assert result.output == "test\n"
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def test_get_context_objects_missing(runner):
|
| 84 |
+
class Foo:
|
| 85 |
+
pass
|
| 86 |
+
|
| 87 |
+
pass_foo = click.make_pass_decorator(Foo)
|
| 88 |
+
|
| 89 |
+
@click.group()
|
| 90 |
+
@click.pass_context
|
| 91 |
+
def cli(ctx):
|
| 92 |
+
pass
|
| 93 |
+
|
| 94 |
+
@cli.command()
|
| 95 |
+
@pass_foo
|
| 96 |
+
def test(foo):
|
| 97 |
+
click.echo(foo.title)
|
| 98 |
+
|
| 99 |
+
result = runner.invoke(cli, ["test"])
|
| 100 |
+
assert result.exception is not None
|
| 101 |
+
assert isinstance(result.exception, RuntimeError)
|
| 102 |
+
assert (
|
| 103 |
+
"Managed to invoke callback without a context object of type"
|
| 104 |
+
" 'Foo' existing" in str(result.exception)
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def test_multi_enter(runner):
|
| 109 |
+
called = []
|
| 110 |
+
|
| 111 |
+
@click.command()
|
| 112 |
+
@click.pass_context
|
| 113 |
+
def cli(ctx):
|
| 114 |
+
def callback():
|
| 115 |
+
called.append(True)
|
| 116 |
+
|
| 117 |
+
ctx.call_on_close(callback)
|
| 118 |
+
|
| 119 |
+
with ctx:
|
| 120 |
+
pass
|
| 121 |
+
assert not called
|
| 122 |
+
|
| 123 |
+
result = runner.invoke(cli, [])
|
| 124 |
+
assert result.exception is None
|
| 125 |
+
assert called == [True]
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def test_global_context_object(runner):
|
| 129 |
+
@click.command()
|
| 130 |
+
@click.pass_context
|
| 131 |
+
def cli(ctx):
|
| 132 |
+
assert click.get_current_context() is ctx
|
| 133 |
+
ctx.obj = "FOOBAR"
|
| 134 |
+
assert click.get_current_context().obj == "FOOBAR"
|
| 135 |
+
|
| 136 |
+
assert click.get_current_context(silent=True) is None
|
| 137 |
+
runner.invoke(cli, [], catch_exceptions=False)
|
| 138 |
+
assert click.get_current_context(silent=True) is None
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def test_context_meta(runner):
|
| 142 |
+
LANG_KEY = f"{__name__}.lang"
|
| 143 |
+
|
| 144 |
+
def set_language(value):
|
| 145 |
+
click.get_current_context().meta[LANG_KEY] = value
|
| 146 |
+
|
| 147 |
+
def get_language():
|
| 148 |
+
return click.get_current_context().meta.get(LANG_KEY, "en_US")
|
| 149 |
+
|
| 150 |
+
@click.command()
|
| 151 |
+
@click.pass_context
|
| 152 |
+
def cli(ctx):
|
| 153 |
+
assert get_language() == "en_US"
|
| 154 |
+
set_language("de_DE")
|
| 155 |
+
assert get_language() == "de_DE"
|
| 156 |
+
|
| 157 |
+
runner.invoke(cli, [], catch_exceptions=False)
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def test_make_pass_meta_decorator(runner):
|
| 161 |
+
@click.group()
|
| 162 |
+
@click.pass_context
|
| 163 |
+
def cli(ctx):
|
| 164 |
+
ctx.meta["value"] = "good"
|
| 165 |
+
|
| 166 |
+
@cli.command()
|
| 167 |
+
@pass_meta_key("value")
|
| 168 |
+
def show(value):
|
| 169 |
+
return value
|
| 170 |
+
|
| 171 |
+
result = runner.invoke(cli, ["show"], standalone_mode=False)
|
| 172 |
+
assert result.return_value == "good"
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
def test_make_pass_meta_decorator_doc():
|
| 176 |
+
pass_value = pass_meta_key("value")
|
| 177 |
+
assert "the 'value' key from :attr:`click.Context.meta`" in pass_value.__doc__
|
| 178 |
+
pass_value = pass_meta_key("value", doc_description="the test value")
|
| 179 |
+
assert "passes the test value" in pass_value.__doc__
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def test_context_pushing():
|
| 183 |
+
rv = []
|
| 184 |
+
|
| 185 |
+
@click.command()
|
| 186 |
+
def cli():
|
| 187 |
+
pass
|
| 188 |
+
|
| 189 |
+
ctx = click.Context(cli)
|
| 190 |
+
|
| 191 |
+
@ctx.call_on_close
|
| 192 |
+
def test_callback():
|
| 193 |
+
rv.append(42)
|
| 194 |
+
|
| 195 |
+
with ctx.scope(cleanup=False):
|
| 196 |
+
# Internal
|
| 197 |
+
assert ctx._depth == 2
|
| 198 |
+
|
| 199 |
+
assert rv == []
|
| 200 |
+
|
| 201 |
+
with ctx.scope():
|
| 202 |
+
# Internal
|
| 203 |
+
assert ctx._depth == 1
|
| 204 |
+
|
| 205 |
+
assert rv == [42]
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
def test_pass_obj(runner):
|
| 209 |
+
@click.group()
|
| 210 |
+
@click.pass_context
|
| 211 |
+
def cli(ctx):
|
| 212 |
+
ctx.obj = "test"
|
| 213 |
+
|
| 214 |
+
@cli.command()
|
| 215 |
+
@click.pass_obj
|
| 216 |
+
def test(obj):
|
| 217 |
+
click.echo(obj)
|
| 218 |
+
|
| 219 |
+
result = runner.invoke(cli, ["test"])
|
| 220 |
+
assert not result.exception
|
| 221 |
+
assert result.output == "test\n"
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def test_close_before_pop(runner):
|
| 225 |
+
called = []
|
| 226 |
+
|
| 227 |
+
@click.command()
|
| 228 |
+
@click.pass_context
|
| 229 |
+
def cli(ctx):
|
| 230 |
+
ctx.obj = "test"
|
| 231 |
+
|
| 232 |
+
@ctx.call_on_close
|
| 233 |
+
def foo():
|
| 234 |
+
assert click.get_current_context().obj == "test"
|
| 235 |
+
called.append(True)
|
| 236 |
+
|
| 237 |
+
click.echo("aha!")
|
| 238 |
+
|
| 239 |
+
result = runner.invoke(cli, [])
|
| 240 |
+
assert not result.exception
|
| 241 |
+
assert result.output == "aha!\n"
|
| 242 |
+
assert called == [True]
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
def test_close_before_exit(runner):
|
| 246 |
+
called = []
|
| 247 |
+
|
| 248 |
+
@click.command()
|
| 249 |
+
@click.pass_context
|
| 250 |
+
def cli(ctx):
|
| 251 |
+
ctx.obj = "test"
|
| 252 |
+
|
| 253 |
+
@ctx.call_on_close
|
| 254 |
+
def foo():
|
| 255 |
+
assert click.get_current_context().obj == "test"
|
| 256 |
+
called.append(True)
|
| 257 |
+
|
| 258 |
+
ctx.exit()
|
| 259 |
+
|
| 260 |
+
click.echo("aha!")
|
| 261 |
+
|
| 262 |
+
result = runner.invoke(cli, [])
|
| 263 |
+
assert not result.exception
|
| 264 |
+
assert not result.output
|
| 265 |
+
assert called == [True]
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
@pytest.mark.parametrize(
|
| 269 |
+
("cli_args", "expect"),
|
| 270 |
+
[
|
| 271 |
+
pytest.param(
|
| 272 |
+
("--option-with-callback", "--force-exit"),
|
| 273 |
+
["ExitingOption", "NonExitingOption"],
|
| 274 |
+
id="natural_order",
|
| 275 |
+
),
|
| 276 |
+
pytest.param(
|
| 277 |
+
("--force-exit", "--option-with-callback"),
|
| 278 |
+
["ExitingOption"],
|
| 279 |
+
id="eagerness_precedence",
|
| 280 |
+
),
|
| 281 |
+
],
|
| 282 |
+
)
|
| 283 |
+
def test_multiple_eager_callbacks(runner, cli_args, expect):
|
| 284 |
+
"""Checks all callbacks are called on exit, even the nasty ones hidden within
|
| 285 |
+
callbacks.
|
| 286 |
+
|
| 287 |
+
Also checks the order in which they're called.
|
| 288 |
+
"""
|
| 289 |
+
# Keeps track of callback calls.
|
| 290 |
+
called = []
|
| 291 |
+
|
| 292 |
+
class NonExitingOption(Option):
|
| 293 |
+
def reset_state(self):
|
| 294 |
+
called.append(self.__class__.__name__)
|
| 295 |
+
|
| 296 |
+
def set_state(self, ctx: Context, param: Parameter, value: str) -> str:
|
| 297 |
+
ctx.call_on_close(self.reset_state)
|
| 298 |
+
return value
|
| 299 |
+
|
| 300 |
+
def __init__(self, *args, **kwargs) -> None:
|
| 301 |
+
kwargs.setdefault("expose_value", False)
|
| 302 |
+
kwargs.setdefault("callback", self.set_state)
|
| 303 |
+
super().__init__(*args, **kwargs)
|
| 304 |
+
|
| 305 |
+
class ExitingOption(NonExitingOption):
|
| 306 |
+
def set_state(self, ctx: Context, param: Parameter, value: str) -> str:
|
| 307 |
+
value = super().set_state(ctx, param, value)
|
| 308 |
+
ctx.exit()
|
| 309 |
+
return value
|
| 310 |
+
|
| 311 |
+
@click.command()
|
| 312 |
+
@click.option("--option-with-callback", is_eager=True, cls=NonExitingOption)
|
| 313 |
+
@click.option("--force-exit", is_eager=True, cls=ExitingOption)
|
| 314 |
+
def cli():
|
| 315 |
+
click.echo("This will never be printed as we forced exit via --force-exit")
|
| 316 |
+
|
| 317 |
+
result = runner.invoke(cli, cli_args)
|
| 318 |
+
assert not result.exception
|
| 319 |
+
assert not result.output
|
| 320 |
+
|
| 321 |
+
assert called == expect
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
def test_no_state_leaks(runner):
|
| 325 |
+
"""Demonstrate state leaks with a specific case of the generic test above.
|
| 326 |
+
|
| 327 |
+
Use a logger as a real-world example of a common fixture which, due to its global
|
| 328 |
+
nature, can leak state if not clean-up properly in a callback.
|
| 329 |
+
"""
|
| 330 |
+
# Keeps track of callback calls.
|
| 331 |
+
called = []
|
| 332 |
+
|
| 333 |
+
class DebugLoggerOption(Option):
|
| 334 |
+
"""A custom option to set the name of the debug logger."""
|
| 335 |
+
|
| 336 |
+
logger_name: str
|
| 337 |
+
"""The ID of the logger to use."""
|
| 338 |
+
|
| 339 |
+
def reset_loggers(self):
|
| 340 |
+
"""Forces logger managed by the option to be reset to the default level."""
|
| 341 |
+
logger = logging.getLogger(self.logger_name)
|
| 342 |
+
logger.setLevel(logging.NOTSET)
|
| 343 |
+
|
| 344 |
+
# Logger has been properly reset to its initial state.
|
| 345 |
+
assert logger.level == logging.NOTSET
|
| 346 |
+
assert logger.getEffectiveLevel() == logging.WARNING
|
| 347 |
+
|
| 348 |
+
called.append(True)
|
| 349 |
+
|
| 350 |
+
def set_level(self, ctx: Context, param: Parameter, value: str) -> None:
|
| 351 |
+
"""Set the logger to DEBUG level."""
|
| 352 |
+
# Keep the logger name around so we can reset it later when winding down
|
| 353 |
+
# the option.
|
| 354 |
+
self.logger_name = value
|
| 355 |
+
|
| 356 |
+
# Get the global logger object.
|
| 357 |
+
logger = logging.getLogger(self.logger_name)
|
| 358 |
+
|
| 359 |
+
# Check pre-conditions: new logger is not set, but inherits its level from
|
| 360 |
+
# default <root> logger. That's the exact same state we are expecting our
|
| 361 |
+
# logger to be in after being messed with by the CLI.
|
| 362 |
+
assert logger.level == logging.NOTSET
|
| 363 |
+
assert logger.getEffectiveLevel() == logging.WARNING
|
| 364 |
+
|
| 365 |
+
logger.setLevel(logging.DEBUG)
|
| 366 |
+
ctx.call_on_close(self.reset_loggers)
|
| 367 |
+
return value
|
| 368 |
+
|
| 369 |
+
def __init__(self, *args, **kwargs) -> None:
|
| 370 |
+
kwargs.setdefault("callback", self.set_level)
|
| 371 |
+
super().__init__(*args, **kwargs)
|
| 372 |
+
|
| 373 |
+
@click.command()
|
| 374 |
+
@click.option("--debug-logger-name", is_eager=True, cls=DebugLoggerOption)
|
| 375 |
+
@help_option()
|
| 376 |
+
@click.pass_context
|
| 377 |
+
def messing_with_logger(ctx, debug_logger_name):
|
| 378 |
+
# Introspect context to make sure logger name are aligned.
|
| 379 |
+
assert debug_logger_name == ctx.command.params[0].logger_name
|
| 380 |
+
|
| 381 |
+
logger = logging.getLogger(debug_logger_name)
|
| 382 |
+
|
| 383 |
+
# Logger's level has been properly set to DEBUG by DebugLoggerOption.
|
| 384 |
+
assert logger.level == logging.DEBUG
|
| 385 |
+
assert logger.getEffectiveLevel() == logging.DEBUG
|
| 386 |
+
|
| 387 |
+
logger.debug("Blah blah blah")
|
| 388 |
+
|
| 389 |
+
ctx.exit()
|
| 390 |
+
|
| 391 |
+
click.echo("This will never be printed as we exited early")
|
| 392 |
+
|
| 393 |
+
# Call the CLI to mess with the custom logger.
|
| 394 |
+
result = runner.invoke(
|
| 395 |
+
messing_with_logger, ["--debug-logger-name", "my_logger", "--help"]
|
| 396 |
+
)
|
| 397 |
+
|
| 398 |
+
assert called == [True]
|
| 399 |
+
|
| 400 |
+
# Check the custom logger has been reverted to it initial state by the option
|
| 401 |
+
# callback after being messed with by the CLI.
|
| 402 |
+
logger = logging.getLogger("my_logger")
|
| 403 |
+
assert logger.level == logging.NOTSET
|
| 404 |
+
assert logger.getEffectiveLevel() == logging.WARNING
|
| 405 |
+
|
| 406 |
+
assert not result.exception
|
| 407 |
+
assert result.output.startswith("Usage: messing-with-logger [OPTIONS]")
|
| 408 |
+
|
| 409 |
+
|
| 410 |
+
def test_with_resource():
|
| 411 |
+
@contextmanager
|
| 412 |
+
def manager():
|
| 413 |
+
val = [1]
|
| 414 |
+
yield val
|
| 415 |
+
val[0] = 0
|
| 416 |
+
|
| 417 |
+
ctx = click.Context(click.Command("test"))
|
| 418 |
+
|
| 419 |
+
with ctx.scope():
|
| 420 |
+
rv = ctx.with_resource(manager())
|
| 421 |
+
assert rv[0] == 1
|
| 422 |
+
|
| 423 |
+
assert rv == [0]
|
| 424 |
+
|
| 425 |
+
|
| 426 |
+
def test_make_pass_decorator_args(runner):
|
| 427 |
+
"""
|
| 428 |
+
Test to check that make_pass_decorator doesn't consume arguments based on
|
| 429 |
+
invocation order.
|
| 430 |
+
"""
|
| 431 |
+
|
| 432 |
+
class Foo:
|
| 433 |
+
title = "foocmd"
|
| 434 |
+
|
| 435 |
+
pass_foo = click.make_pass_decorator(Foo)
|
| 436 |
+
|
| 437 |
+
@click.group()
|
| 438 |
+
@click.pass_context
|
| 439 |
+
def cli(ctx):
|
| 440 |
+
ctx.obj = Foo()
|
| 441 |
+
|
| 442 |
+
@cli.command()
|
| 443 |
+
@click.pass_context
|
| 444 |
+
@pass_foo
|
| 445 |
+
def test1(foo, ctx):
|
| 446 |
+
click.echo(foo.title)
|
| 447 |
+
|
| 448 |
+
@cli.command()
|
| 449 |
+
@pass_foo
|
| 450 |
+
@click.pass_context
|
| 451 |
+
def test2(ctx, foo):
|
| 452 |
+
click.echo(foo.title)
|
| 453 |
+
|
| 454 |
+
result = runner.invoke(cli, ["test1"])
|
| 455 |
+
assert not result.exception
|
| 456 |
+
assert result.output == "foocmd\n"
|
| 457 |
+
|
| 458 |
+
result = runner.invoke(cli, ["test2"])
|
| 459 |
+
assert not result.exception
|
| 460 |
+
assert result.output == "foocmd\n"
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
def test_propagate_show_default_setting(runner):
|
| 464 |
+
"""A context's ``show_default`` setting defaults to the value from
|
| 465 |
+
the parent context.
|
| 466 |
+
"""
|
| 467 |
+
group = click.Group(
|
| 468 |
+
commands={
|
| 469 |
+
"sub": click.Command("sub", params=[click.Option(["-a"], default="a")]),
|
| 470 |
+
},
|
| 471 |
+
context_settings={"show_default": True},
|
| 472 |
+
)
|
| 473 |
+
result = runner.invoke(group, ["sub", "--help"])
|
| 474 |
+
assert "[default: a]" in result.output
|
| 475 |
+
|
| 476 |
+
|
| 477 |
+
def test_exit_not_standalone():
|
| 478 |
+
@click.command()
|
| 479 |
+
@click.pass_context
|
| 480 |
+
def cli(ctx):
|
| 481 |
+
ctx.exit(1)
|
| 482 |
+
|
| 483 |
+
assert cli.main([], "test_exit_not_standalone", standalone_mode=False) == 1
|
| 484 |
+
|
| 485 |
+
@click.command()
|
| 486 |
+
@click.pass_context
|
| 487 |
+
def cli(ctx):
|
| 488 |
+
ctx.exit(0)
|
| 489 |
+
|
| 490 |
+
assert cli.main([], "test_exit_not_standalone", standalone_mode=False) == 0
|
| 491 |
+
|
| 492 |
+
|
| 493 |
+
@pytest.mark.parametrize(
|
| 494 |
+
("option_args", "invoke_args", "expect"),
|
| 495 |
+
[
|
| 496 |
+
pytest.param({}, {}, ParameterSource.DEFAULT, id="default"),
|
| 497 |
+
pytest.param(
|
| 498 |
+
{},
|
| 499 |
+
{"default_map": {"option": 1}},
|
| 500 |
+
ParameterSource.DEFAULT_MAP,
|
| 501 |
+
id="default_map",
|
| 502 |
+
),
|
| 503 |
+
pytest.param(
|
| 504 |
+
{},
|
| 505 |
+
{"args": ["-o", "1"]},
|
| 506 |
+
ParameterSource.COMMANDLINE,
|
| 507 |
+
id="commandline short",
|
| 508 |
+
),
|
| 509 |
+
pytest.param(
|
| 510 |
+
{},
|
| 511 |
+
{"args": ["--option", "1"]},
|
| 512 |
+
ParameterSource.COMMANDLINE,
|
| 513 |
+
id="commandline long",
|
| 514 |
+
),
|
| 515 |
+
pytest.param(
|
| 516 |
+
{},
|
| 517 |
+
{"auto_envvar_prefix": "TEST", "env": {"TEST_OPTION": "1"}},
|
| 518 |
+
ParameterSource.ENVIRONMENT,
|
| 519 |
+
id="environment auto",
|
| 520 |
+
),
|
| 521 |
+
pytest.param(
|
| 522 |
+
{"envvar": "NAME"},
|
| 523 |
+
{"env": {"NAME": "1"}},
|
| 524 |
+
ParameterSource.ENVIRONMENT,
|
| 525 |
+
id="environment manual",
|
| 526 |
+
),
|
| 527 |
+
],
|
| 528 |
+
)
|
| 529 |
+
def test_parameter_source(runner, option_args, invoke_args, expect):
|
| 530 |
+
@click.command()
|
| 531 |
+
@click.pass_context
|
| 532 |
+
@click.option("-o", "--option", default=1, **option_args)
|
| 533 |
+
def cli(ctx, option):
|
| 534 |
+
return ctx.get_parameter_source("option")
|
| 535 |
+
|
| 536 |
+
rv = runner.invoke(cli, standalone_mode=False, **invoke_args)
|
| 537 |
+
assert rv.return_value == expect
|
| 538 |
+
|
| 539 |
+
|
| 540 |
+
def test_propagate_opt_prefixes():
|
| 541 |
+
parent = click.Context(click.Command("test"))
|
| 542 |
+
parent._opt_prefixes = {"-", "--", "!"}
|
| 543 |
+
ctx = click.Context(click.Command("test2"), parent=parent)
|
| 544 |
+
|
| 545 |
+
assert ctx._opt_prefixes == {"-", "--", "!"}
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_custom_classes.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import click
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def test_command_context_class():
|
| 5 |
+
"""A command with a custom ``context_class`` should produce a
|
| 6 |
+
context using that type.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
class CustomContext(click.Context):
|
| 10 |
+
pass
|
| 11 |
+
|
| 12 |
+
class CustomCommand(click.Command):
|
| 13 |
+
context_class = CustomContext
|
| 14 |
+
|
| 15 |
+
command = CustomCommand("test")
|
| 16 |
+
context = command.make_context("test", [])
|
| 17 |
+
assert isinstance(context, CustomContext)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def test_context_invoke_type(runner):
|
| 21 |
+
"""A command invoked from a custom context should have a new
|
| 22 |
+
context with the same type.
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
class CustomContext(click.Context):
|
| 26 |
+
pass
|
| 27 |
+
|
| 28 |
+
class CustomCommand(click.Command):
|
| 29 |
+
context_class = CustomContext
|
| 30 |
+
|
| 31 |
+
@click.command()
|
| 32 |
+
@click.argument("first_id", type=int)
|
| 33 |
+
@click.pass_context
|
| 34 |
+
def second(ctx, first_id):
|
| 35 |
+
assert isinstance(ctx, CustomContext)
|
| 36 |
+
assert id(ctx) != first_id
|
| 37 |
+
|
| 38 |
+
@click.command(cls=CustomCommand)
|
| 39 |
+
@click.pass_context
|
| 40 |
+
def first(ctx):
|
| 41 |
+
assert isinstance(ctx, CustomContext)
|
| 42 |
+
ctx.invoke(second, first_id=id(ctx))
|
| 43 |
+
|
| 44 |
+
assert not runner.invoke(first).exception
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def test_context_formatter_class():
|
| 48 |
+
"""A context with a custom ``formatter_class`` should format help
|
| 49 |
+
using that type.
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
class CustomFormatter(click.HelpFormatter):
|
| 53 |
+
def write_heading(self, heading):
|
| 54 |
+
heading = click.style(heading, fg="yellow")
|
| 55 |
+
return super().write_heading(heading)
|
| 56 |
+
|
| 57 |
+
class CustomContext(click.Context):
|
| 58 |
+
formatter_class = CustomFormatter
|
| 59 |
+
|
| 60 |
+
context = CustomContext(
|
| 61 |
+
click.Command("test", params=[click.Option(["--value"])]), color=True
|
| 62 |
+
)
|
| 63 |
+
assert "\x1b[33mOptions\x1b[0m:" in context.get_help()
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def test_group_command_class(runner):
|
| 67 |
+
"""A group with a custom ``command_class`` should create subcommands
|
| 68 |
+
of that type by default.
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
class CustomCommand(click.Command):
|
| 72 |
+
pass
|
| 73 |
+
|
| 74 |
+
class CustomGroup(click.Group):
|
| 75 |
+
command_class = CustomCommand
|
| 76 |
+
|
| 77 |
+
group = CustomGroup()
|
| 78 |
+
subcommand = group.command()(lambda: None)
|
| 79 |
+
assert type(subcommand) is CustomCommand
|
| 80 |
+
subcommand = group.command(cls=click.Command)(lambda: None)
|
| 81 |
+
assert type(subcommand) is click.Command
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def test_group_group_class(runner):
|
| 85 |
+
"""A group with a custom ``group_class`` should create subgroups
|
| 86 |
+
of that type by default.
|
| 87 |
+
"""
|
| 88 |
+
|
| 89 |
+
class CustomSubGroup(click.Group):
|
| 90 |
+
pass
|
| 91 |
+
|
| 92 |
+
class CustomGroup(click.Group):
|
| 93 |
+
group_class = CustomSubGroup
|
| 94 |
+
|
| 95 |
+
group = CustomGroup()
|
| 96 |
+
subgroup = group.group()(lambda: None)
|
| 97 |
+
assert type(subgroup) is CustomSubGroup
|
| 98 |
+
subgroup = group.command(cls=click.Group)(lambda: None)
|
| 99 |
+
assert type(subgroup) is click.Group
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def test_group_group_class_self(runner):
|
| 103 |
+
"""A group with ``group_class = type`` should create subgroups of
|
| 104 |
+
the same type as itself.
|
| 105 |
+
"""
|
| 106 |
+
|
| 107 |
+
class CustomGroup(click.Group):
|
| 108 |
+
group_class = type
|
| 109 |
+
|
| 110 |
+
group = CustomGroup()
|
| 111 |
+
subgroup = group.group()(lambda: None)
|
| 112 |
+
assert type(subgroup) is CustomGroup
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_defaults.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import click
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def test_basic_defaults(runner):
|
| 5 |
+
@click.command()
|
| 6 |
+
@click.option("--foo", default=42, type=click.FLOAT)
|
| 7 |
+
def cli(foo):
|
| 8 |
+
assert isinstance(foo, float)
|
| 9 |
+
click.echo(f"FOO:[{foo}]")
|
| 10 |
+
|
| 11 |
+
result = runner.invoke(cli, [])
|
| 12 |
+
assert not result.exception
|
| 13 |
+
assert "FOO:[42.0]" in result.output
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def test_multiple_defaults(runner):
|
| 17 |
+
@click.command()
|
| 18 |
+
@click.option("--foo", default=[23, 42], type=click.FLOAT, multiple=True)
|
| 19 |
+
def cli(foo):
|
| 20 |
+
for item in foo:
|
| 21 |
+
assert isinstance(item, float)
|
| 22 |
+
click.echo(item)
|
| 23 |
+
|
| 24 |
+
result = runner.invoke(cli, [])
|
| 25 |
+
assert not result.exception
|
| 26 |
+
assert result.output.splitlines() == ["23.0", "42.0"]
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def test_nargs_plus_multiple(runner):
|
| 30 |
+
@click.command()
|
| 31 |
+
@click.option(
|
| 32 |
+
"--arg", default=((1, 2), (3, 4)), nargs=2, multiple=True, type=click.INT
|
| 33 |
+
)
|
| 34 |
+
def cli(arg):
|
| 35 |
+
for a, b in arg:
|
| 36 |
+
click.echo(f"<{a:d}|{b:d}>")
|
| 37 |
+
|
| 38 |
+
result = runner.invoke(cli, [])
|
| 39 |
+
assert not result.exception
|
| 40 |
+
assert result.output.splitlines() == ["<1|2>", "<3|4>"]
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def test_multiple_flag_default(runner):
|
| 44 |
+
"""Default default for flags when multiple=True should be empty tuple."""
|
| 45 |
+
|
| 46 |
+
@click.command
|
| 47 |
+
# flag due to secondary token
|
| 48 |
+
@click.option("-y/-n", multiple=True)
|
| 49 |
+
# flag due to is_flag
|
| 50 |
+
@click.option("-f", is_flag=True, multiple=True)
|
| 51 |
+
# flag due to flag_value
|
| 52 |
+
@click.option("-v", "v", flag_value=1, multiple=True)
|
| 53 |
+
@click.option("-q", "v", flag_value=-1, multiple=True)
|
| 54 |
+
def cli(y, f, v):
|
| 55 |
+
return y, f, v
|
| 56 |
+
|
| 57 |
+
result = runner.invoke(cli, standalone_mode=False)
|
| 58 |
+
assert result.return_value == ((), (), ())
|
| 59 |
+
|
| 60 |
+
result = runner.invoke(cli, ["-y", "-n", "-f", "-v", "-q"], standalone_mode=False)
|
| 61 |
+
assert result.return_value == ((True, False), (True,), (1, -1))
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def test_flag_default_map(runner):
|
| 65 |
+
"""test flag with default map"""
|
| 66 |
+
|
| 67 |
+
@click.group()
|
| 68 |
+
def cli():
|
| 69 |
+
pass
|
| 70 |
+
|
| 71 |
+
@cli.command()
|
| 72 |
+
@click.option("--name/--no-name", is_flag=True, show_default=True, help="name flag")
|
| 73 |
+
def foo(name):
|
| 74 |
+
click.echo(name)
|
| 75 |
+
|
| 76 |
+
result = runner.invoke(cli, ["foo"])
|
| 77 |
+
assert "False" in result.output
|
| 78 |
+
|
| 79 |
+
result = runner.invoke(cli, ["foo", "--help"])
|
| 80 |
+
assert "default: no-name" in result.output
|
| 81 |
+
|
| 82 |
+
result = runner.invoke(cli, ["foo"], default_map={"foo": {"name": True}})
|
| 83 |
+
assert "True" in result.output
|
| 84 |
+
|
| 85 |
+
result = runner.invoke(cli, ["foo", "--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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import click
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def test_basic_functionality(runner):
|
| 5 |
+
@click.command()
|
| 6 |
+
def cli():
|
| 7 |
+
"""First paragraph.
|
| 8 |
+
|
| 9 |
+
This is a very long second
|
| 10 |
+
paragraph and not correctly
|
| 11 |
+
wrapped but it will be rewrapped.
|
| 12 |
+
|
| 13 |
+
\b
|
| 14 |
+
This is
|
| 15 |
+
a paragraph
|
| 16 |
+
without rewrapping.
|
| 17 |
+
|
| 18 |
+
\b
|
| 19 |
+
1
|
| 20 |
+
2
|
| 21 |
+
3
|
| 22 |
+
|
| 23 |
+
And this is a paragraph
|
| 24 |
+
that will be rewrapped again.
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
result = runner.invoke(cli, ["--help"], terminal_width=60)
|
| 28 |
+
assert not result.exception
|
| 29 |
+
assert result.output.splitlines() == [
|
| 30 |
+
"Usage: cli [OPTIONS]",
|
| 31 |
+
"",
|
| 32 |
+
" First paragraph.",
|
| 33 |
+
"",
|
| 34 |
+
" This is a very long second paragraph and not correctly",
|
| 35 |
+
" wrapped but it will be rewrapped.",
|
| 36 |
+
"",
|
| 37 |
+
" This is",
|
| 38 |
+
" a paragraph",
|
| 39 |
+
" without rewrapping.",
|
| 40 |
+
"",
|
| 41 |
+
" 1",
|
| 42 |
+
" 2",
|
| 43 |
+
" 3",
|
| 44 |
+
"",
|
| 45 |
+
" And this is a paragraph that will be rewrapped again.",
|
| 46 |
+
"",
|
| 47 |
+
"Options:",
|
| 48 |
+
" --help Show this message and exit.",
|
| 49 |
+
]
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def test_wrapping_long_options_strings(runner):
|
| 53 |
+
@click.group()
|
| 54 |
+
def cli():
|
| 55 |
+
"""Top level command"""
|
| 56 |
+
|
| 57 |
+
@cli.group()
|
| 58 |
+
def a_very_long():
|
| 59 |
+
"""Second level"""
|
| 60 |
+
|
| 61 |
+
@a_very_long.command()
|
| 62 |
+
@click.argument("first")
|
| 63 |
+
@click.argument("second")
|
| 64 |
+
@click.argument("third")
|
| 65 |
+
@click.argument("fourth")
|
| 66 |
+
@click.argument("fifth")
|
| 67 |
+
@click.argument("sixth")
|
| 68 |
+
def command():
|
| 69 |
+
"""A command."""
|
| 70 |
+
|
| 71 |
+
# 54 is chosen as a length where the second line is one character
|
| 72 |
+
# longer than the maximum length.
|
| 73 |
+
result = runner.invoke(cli, ["a-very-long", "command", "--help"], terminal_width=54)
|
| 74 |
+
assert not result.exception
|
| 75 |
+
assert result.output.splitlines() == [
|
| 76 |
+
"Usage: cli a-very-long command [OPTIONS] FIRST SECOND",
|
| 77 |
+
" THIRD FOURTH FIFTH",
|
| 78 |
+
" SIXTH",
|
| 79 |
+
"",
|
| 80 |
+
" A command.",
|
| 81 |
+
"",
|
| 82 |
+
"Options:",
|
| 83 |
+
" --help Show this message and exit.",
|
| 84 |
+
]
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def test_wrapping_long_command_name(runner):
|
| 88 |
+
@click.group()
|
| 89 |
+
def cli():
|
| 90 |
+
"""Top level command"""
|
| 91 |
+
|
| 92 |
+
@cli.group()
|
| 93 |
+
def a_very_very_very_long():
|
| 94 |
+
"""Second level"""
|
| 95 |
+
|
| 96 |
+
@a_very_very_very_long.command()
|
| 97 |
+
@click.argument("first")
|
| 98 |
+
@click.argument("second")
|
| 99 |
+
@click.argument("third")
|
| 100 |
+
@click.argument("fourth")
|
| 101 |
+
@click.argument("fifth")
|
| 102 |
+
@click.argument("sixth")
|
| 103 |
+
def command():
|
| 104 |
+
"""A command."""
|
| 105 |
+
|
| 106 |
+
result = runner.invoke(
|
| 107 |
+
cli, ["a-very-very-very-long", "command", "--help"], terminal_width=54
|
| 108 |
+
)
|
| 109 |
+
assert not result.exception
|
| 110 |
+
assert result.output.splitlines() == [
|
| 111 |
+
"Usage: cli a-very-very-very-long command ",
|
| 112 |
+
" [OPTIONS] FIRST SECOND THIRD FOURTH FIFTH",
|
| 113 |
+
" SIXTH",
|
| 114 |
+
"",
|
| 115 |
+
" A command.",
|
| 116 |
+
"",
|
| 117 |
+
"Options:",
|
| 118 |
+
" --help Show this message and exit.",
|
| 119 |
+
]
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def test_formatting_empty_help_lines(runner):
|
| 123 |
+
@click.command()
|
| 124 |
+
def cli():
|
| 125 |
+
# fmt: off
|
| 126 |
+
"""Top level command
|
| 127 |
+
|
| 128 |
+
"""
|
| 129 |
+
# fmt: on
|
| 130 |
+
|
| 131 |
+
result = runner.invoke(cli, ["--help"])
|
| 132 |
+
assert not result.exception
|
| 133 |
+
assert result.output.splitlines() == [
|
| 134 |
+
"Usage: cli [OPTIONS]",
|
| 135 |
+
"",
|
| 136 |
+
" Top level command",
|
| 137 |
+
"",
|
| 138 |
+
"",
|
| 139 |
+
"",
|
| 140 |
+
"Options:",
|
| 141 |
+
" --help Show this message and exit.",
|
| 142 |
+
]
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def test_formatting_usage_error(runner):
|
| 146 |
+
@click.command()
|
| 147 |
+
@click.argument("arg")
|
| 148 |
+
def cmd(arg):
|
| 149 |
+
click.echo(f"arg:{arg}")
|
| 150 |
+
|
| 151 |
+
result = runner.invoke(cmd, [])
|
| 152 |
+
assert result.exit_code == 2
|
| 153 |
+
assert result.output.splitlines() == [
|
| 154 |
+
"Usage: cmd [OPTIONS] ARG",
|
| 155 |
+
"Try 'cmd --help' for help.",
|
| 156 |
+
"",
|
| 157 |
+
"Error: Missing argument 'ARG'.",
|
| 158 |
+
]
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def test_formatting_usage_error_metavar_missing_arg(runner):
|
| 162 |
+
"""
|
| 163 |
+
:author: @r-m-n
|
| 164 |
+
Including attribution to #612
|
| 165 |
+
"""
|
| 166 |
+
|
| 167 |
+
@click.command()
|
| 168 |
+
@click.argument("arg", metavar="metavar")
|
| 169 |
+
def cmd(arg):
|
| 170 |
+
pass
|
| 171 |
+
|
| 172 |
+
result = runner.invoke(cmd, [])
|
| 173 |
+
assert result.exit_code == 2
|
| 174 |
+
assert result.output.splitlines() == [
|
| 175 |
+
"Usage: cmd [OPTIONS] metavar",
|
| 176 |
+
"Try 'cmd --help' for help.",
|
| 177 |
+
"",
|
| 178 |
+
"Error: Missing argument 'metavar'.",
|
| 179 |
+
]
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def test_formatting_usage_error_metavar_bad_arg(runner):
|
| 183 |
+
@click.command()
|
| 184 |
+
@click.argument("arg", type=click.INT, metavar="metavar")
|
| 185 |
+
def cmd(arg):
|
| 186 |
+
pass
|
| 187 |
+
|
| 188 |
+
result = runner.invoke(cmd, ["3.14"])
|
| 189 |
+
assert result.exit_code == 2
|
| 190 |
+
assert result.output.splitlines() == [
|
| 191 |
+
"Usage: cmd [OPTIONS] metavar",
|
| 192 |
+
"Try 'cmd --help' for help.",
|
| 193 |
+
"",
|
| 194 |
+
"Error: Invalid value for 'metavar': '3.14' is not a valid integer.",
|
| 195 |
+
]
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
def test_formatting_usage_error_nested(runner):
|
| 199 |
+
@click.group()
|
| 200 |
+
def cmd():
|
| 201 |
+
pass
|
| 202 |
+
|
| 203 |
+
@cmd.command()
|
| 204 |
+
@click.argument("bar")
|
| 205 |
+
def foo(bar):
|
| 206 |
+
click.echo(f"foo:{bar}")
|
| 207 |
+
|
| 208 |
+
result = runner.invoke(cmd, ["foo"])
|
| 209 |
+
assert result.exit_code == 2
|
| 210 |
+
assert result.output.splitlines() == [
|
| 211 |
+
"Usage: cmd foo [OPTIONS] BAR",
|
| 212 |
+
"Try 'cmd foo --help' for help.",
|
| 213 |
+
"",
|
| 214 |
+
"Error: Missing argument 'BAR'.",
|
| 215 |
+
]
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
def test_formatting_usage_error_no_help(runner):
|
| 219 |
+
@click.command(add_help_option=False)
|
| 220 |
+
@click.argument("arg")
|
| 221 |
+
def cmd(arg):
|
| 222 |
+
click.echo(f"arg:{arg}")
|
| 223 |
+
|
| 224 |
+
result = runner.invoke(cmd, [])
|
| 225 |
+
assert result.exit_code == 2
|
| 226 |
+
assert result.output.splitlines() == [
|
| 227 |
+
"Usage: cmd [OPTIONS] ARG",
|
| 228 |
+
"",
|
| 229 |
+
"Error: Missing argument 'ARG'.",
|
| 230 |
+
]
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
def test_formatting_usage_custom_help(runner):
|
| 234 |
+
@click.command(context_settings=dict(help_option_names=["--man"]))
|
| 235 |
+
@click.argument("arg")
|
| 236 |
+
def cmd(arg):
|
| 237 |
+
click.echo(f"arg:{arg}")
|
| 238 |
+
|
| 239 |
+
result = runner.invoke(cmd, [])
|
| 240 |
+
assert result.exit_code == 2
|
| 241 |
+
assert result.output.splitlines() == [
|
| 242 |
+
"Usage: cmd [OPTIONS] ARG",
|
| 243 |
+
"Try 'cmd --man' for help.",
|
| 244 |
+
"",
|
| 245 |
+
"Error: Missing argument 'ARG'.",
|
| 246 |
+
]
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def test_formatting_custom_type_metavar(runner):
|
| 250 |
+
class MyType(click.ParamType):
|
| 251 |
+
def get_metavar(self, param):
|
| 252 |
+
return "MY_TYPE"
|
| 253 |
+
|
| 254 |
+
@click.command("foo")
|
| 255 |
+
@click.help_option()
|
| 256 |
+
@click.argument("param", type=MyType())
|
| 257 |
+
def cmd(param):
|
| 258 |
+
pass
|
| 259 |
+
|
| 260 |
+
result = runner.invoke(cmd, "--help")
|
| 261 |
+
assert not result.exception
|
| 262 |
+
assert result.output.splitlines() == [
|
| 263 |
+
"Usage: foo [OPTIONS] MY_TYPE",
|
| 264 |
+
"",
|
| 265 |
+
"Options:",
|
| 266 |
+
" --help Show this message and exit.",
|
| 267 |
+
]
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
def test_truncating_docstring(runner):
|
| 271 |
+
@click.command()
|
| 272 |
+
@click.pass_context
|
| 273 |
+
def cli(ctx):
|
| 274 |
+
"""First paragraph.
|
| 275 |
+
|
| 276 |
+
This is a very long second
|
| 277 |
+
paragraph and not correctly
|
| 278 |
+
wrapped but it will be rewrapped.
|
| 279 |
+
\f
|
| 280 |
+
|
| 281 |
+
:param click.core.Context ctx: Click context.
|
| 282 |
+
"""
|
| 283 |
+
|
| 284 |
+
result = runner.invoke(cli, ["--help"], terminal_width=60)
|
| 285 |
+
assert not result.exception
|
| 286 |
+
assert result.output.splitlines() == [
|
| 287 |
+
"Usage: cli [OPTIONS]",
|
| 288 |
+
"",
|
| 289 |
+
" First paragraph.",
|
| 290 |
+
"",
|
| 291 |
+
" This is a very long second paragraph and not correctly",
|
| 292 |
+
" wrapped but it will be rewrapped.",
|
| 293 |
+
"",
|
| 294 |
+
"Options:",
|
| 295 |
+
" --help Show this message and exit.",
|
| 296 |
+
]
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
def test_truncating_docstring_no_help(runner):
|
| 300 |
+
@click.command()
|
| 301 |
+
@click.pass_context
|
| 302 |
+
def cli(ctx):
|
| 303 |
+
"""
|
| 304 |
+
\f
|
| 305 |
+
|
| 306 |
+
This text should be truncated.
|
| 307 |
+
"""
|
| 308 |
+
|
| 309 |
+
result = runner.invoke(cli, ["--help"], terminal_width=60)
|
| 310 |
+
assert not result.exception
|
| 311 |
+
assert result.output.splitlines() == [
|
| 312 |
+
"Usage: cli [OPTIONS]",
|
| 313 |
+
"",
|
| 314 |
+
"Options:",
|
| 315 |
+
" --help Show this message and exit.",
|
| 316 |
+
]
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
def test_removing_multiline_marker(runner):
|
| 320 |
+
@click.group()
|
| 321 |
+
def cli():
|
| 322 |
+
pass
|
| 323 |
+
|
| 324 |
+
@cli.command()
|
| 325 |
+
def cmd1():
|
| 326 |
+
"""\b
|
| 327 |
+
This is command with a multiline help text
|
| 328 |
+
which should not be rewrapped.
|
| 329 |
+
The output of the short help text should
|
| 330 |
+
not contain the multiline marker.
|
| 331 |
+
"""
|
| 332 |
+
pass
|
| 333 |
+
|
| 334 |
+
result = runner.invoke(cli, ["--help"])
|
| 335 |
+
assert "\b" not in result.output
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
def test_global_show_default(runner):
|
| 339 |
+
@click.command(context_settings=dict(show_default=True))
|
| 340 |
+
@click.option("-f", "in_file", default="out.txt", help="Output file name")
|
| 341 |
+
def cli():
|
| 342 |
+
pass
|
| 343 |
+
|
| 344 |
+
result = runner.invoke(cli, ["--help"])
|
| 345 |
+
# the default to "--help" is not shown because it is False
|
| 346 |
+
assert result.output.splitlines() == [
|
| 347 |
+
"Usage: cli [OPTIONS]",
|
| 348 |
+
"",
|
| 349 |
+
"Options:",
|
| 350 |
+
" -f TEXT Output file name [default: out.txt]",
|
| 351 |
+
" --help Show this message and exit.",
|
| 352 |
+
]
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
def test_formatting_with_options_metavar_empty(runner):
|
| 356 |
+
cli = click.Command("cli", options_metavar="", params=[click.Argument(["var"])])
|
| 357 |
+
result = runner.invoke(cli, ["--help"])
|
| 358 |
+
assert "Usage: cli VAR\n" in result.output
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
def test_help_formatter_write_text():
|
| 362 |
+
text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit"
|
| 363 |
+
formatter = click.HelpFormatter(width=len(" Lorem ipsum dolor sit amet,"))
|
| 364 |
+
formatter.current_indent = 2
|
| 365 |
+
formatter.write_text(text)
|
| 366 |
+
actual = formatter.getvalue()
|
| 367 |
+
expected = " Lorem ipsum dolor sit amet,\n consectetur adipiscing elit\n"
|
| 368 |
+
assert actual == expected
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_imports.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import subprocess
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
from click._compat import WIN
|
| 6 |
+
|
| 7 |
+
IMPORT_TEST = b"""\
|
| 8 |
+
import builtins
|
| 9 |
+
|
| 10 |
+
found_imports = set()
|
| 11 |
+
real_import = builtins.__import__
|
| 12 |
+
import sys
|
| 13 |
+
|
| 14 |
+
def tracking_import(module, locals=None, globals=None, fromlist=None,
|
| 15 |
+
level=0):
|
| 16 |
+
rv = real_import(module, locals, globals, fromlist, level)
|
| 17 |
+
if globals and globals['__name__'].startswith('click') and level == 0:
|
| 18 |
+
found_imports.add(module)
|
| 19 |
+
return rv
|
| 20 |
+
builtins.__import__ = tracking_import
|
| 21 |
+
|
| 22 |
+
import click
|
| 23 |
+
rv = list(found_imports)
|
| 24 |
+
import json
|
| 25 |
+
click.echo(json.dumps(rv))
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
ALLOWED_IMPORTS = {
|
| 29 |
+
"__future__",
|
| 30 |
+
"weakref",
|
| 31 |
+
"os",
|
| 32 |
+
"struct",
|
| 33 |
+
"collections",
|
| 34 |
+
"collections.abc",
|
| 35 |
+
"sys",
|
| 36 |
+
"contextlib",
|
| 37 |
+
"functools",
|
| 38 |
+
"stat",
|
| 39 |
+
"re",
|
| 40 |
+
"codecs",
|
| 41 |
+
"inspect",
|
| 42 |
+
"itertools",
|
| 43 |
+
"io",
|
| 44 |
+
"threading",
|
| 45 |
+
"errno",
|
| 46 |
+
"fcntl",
|
| 47 |
+
"datetime",
|
| 48 |
+
"enum",
|
| 49 |
+
"typing",
|
| 50 |
+
"types",
|
| 51 |
+
"gettext",
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
if WIN:
|
| 55 |
+
ALLOWED_IMPORTS.update(["ctypes", "ctypes.wintypes", "msvcrt", "time"])
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def test_light_imports():
|
| 59 |
+
c = subprocess.Popen(
|
| 60 |
+
[sys.executable, "-"], stdin=subprocess.PIPE, stdout=subprocess.PIPE
|
| 61 |
+
)
|
| 62 |
+
rv = c.communicate(IMPORT_TEST)[0]
|
| 63 |
+
rv = rv.decode("utf-8")
|
| 64 |
+
imported = json.loads(rv)
|
| 65 |
+
|
| 66 |
+
for module in imported:
|
| 67 |
+
if module == "click" or module.startswith("click."):
|
| 68 |
+
continue
|
| 69 |
+
assert module in ALLOWED_IMPORTS
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_info_dict.py
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
|
| 3 |
+
import click.types
|
| 4 |
+
|
| 5 |
+
# Common (obj, expect) pairs used to construct multiple tests.
|
| 6 |
+
STRING_PARAM_TYPE = (click.STRING, {"param_type": "String", "name": "text"})
|
| 7 |
+
INT_PARAM_TYPE = (click.INT, {"param_type": "Int", "name": "integer"})
|
| 8 |
+
BOOL_PARAM_TYPE = (click.BOOL, {"param_type": "Bool", "name": "boolean"})
|
| 9 |
+
HELP_OPTION = (
|
| 10 |
+
None,
|
| 11 |
+
{
|
| 12 |
+
"name": "help",
|
| 13 |
+
"param_type_name": "option",
|
| 14 |
+
"opts": ["--help"],
|
| 15 |
+
"secondary_opts": [],
|
| 16 |
+
"type": BOOL_PARAM_TYPE[1],
|
| 17 |
+
"required": False,
|
| 18 |
+
"nargs": 1,
|
| 19 |
+
"multiple": False,
|
| 20 |
+
"default": False,
|
| 21 |
+
"envvar": None,
|
| 22 |
+
"help": "Show this message and exit.",
|
| 23 |
+
"prompt": None,
|
| 24 |
+
"is_flag": True,
|
| 25 |
+
"flag_value": True,
|
| 26 |
+
"count": False,
|
| 27 |
+
"hidden": False,
|
| 28 |
+
},
|
| 29 |
+
)
|
| 30 |
+
NAME_ARGUMENT = (
|
| 31 |
+
click.Argument(["name"]),
|
| 32 |
+
{
|
| 33 |
+
"name": "name",
|
| 34 |
+
"param_type_name": "argument",
|
| 35 |
+
"opts": ["name"],
|
| 36 |
+
"secondary_opts": [],
|
| 37 |
+
"type": STRING_PARAM_TYPE[1],
|
| 38 |
+
"required": True,
|
| 39 |
+
"nargs": 1,
|
| 40 |
+
"multiple": False,
|
| 41 |
+
"default": None,
|
| 42 |
+
"envvar": None,
|
| 43 |
+
},
|
| 44 |
+
)
|
| 45 |
+
NUMBER_OPTION = (
|
| 46 |
+
click.Option(["-c", "--count", "number"], default=1),
|
| 47 |
+
{
|
| 48 |
+
"name": "number",
|
| 49 |
+
"param_type_name": "option",
|
| 50 |
+
"opts": ["-c", "--count"],
|
| 51 |
+
"secondary_opts": [],
|
| 52 |
+
"type": INT_PARAM_TYPE[1],
|
| 53 |
+
"required": False,
|
| 54 |
+
"nargs": 1,
|
| 55 |
+
"multiple": False,
|
| 56 |
+
"default": 1,
|
| 57 |
+
"envvar": None,
|
| 58 |
+
"help": None,
|
| 59 |
+
"prompt": None,
|
| 60 |
+
"is_flag": False,
|
| 61 |
+
"flag_value": False,
|
| 62 |
+
"count": False,
|
| 63 |
+
"hidden": False,
|
| 64 |
+
},
|
| 65 |
+
)
|
| 66 |
+
HELLO_COMMAND = (
|
| 67 |
+
click.Command("hello", params=[NUMBER_OPTION[0]]),
|
| 68 |
+
{
|
| 69 |
+
"name": "hello",
|
| 70 |
+
"params": [NUMBER_OPTION[1], HELP_OPTION[1]],
|
| 71 |
+
"help": None,
|
| 72 |
+
"epilog": None,
|
| 73 |
+
"short_help": None,
|
| 74 |
+
"hidden": False,
|
| 75 |
+
"deprecated": False,
|
| 76 |
+
},
|
| 77 |
+
)
|
| 78 |
+
HELLO_GROUP = (
|
| 79 |
+
click.Group("cli", [HELLO_COMMAND[0]]),
|
| 80 |
+
{
|
| 81 |
+
"name": "cli",
|
| 82 |
+
"params": [HELP_OPTION[1]],
|
| 83 |
+
"help": None,
|
| 84 |
+
"epilog": None,
|
| 85 |
+
"short_help": None,
|
| 86 |
+
"hidden": False,
|
| 87 |
+
"deprecated": False,
|
| 88 |
+
"commands": {"hello": HELLO_COMMAND[1]},
|
| 89 |
+
"chain": False,
|
| 90 |
+
},
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
@pytest.mark.parametrize(
|
| 95 |
+
("obj", "expect"),
|
| 96 |
+
[
|
| 97 |
+
pytest.param(
|
| 98 |
+
click.types.FuncParamType(range),
|
| 99 |
+
{"param_type": "Func", "name": "range", "func": range},
|
| 100 |
+
id="Func ParamType",
|
| 101 |
+
),
|
| 102 |
+
pytest.param(
|
| 103 |
+
click.UNPROCESSED,
|
| 104 |
+
{"param_type": "Unprocessed", "name": "text"},
|
| 105 |
+
id="UNPROCESSED ParamType",
|
| 106 |
+
),
|
| 107 |
+
pytest.param(*STRING_PARAM_TYPE, id="STRING ParamType"),
|
| 108 |
+
pytest.param(
|
| 109 |
+
click.Choice(["a", "b"]),
|
| 110 |
+
{
|
| 111 |
+
"param_type": "Choice",
|
| 112 |
+
"name": "choice",
|
| 113 |
+
"choices": ["a", "b"],
|
| 114 |
+
"case_sensitive": True,
|
| 115 |
+
},
|
| 116 |
+
id="Choice ParamType",
|
| 117 |
+
),
|
| 118 |
+
pytest.param(
|
| 119 |
+
click.DateTime(["%Y-%m-%d"]),
|
| 120 |
+
{"param_type": "DateTime", "name": "datetime", "formats": ["%Y-%m-%d"]},
|
| 121 |
+
id="DateTime ParamType",
|
| 122 |
+
),
|
| 123 |
+
pytest.param(*INT_PARAM_TYPE, id="INT ParamType"),
|
| 124 |
+
pytest.param(
|
| 125 |
+
click.IntRange(0, 10, clamp=True),
|
| 126 |
+
{
|
| 127 |
+
"param_type": "IntRange",
|
| 128 |
+
"name": "integer range",
|
| 129 |
+
"min": 0,
|
| 130 |
+
"max": 10,
|
| 131 |
+
"min_open": False,
|
| 132 |
+
"max_open": False,
|
| 133 |
+
"clamp": True,
|
| 134 |
+
},
|
| 135 |
+
id="IntRange ParamType",
|
| 136 |
+
),
|
| 137 |
+
pytest.param(
|
| 138 |
+
click.FLOAT, {"param_type": "Float", "name": "float"}, id="FLOAT ParamType"
|
| 139 |
+
),
|
| 140 |
+
pytest.param(
|
| 141 |
+
click.FloatRange(-0.5, 0.5),
|
| 142 |
+
{
|
| 143 |
+
"param_type": "FloatRange",
|
| 144 |
+
"name": "float range",
|
| 145 |
+
"min": -0.5,
|
| 146 |
+
"max": 0.5,
|
| 147 |
+
"min_open": False,
|
| 148 |
+
"max_open": False,
|
| 149 |
+
"clamp": False,
|
| 150 |
+
},
|
| 151 |
+
id="FloatRange ParamType",
|
| 152 |
+
),
|
| 153 |
+
pytest.param(*BOOL_PARAM_TYPE, id="Bool ParamType"),
|
| 154 |
+
pytest.param(
|
| 155 |
+
click.UUID, {"param_type": "UUID", "name": "uuid"}, id="UUID ParamType"
|
| 156 |
+
),
|
| 157 |
+
pytest.param(
|
| 158 |
+
click.File(),
|
| 159 |
+
{"param_type": "File", "name": "filename", "mode": "r", "encoding": None},
|
| 160 |
+
id="File ParamType",
|
| 161 |
+
),
|
| 162 |
+
pytest.param(
|
| 163 |
+
click.Path(),
|
| 164 |
+
{
|
| 165 |
+
"param_type": "Path",
|
| 166 |
+
"name": "path",
|
| 167 |
+
"exists": False,
|
| 168 |
+
"file_okay": True,
|
| 169 |
+
"dir_okay": True,
|
| 170 |
+
"writable": False,
|
| 171 |
+
"readable": True,
|
| 172 |
+
"allow_dash": False,
|
| 173 |
+
},
|
| 174 |
+
id="Path ParamType",
|
| 175 |
+
),
|
| 176 |
+
pytest.param(
|
| 177 |
+
click.Tuple((click.STRING, click.INT)),
|
| 178 |
+
{
|
| 179 |
+
"param_type": "Tuple",
|
| 180 |
+
"name": "<text integer>",
|
| 181 |
+
"types": [STRING_PARAM_TYPE[1], INT_PARAM_TYPE[1]],
|
| 182 |
+
},
|
| 183 |
+
id="Tuple ParamType",
|
| 184 |
+
),
|
| 185 |
+
pytest.param(*NUMBER_OPTION, id="Option"),
|
| 186 |
+
pytest.param(
|
| 187 |
+
click.Option(["--cache/--no-cache", "-c/-u"]),
|
| 188 |
+
{
|
| 189 |
+
"name": "cache",
|
| 190 |
+
"param_type_name": "option",
|
| 191 |
+
"opts": ["--cache", "-c"],
|
| 192 |
+
"secondary_opts": ["--no-cache", "-u"],
|
| 193 |
+
"type": BOOL_PARAM_TYPE[1],
|
| 194 |
+
"required": False,
|
| 195 |
+
"nargs": 1,
|
| 196 |
+
"multiple": False,
|
| 197 |
+
"default": False,
|
| 198 |
+
"envvar": None,
|
| 199 |
+
"help": None,
|
| 200 |
+
"prompt": None,
|
| 201 |
+
"is_flag": True,
|
| 202 |
+
"flag_value": True,
|
| 203 |
+
"count": False,
|
| 204 |
+
"hidden": False,
|
| 205 |
+
},
|
| 206 |
+
id="Flag Option",
|
| 207 |
+
),
|
| 208 |
+
pytest.param(*NAME_ARGUMENT, id="Argument"),
|
| 209 |
+
],
|
| 210 |
+
)
|
| 211 |
+
def test_parameter(obj, expect):
|
| 212 |
+
out = obj.to_info_dict()
|
| 213 |
+
assert out == expect
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
@pytest.mark.parametrize(
|
| 217 |
+
("obj", "expect"),
|
| 218 |
+
[
|
| 219 |
+
pytest.param(*HELLO_COMMAND, id="Command"),
|
| 220 |
+
pytest.param(*HELLO_GROUP, id="Group"),
|
| 221 |
+
pytest.param(
|
| 222 |
+
click.Group(
|
| 223 |
+
"base",
|
| 224 |
+
[click.Command("test", params=[NAME_ARGUMENT[0]]), HELLO_GROUP[0]],
|
| 225 |
+
),
|
| 226 |
+
{
|
| 227 |
+
"name": "base",
|
| 228 |
+
"params": [HELP_OPTION[1]],
|
| 229 |
+
"help": None,
|
| 230 |
+
"epilog": None,
|
| 231 |
+
"short_help": None,
|
| 232 |
+
"hidden": False,
|
| 233 |
+
"deprecated": False,
|
| 234 |
+
"commands": {
|
| 235 |
+
"cli": HELLO_GROUP[1],
|
| 236 |
+
"test": {
|
| 237 |
+
"name": "test",
|
| 238 |
+
"params": [NAME_ARGUMENT[1], HELP_OPTION[1]],
|
| 239 |
+
"help": None,
|
| 240 |
+
"epilog": None,
|
| 241 |
+
"short_help": None,
|
| 242 |
+
"hidden": False,
|
| 243 |
+
"deprecated": False,
|
| 244 |
+
},
|
| 245 |
+
},
|
| 246 |
+
"chain": False,
|
| 247 |
+
},
|
| 248 |
+
id="Nested Group",
|
| 249 |
+
),
|
| 250 |
+
],
|
| 251 |
+
)
|
| 252 |
+
def test_command(obj, expect):
|
| 253 |
+
ctx = click.Context(obj)
|
| 254 |
+
out = obj.to_info_dict(ctx)
|
| 255 |
+
assert out == expect
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
def test_context():
|
| 259 |
+
ctx = click.Context(HELLO_COMMAND[0])
|
| 260 |
+
out = ctx.to_info_dict()
|
| 261 |
+
assert out == {
|
| 262 |
+
"command": HELLO_COMMAND[1],
|
| 263 |
+
"info_name": None,
|
| 264 |
+
"allow_extra_args": False,
|
| 265 |
+
"allow_interspersed_args": True,
|
| 266 |
+
"ignore_unknown_options": False,
|
| 267 |
+
"auto_envvar_prefix": None,
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
def test_paramtype_no_name():
|
| 272 |
+
class TestType(click.ParamType):
|
| 273 |
+
pass
|
| 274 |
+
|
| 275 |
+
assert TestType().to_info_dict()["name"] == "TestType"
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_normalization.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import click
|
| 2 |
+
|
| 3 |
+
CONTEXT_SETTINGS = dict(token_normalize_func=lambda x: x.lower())
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def test_option_normalization(runner):
|
| 7 |
+
@click.command(context_settings=CONTEXT_SETTINGS)
|
| 8 |
+
@click.option("--foo")
|
| 9 |
+
@click.option("-x")
|
| 10 |
+
def cli(foo, x):
|
| 11 |
+
click.echo(foo)
|
| 12 |
+
click.echo(x)
|
| 13 |
+
|
| 14 |
+
result = runner.invoke(cli, ["--FOO", "42", "-X", 23])
|
| 15 |
+
assert result.output == "42\n23\n"
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def test_choice_normalization(runner):
|
| 19 |
+
@click.command(context_settings=CONTEXT_SETTINGS)
|
| 20 |
+
@click.option("--choice", type=click.Choice(["Foo", "Bar"]))
|
| 21 |
+
def cli(choice):
|
| 22 |
+
click.echo(choice)
|
| 23 |
+
|
| 24 |
+
result = runner.invoke(cli, ["--CHOICE", "FOO"])
|
| 25 |
+
assert result.output == "Foo\n"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def test_command_normalization(runner):
|
| 29 |
+
@click.group(context_settings=CONTEXT_SETTINGS)
|
| 30 |
+
def cli():
|
| 31 |
+
pass
|
| 32 |
+
|
| 33 |
+
@cli.command()
|
| 34 |
+
def foo():
|
| 35 |
+
click.echo("here!")
|
| 36 |
+
|
| 37 |
+
result = runner.invoke(cli, ["FOO"])
|
| 38 |
+
assert result.output == "here!\n"
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_options.py
ADDED
|
@@ -0,0 +1,1017 @@
|
|
|
|
|
|
|
|
|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| 5 |
+
|
| 6 |
+
import click
|
| 7 |
+
from click import Option
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def test_prefixes(runner):
|
| 11 |
+
@click.command()
|
| 12 |
+
@click.option("++foo", is_flag=True, help="das foo")
|
| 13 |
+
@click.option("--bar", is_flag=True, help="das bar")
|
| 14 |
+
def cli(foo, bar):
|
| 15 |
+
click.echo(f"foo={foo} bar={bar}")
|
| 16 |
+
|
| 17 |
+
result = runner.invoke(cli, ["++foo", "--bar"])
|
| 18 |
+
assert not result.exception
|
| 19 |
+
assert result.output == "foo=True bar=True\n"
|
| 20 |
+
|
| 21 |
+
result = runner.invoke(cli, ["--help"])
|
| 22 |
+
assert re.search(r"\+\+foo\s+das foo", result.output) is not None
|
| 23 |
+
assert re.search(r"--bar\s+das bar", result.output) is not None
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def test_invalid_option(runner):
|
| 27 |
+
with pytest.raises(TypeError, match="name was passed") as exc_info:
|
| 28 |
+
click.Option(["foo"])
|
| 29 |
+
|
| 30 |
+
message = str(exc_info.value)
|
| 31 |
+
assert "name was passed (foo)" in message
|
| 32 |
+
assert "declare an argument" in message
|
| 33 |
+
assert "'--foo'" in message
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def test_invalid_nargs(runner):
|
| 37 |
+
with pytest.raises(TypeError, match="nargs=-1"):
|
| 38 |
+
|
| 39 |
+
@click.command()
|
| 40 |
+
@click.option("--foo", nargs=-1)
|
| 41 |
+
def cli(foo):
|
| 42 |
+
pass
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def test_nargs_tup_composite_mult(runner):
|
| 46 |
+
@click.command()
|
| 47 |
+
@click.option("--item", type=(str, int), multiple=True)
|
| 48 |
+
def copy(item):
|
| 49 |
+
for name, id in item:
|
| 50 |
+
click.echo(f"name={name} id={id:d}")
|
| 51 |
+
|
| 52 |
+
result = runner.invoke(copy, ["--item", "peter", "1", "--item", "max", "2"])
|
| 53 |
+
assert not result.exception
|
| 54 |
+
assert result.output.splitlines() == ["name=peter id=1", "name=max id=2"]
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def test_counting(runner):
|
| 58 |
+
@click.command()
|
| 59 |
+
@click.option("-v", count=True, help="Verbosity", type=click.IntRange(0, 3))
|
| 60 |
+
def cli(v):
|
| 61 |
+
click.echo(f"verbosity={v:d}")
|
| 62 |
+
|
| 63 |
+
result = runner.invoke(cli, ["-vvv"])
|
| 64 |
+
assert not result.exception
|
| 65 |
+
assert result.output == "verbosity=3\n"
|
| 66 |
+
|
| 67 |
+
result = runner.invoke(cli, ["-vvvv"])
|
| 68 |
+
assert result.exception
|
| 69 |
+
assert "Invalid value for '-v': 4 is not in the range 0<=x<=3." in result.output
|
| 70 |
+
|
| 71 |
+
result = runner.invoke(cli, [])
|
| 72 |
+
assert not result.exception
|
| 73 |
+
assert result.output == "verbosity=0\n"
|
| 74 |
+
|
| 75 |
+
result = runner.invoke(cli, ["--help"])
|
| 76 |
+
assert re.search(r"-v\s+Verbosity", result.output) is not None
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
@pytest.mark.parametrize("unknown_flag", ["--foo", "-f"])
|
| 80 |
+
def test_unknown_options(runner, unknown_flag):
|
| 81 |
+
@click.command()
|
| 82 |
+
def cli():
|
| 83 |
+
pass
|
| 84 |
+
|
| 85 |
+
result = runner.invoke(cli, [unknown_flag])
|
| 86 |
+
assert result.exception
|
| 87 |
+
assert f"No such option: {unknown_flag}" in result.output
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
@pytest.mark.parametrize(
|
| 91 |
+
("value", "expect"),
|
| 92 |
+
[
|
| 93 |
+
("--cat", "Did you mean --count?"),
|
| 94 |
+
("--bounds", "(Possible options: --bound, --count)"),
|
| 95 |
+
("--bount", "(Possible options: --bound, --count)"),
|
| 96 |
+
],
|
| 97 |
+
)
|
| 98 |
+
def test_suggest_possible_options(runner, value, expect):
|
| 99 |
+
cli = click.Command(
|
| 100 |
+
"cli", params=[click.Option(["--bound"]), click.Option(["--count"])]
|
| 101 |
+
)
|
| 102 |
+
result = runner.invoke(cli, [value])
|
| 103 |
+
assert expect in result.output
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def test_multiple_required(runner):
|
| 107 |
+
@click.command()
|
| 108 |
+
@click.option("-m", "--message", multiple=True, required=True)
|
| 109 |
+
def cli(message):
|
| 110 |
+
click.echo("\n".join(message))
|
| 111 |
+
|
| 112 |
+
result = runner.invoke(cli, ["-m", "foo", "-mbar"])
|
| 113 |
+
assert not result.exception
|
| 114 |
+
assert result.output == "foo\nbar\n"
|
| 115 |
+
|
| 116 |
+
result = runner.invoke(cli, [])
|
| 117 |
+
assert result.exception
|
| 118 |
+
assert "Error: Missing option '-m' / '--message'." in result.output
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
@pytest.mark.parametrize(
|
| 122 |
+
("multiple", "nargs", "default"),
|
| 123 |
+
[
|
| 124 |
+
(True, 1, []),
|
| 125 |
+
(True, 1, [1]),
|
| 126 |
+
# (False, -1, []),
|
| 127 |
+
# (False, -1, [1]),
|
| 128 |
+
(False, 2, [1, 2]),
|
| 129 |
+
# (True, -1, [[]]),
|
| 130 |
+
# (True, -1, []),
|
| 131 |
+
# (True, -1, [[1]]),
|
| 132 |
+
(True, 2, []),
|
| 133 |
+
(True, 2, [[1, 2]]),
|
| 134 |
+
],
|
| 135 |
+
)
|
| 136 |
+
def test_init_good_default_list(runner, multiple, nargs, default):
|
| 137 |
+
click.Option(["-a"], multiple=multiple, nargs=nargs, default=default)
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
@pytest.mark.parametrize(
|
| 141 |
+
("multiple", "nargs", "default"),
|
| 142 |
+
[
|
| 143 |
+
(True, 1, 1),
|
| 144 |
+
# (False, -1, 1),
|
| 145 |
+
(False, 2, [1]),
|
| 146 |
+
(True, 2, [[1]]),
|
| 147 |
+
],
|
| 148 |
+
)
|
| 149 |
+
def test_init_bad_default_list(runner, multiple, nargs, default):
|
| 150 |
+
type = (str, str) if nargs == 2 else None
|
| 151 |
+
|
| 152 |
+
with pytest.raises(ValueError, match="default"):
|
| 153 |
+
click.Option(["-a"], type=type, multiple=multiple, nargs=nargs, default=default)
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
@pytest.mark.parametrize("env_key", ["MYPATH", "AUTO_MYPATH"])
|
| 157 |
+
def test_empty_envvar(runner, env_key):
|
| 158 |
+
@click.command()
|
| 159 |
+
@click.option("--mypath", type=click.Path(exists=True), envvar="MYPATH")
|
| 160 |
+
def cli(mypath):
|
| 161 |
+
click.echo(f"mypath: {mypath}")
|
| 162 |
+
|
| 163 |
+
result = runner.invoke(cli, env={env_key: ""}, auto_envvar_prefix="AUTO")
|
| 164 |
+
assert result.exception is None
|
| 165 |
+
assert result.output == "mypath: None\n"
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
def test_multiple_envvar(runner):
|
| 169 |
+
@click.command()
|
| 170 |
+
@click.option("--arg", multiple=True)
|
| 171 |
+
def cmd(arg):
|
| 172 |
+
click.echo("|".join(arg))
|
| 173 |
+
|
| 174 |
+
result = runner.invoke(
|
| 175 |
+
cmd, [], auto_envvar_prefix="TEST", env={"TEST_ARG": "foo bar baz"}
|
| 176 |
+
)
|
| 177 |
+
assert not result.exception
|
| 178 |
+
assert result.output == "foo|bar|baz\n"
|
| 179 |
+
|
| 180 |
+
@click.command()
|
| 181 |
+
@click.option("--arg", multiple=True, envvar="X")
|
| 182 |
+
def cmd(arg):
|
| 183 |
+
click.echo("|".join(arg))
|
| 184 |
+
|
| 185 |
+
result = runner.invoke(cmd, [], env={"X": "foo bar baz"})
|
| 186 |
+
assert not result.exception
|
| 187 |
+
assert result.output == "foo|bar|baz\n"
|
| 188 |
+
|
| 189 |
+
@click.command()
|
| 190 |
+
@click.option("--arg", multiple=True, type=click.Path())
|
| 191 |
+
def cmd(arg):
|
| 192 |
+
click.echo("|".join(arg))
|
| 193 |
+
|
| 194 |
+
result = runner.invoke(
|
| 195 |
+
cmd,
|
| 196 |
+
[],
|
| 197 |
+
auto_envvar_prefix="TEST",
|
| 198 |
+
env={"TEST_ARG": f"foo{os.path.pathsep}bar"},
|
| 199 |
+
)
|
| 200 |
+
assert not result.exception
|
| 201 |
+
assert result.output == "foo|bar\n"
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def test_trailing_blanks_boolean_envvar(runner):
|
| 205 |
+
@click.command()
|
| 206 |
+
@click.option("--shout/--no-shout", envvar="SHOUT")
|
| 207 |
+
def cli(shout):
|
| 208 |
+
click.echo(f"shout: {shout!r}")
|
| 209 |
+
|
| 210 |
+
result = runner.invoke(cli, [], env={"SHOUT": " true "})
|
| 211 |
+
assert result.exit_code == 0
|
| 212 |
+
assert result.output == "shout: True\n"
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
def test_multiple_default_help(runner):
|
| 216 |
+
@click.command()
|
| 217 |
+
@click.option("--arg1", multiple=True, default=("foo", "bar"), show_default=True)
|
| 218 |
+
@click.option("--arg2", multiple=True, default=(1, 2), type=int, show_default=True)
|
| 219 |
+
def cmd(arg, arg2):
|
| 220 |
+
pass
|
| 221 |
+
|
| 222 |
+
result = runner.invoke(cmd, ["--help"])
|
| 223 |
+
assert not result.exception
|
| 224 |
+
assert "foo, bar" in result.output
|
| 225 |
+
assert "1, 2" in result.output
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
def test_show_default_default_map(runner):
|
| 229 |
+
@click.command()
|
| 230 |
+
@click.option("--arg", default="a", show_default=True)
|
| 231 |
+
def cmd(arg):
|
| 232 |
+
click.echo(arg)
|
| 233 |
+
|
| 234 |
+
result = runner.invoke(cmd, ["--help"], default_map={"arg": "b"})
|
| 235 |
+
|
| 236 |
+
assert not result.exception
|
| 237 |
+
assert "[default: b]" in result.output
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
def test_multiple_default_type():
|
| 241 |
+
opt = click.Option(["-a"], multiple=True, default=(1, 2))
|
| 242 |
+
assert opt.nargs == 1
|
| 243 |
+
assert opt.multiple
|
| 244 |
+
assert opt.type is click.INT
|
| 245 |
+
ctx = click.Context(click.Command("test"))
|
| 246 |
+
assert opt.get_default(ctx) == (1, 2)
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def test_multiple_default_composite_type():
|
| 250 |
+
opt = click.Option(["-a"], multiple=True, default=[(1, "a")])
|
| 251 |
+
assert opt.nargs == 2
|
| 252 |
+
assert opt.multiple
|
| 253 |
+
assert isinstance(opt.type, click.Tuple)
|
| 254 |
+
assert opt.type.types == [click.INT, click.STRING]
|
| 255 |
+
ctx = click.Context(click.Command("test"))
|
| 256 |
+
assert opt.type_cast_value(ctx, opt.get_default(ctx)) == ((1, "a"),)
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
def test_parse_multiple_default_composite_type(runner):
|
| 260 |
+
@click.command()
|
| 261 |
+
@click.option("-a", multiple=True, default=("a", "b"))
|
| 262 |
+
@click.option("-b", multiple=True, default=[(1, "a")])
|
| 263 |
+
def cmd(a, b):
|
| 264 |
+
click.echo(a)
|
| 265 |
+
click.echo(b)
|
| 266 |
+
|
| 267 |
+
# result = runner.invoke(cmd, "-a c -a 1 -a d -b 2 two -b 4 four".split())
|
| 268 |
+
# assert result.output == "('c', '1', 'd')\n((2, 'two'), (4, 'four'))\n"
|
| 269 |
+
result = runner.invoke(cmd)
|
| 270 |
+
assert result.output == "('a', 'b')\n((1, 'a'),)\n"
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
def test_dynamic_default_help_unset(runner):
|
| 274 |
+
@click.command()
|
| 275 |
+
@click.option(
|
| 276 |
+
"--username",
|
| 277 |
+
prompt=True,
|
| 278 |
+
default=lambda: os.environ.get("USER", ""),
|
| 279 |
+
show_default=True,
|
| 280 |
+
)
|
| 281 |
+
def cmd(username):
|
| 282 |
+
print("Hello,", username)
|
| 283 |
+
|
| 284 |
+
result = runner.invoke(cmd, ["--help"])
|
| 285 |
+
assert result.exit_code == 0
|
| 286 |
+
assert "--username" in result.output
|
| 287 |
+
assert "lambda" not in result.output
|
| 288 |
+
assert "(dynamic)" in result.output
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
def test_dynamic_default_help_text(runner):
|
| 292 |
+
@click.command()
|
| 293 |
+
@click.option(
|
| 294 |
+
"--username",
|
| 295 |
+
prompt=True,
|
| 296 |
+
default=lambda: os.environ.get("USER", ""),
|
| 297 |
+
show_default="current user",
|
| 298 |
+
)
|
| 299 |
+
def cmd(username):
|
| 300 |
+
print("Hello,", username)
|
| 301 |
+
|
| 302 |
+
result = runner.invoke(cmd, ["--help"])
|
| 303 |
+
assert result.exit_code == 0
|
| 304 |
+
assert "--username" in result.output
|
| 305 |
+
assert "lambda" not in result.output
|
| 306 |
+
assert "(current user)" in result.output
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
def test_dynamic_default_help_special_method(runner):
|
| 310 |
+
class Value:
|
| 311 |
+
def __call__(self):
|
| 312 |
+
return 42
|
| 313 |
+
|
| 314 |
+
def __str__(self):
|
| 315 |
+
return "special value"
|
| 316 |
+
|
| 317 |
+
opt = click.Option(["-a"], default=Value(), show_default=True)
|
| 318 |
+
ctx = click.Context(click.Command("cli"))
|
| 319 |
+
assert opt.get_help_extra(ctx) == {"default": "special value"}
|
| 320 |
+
assert "special value" in opt.get_help_record(ctx)[1]
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
@pytest.mark.parametrize(
|
| 324 |
+
("type", "expect"),
|
| 325 |
+
[
|
| 326 |
+
(click.IntRange(1, 32), "1<=x<=32"),
|
| 327 |
+
(click.IntRange(1, 32, min_open=True, max_open=True), "1<x<32"),
|
| 328 |
+
(click.IntRange(1), "x>=1"),
|
| 329 |
+
(click.IntRange(max=32), "x<=32"),
|
| 330 |
+
],
|
| 331 |
+
)
|
| 332 |
+
def test_intrange_default_help_text(type, expect):
|
| 333 |
+
option = click.Option(["--num"], type=type, show_default=True, default=2)
|
| 334 |
+
context = click.Context(click.Command("test"))
|
| 335 |
+
assert option.get_help_extra(context) == {"default": "2", "range": expect}
|
| 336 |
+
result = option.get_help_record(context)[1]
|
| 337 |
+
assert expect in result
|
| 338 |
+
|
| 339 |
+
|
| 340 |
+
def test_count_default_type_help():
|
| 341 |
+
"""A count option with the default type should not show >=0 in help."""
|
| 342 |
+
option = click.Option(["--count"], count=True, help="some words")
|
| 343 |
+
context = click.Context(click.Command("test"))
|
| 344 |
+
assert option.get_help_extra(context) == {}
|
| 345 |
+
result = option.get_help_record(context)[1]
|
| 346 |
+
assert result == "some words"
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
def test_file_type_help_default():
|
| 350 |
+
"""The default for a File type is a filename string. The string
|
| 351 |
+
should be displayed in help, not an open file object.
|
| 352 |
+
|
| 353 |
+
Type casting is only applied to defaults in processing, not when
|
| 354 |
+
getting the default value.
|
| 355 |
+
"""
|
| 356 |
+
option = click.Option(
|
| 357 |
+
["--in"], type=click.File(), default=__file__, show_default=True
|
| 358 |
+
)
|
| 359 |
+
context = click.Context(click.Command("test"))
|
| 360 |
+
assert option.get_help_extra(context) == {"default": __file__}
|
| 361 |
+
result = option.get_help_record(context)[1]
|
| 362 |
+
assert __file__ in result
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
def test_toupper_envvar_prefix(runner):
|
| 366 |
+
@click.command()
|
| 367 |
+
@click.option("--arg")
|
| 368 |
+
def cmd(arg):
|
| 369 |
+
click.echo(arg)
|
| 370 |
+
|
| 371 |
+
result = runner.invoke(cmd, [], auto_envvar_prefix="test", env={"TEST_ARG": "foo"})
|
| 372 |
+
assert not result.exception
|
| 373 |
+
assert result.output == "foo\n"
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
def test_nargs_envvar(runner):
|
| 377 |
+
@click.command()
|
| 378 |
+
@click.option("--arg", nargs=2)
|
| 379 |
+
def cmd(arg):
|
| 380 |
+
click.echo("|".join(arg))
|
| 381 |
+
|
| 382 |
+
result = runner.invoke(
|
| 383 |
+
cmd, [], auto_envvar_prefix="TEST", env={"TEST_ARG": "foo bar"}
|
| 384 |
+
)
|
| 385 |
+
assert not result.exception
|
| 386 |
+
assert result.output == "foo|bar\n"
|
| 387 |
+
|
| 388 |
+
@click.command()
|
| 389 |
+
@click.option("--arg", nargs=2, multiple=True)
|
| 390 |
+
def cmd(arg):
|
| 391 |
+
for item in arg:
|
| 392 |
+
click.echo("|".join(item))
|
| 393 |
+
|
| 394 |
+
result = runner.invoke(
|
| 395 |
+
cmd, [], auto_envvar_prefix="TEST", env={"TEST_ARG": "x 1 y 2"}
|
| 396 |
+
)
|
| 397 |
+
assert not result.exception
|
| 398 |
+
assert result.output == "x|1\ny|2\n"
|
| 399 |
+
|
| 400 |
+
|
| 401 |
+
def test_show_envvar(runner):
|
| 402 |
+
@click.command()
|
| 403 |
+
@click.option("--arg1", envvar="ARG1", show_envvar=True)
|
| 404 |
+
def cmd(arg):
|
| 405 |
+
pass
|
| 406 |
+
|
| 407 |
+
result = runner.invoke(cmd, ["--help"])
|
| 408 |
+
assert not result.exception
|
| 409 |
+
assert "ARG1" in result.output
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
def test_show_envvar_auto_prefix(runner):
|
| 413 |
+
@click.command()
|
| 414 |
+
@click.option("--arg1", show_envvar=True)
|
| 415 |
+
def cmd(arg):
|
| 416 |
+
pass
|
| 417 |
+
|
| 418 |
+
result = runner.invoke(cmd, ["--help"], auto_envvar_prefix="TEST")
|
| 419 |
+
assert not result.exception
|
| 420 |
+
assert "TEST_ARG1" in result.output
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
def test_show_envvar_auto_prefix_dash_in_command(runner):
|
| 424 |
+
@click.group()
|
| 425 |
+
def cli():
|
| 426 |
+
pass
|
| 427 |
+
|
| 428 |
+
@cli.command()
|
| 429 |
+
@click.option("--baz", show_envvar=True)
|
| 430 |
+
def foo_bar(baz):
|
| 431 |
+
pass
|
| 432 |
+
|
| 433 |
+
result = runner.invoke(cli, ["foo-bar", "--help"], auto_envvar_prefix="TEST")
|
| 434 |
+
assert not result.exception
|
| 435 |
+
assert "TEST_FOO_BAR_BAZ" in result.output
|
| 436 |
+
|
| 437 |
+
|
| 438 |
+
def test_custom_validation(runner):
|
| 439 |
+
def validate_pos_int(ctx, param, value):
|
| 440 |
+
if value < 0:
|
| 441 |
+
raise click.BadParameter("Value needs to be positive")
|
| 442 |
+
return value
|
| 443 |
+
|
| 444 |
+
@click.command()
|
| 445 |
+
@click.option("--foo", callback=validate_pos_int, default=1)
|
| 446 |
+
def cmd(foo):
|
| 447 |
+
click.echo(foo)
|
| 448 |
+
|
| 449 |
+
result = runner.invoke(cmd, ["--foo", "-1"])
|
| 450 |
+
assert "Invalid value for '--foo': Value needs to be positive" in result.output
|
| 451 |
+
|
| 452 |
+
result = runner.invoke(cmd, ["--foo", "42"])
|
| 453 |
+
assert result.output == "42\n"
|
| 454 |
+
|
| 455 |
+
|
| 456 |
+
def test_callback_validates_prompt(runner, monkeypatch):
|
| 457 |
+
def validate(ctx, param, value):
|
| 458 |
+
if value < 0:
|
| 459 |
+
raise click.BadParameter("should be positive")
|
| 460 |
+
|
| 461 |
+
return value
|
| 462 |
+
|
| 463 |
+
@click.command()
|
| 464 |
+
@click.option("-a", type=int, callback=validate, prompt=True)
|
| 465 |
+
def cli(a):
|
| 466 |
+
click.echo(a)
|
| 467 |
+
|
| 468 |
+
result = runner.invoke(cli, input="-12\n60\n")
|
| 469 |
+
assert result.output == "A: -12\nError: should be positive\nA: 60\n60\n"
|
| 470 |
+
|
| 471 |
+
|
| 472 |
+
def test_winstyle_options(runner):
|
| 473 |
+
@click.command()
|
| 474 |
+
@click.option("/debug;/no-debug", help="Enables or disables debug mode.")
|
| 475 |
+
def cmd(debug):
|
| 476 |
+
click.echo(debug)
|
| 477 |
+
|
| 478 |
+
result = runner.invoke(cmd, ["/debug"], help_option_names=["/?"])
|
| 479 |
+
assert result.output == "True\n"
|
| 480 |
+
result = runner.invoke(cmd, ["/no-debug"], help_option_names=["/?"])
|
| 481 |
+
assert result.output == "False\n"
|
| 482 |
+
result = runner.invoke(cmd, [], help_option_names=["/?"])
|
| 483 |
+
assert result.output == "False\n"
|
| 484 |
+
result = runner.invoke(cmd, ["/?"], help_option_names=["/?"])
|
| 485 |
+
assert "/debug; /no-debug Enables or disables debug mode." in result.output
|
| 486 |
+
assert "/? Show this message and exit." in result.output
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
def test_legacy_options(runner):
|
| 490 |
+
@click.command()
|
| 491 |
+
@click.option("-whatever")
|
| 492 |
+
def cmd(whatever):
|
| 493 |
+
click.echo(whatever)
|
| 494 |
+
|
| 495 |
+
result = runner.invoke(cmd, ["-whatever", "42"])
|
| 496 |
+
assert result.output == "42\n"
|
| 497 |
+
result = runner.invoke(cmd, ["-whatever=23"])
|
| 498 |
+
assert result.output == "23\n"
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
def test_missing_option_string_cast():
|
| 502 |
+
ctx = click.Context(click.Command(""))
|
| 503 |
+
|
| 504 |
+
with pytest.raises(click.MissingParameter) as excinfo:
|
| 505 |
+
click.Option(["-a"], required=True).process_value(ctx, None)
|
| 506 |
+
|
| 507 |
+
assert str(excinfo.value) == "Missing parameter: a"
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
def test_missing_required_flag(runner):
|
| 511 |
+
cli = click.Command(
|
| 512 |
+
"cli", params=[click.Option(["--on/--off"], is_flag=True, required=True)]
|
| 513 |
+
)
|
| 514 |
+
result = runner.invoke(cli)
|
| 515 |
+
assert result.exit_code == 2
|
| 516 |
+
assert "Error: Missing option '--on'." in result.output
|
| 517 |
+
|
| 518 |
+
|
| 519 |
+
def test_missing_choice(runner):
|
| 520 |
+
@click.command()
|
| 521 |
+
@click.option("--foo", type=click.Choice(["foo", "bar"]), required=True)
|
| 522 |
+
def cmd(foo):
|
| 523 |
+
click.echo(foo)
|
| 524 |
+
|
| 525 |
+
result = runner.invoke(cmd)
|
| 526 |
+
assert result.exit_code == 2
|
| 527 |
+
error, separator, choices = result.output.partition("Choose from")
|
| 528 |
+
assert "Error: Missing option '--foo'. " in error
|
| 529 |
+
assert "Choose from" in separator
|
| 530 |
+
assert "foo" in choices
|
| 531 |
+
assert "bar" in choices
|
| 532 |
+
|
| 533 |
+
|
| 534 |
+
def test_missing_envvar(runner):
|
| 535 |
+
cli = click.Command(
|
| 536 |
+
"cli", params=[click.Option(["--foo"], envvar="bar", required=True)]
|
| 537 |
+
)
|
| 538 |
+
result = runner.invoke(cli)
|
| 539 |
+
assert result.exit_code == 2
|
| 540 |
+
assert "Error: Missing option '--foo'." in result.output
|
| 541 |
+
cli = click.Command(
|
| 542 |
+
"cli",
|
| 543 |
+
params=[click.Option(["--foo"], envvar="bar", show_envvar=True, required=True)],
|
| 544 |
+
)
|
| 545 |
+
result = runner.invoke(cli)
|
| 546 |
+
assert result.exit_code == 2
|
| 547 |
+
assert "Error: Missing option '--foo' (env var: 'bar')." in result.output
|
| 548 |
+
|
| 549 |
+
|
| 550 |
+
def test_case_insensitive_choice(runner):
|
| 551 |
+
@click.command()
|
| 552 |
+
@click.option("--foo", type=click.Choice(["Orange", "Apple"], case_sensitive=False))
|
| 553 |
+
def cmd(foo):
|
| 554 |
+
click.echo(foo)
|
| 555 |
+
|
| 556 |
+
result = runner.invoke(cmd, ["--foo", "apple"])
|
| 557 |
+
assert result.exit_code == 0
|
| 558 |
+
assert result.output == "Apple\n"
|
| 559 |
+
|
| 560 |
+
result = runner.invoke(cmd, ["--foo", "oRANGe"])
|
| 561 |
+
assert result.exit_code == 0
|
| 562 |
+
assert result.output == "Orange\n"
|
| 563 |
+
|
| 564 |
+
result = runner.invoke(cmd, ["--foo", "Apple"])
|
| 565 |
+
assert result.exit_code == 0
|
| 566 |
+
assert result.output == "Apple\n"
|
| 567 |
+
|
| 568 |
+
@click.command()
|
| 569 |
+
@click.option("--foo", type=click.Choice(["Orange", "Apple"]))
|
| 570 |
+
def cmd2(foo):
|
| 571 |
+
click.echo(foo)
|
| 572 |
+
|
| 573 |
+
result = runner.invoke(cmd2, ["--foo", "apple"])
|
| 574 |
+
assert result.exit_code == 2
|
| 575 |
+
|
| 576 |
+
result = runner.invoke(cmd2, ["--foo", "oRANGe"])
|
| 577 |
+
assert result.exit_code == 2
|
| 578 |
+
|
| 579 |
+
result = runner.invoke(cmd2, ["--foo", "Apple"])
|
| 580 |
+
assert result.exit_code == 0
|
| 581 |
+
|
| 582 |
+
|
| 583 |
+
def test_case_insensitive_choice_returned_exactly(runner):
|
| 584 |
+
@click.command()
|
| 585 |
+
@click.option("--foo", type=click.Choice(["Orange", "Apple"], case_sensitive=False))
|
| 586 |
+
def cmd(foo):
|
| 587 |
+
click.echo(foo)
|
| 588 |
+
|
| 589 |
+
result = runner.invoke(cmd, ["--foo", "apple"])
|
| 590 |
+
assert result.exit_code == 0
|
| 591 |
+
assert result.output == "Apple\n"
|
| 592 |
+
|
| 593 |
+
|
| 594 |
+
def test_option_help_preserve_paragraphs(runner):
|
| 595 |
+
@click.command()
|
| 596 |
+
@click.option(
|
| 597 |
+
"-C",
|
| 598 |
+
"--config",
|
| 599 |
+
type=click.Path(),
|
| 600 |
+
help="""Configuration file to use.
|
| 601 |
+
|
| 602 |
+
If not given, the environment variable CONFIG_FILE is consulted
|
| 603 |
+
and used if set. If neither are given, a default configuration
|
| 604 |
+
file is loaded.""",
|
| 605 |
+
)
|
| 606 |
+
def cmd(config):
|
| 607 |
+
pass
|
| 608 |
+
|
| 609 |
+
result = runner.invoke(cmd, ["--help"])
|
| 610 |
+
assert result.exit_code == 0
|
| 611 |
+
i = " " * 21
|
| 612 |
+
assert (
|
| 613 |
+
" -C, --config PATH Configuration file to use.\n"
|
| 614 |
+
f"{i}\n"
|
| 615 |
+
f"{i}If not given, the environment variable CONFIG_FILE is\n"
|
| 616 |
+
f"{i}consulted and used if set. If neither are given, a default\n"
|
| 617 |
+
f"{i}configuration file is loaded."
|
| 618 |
+
) in result.output
|
| 619 |
+
|
| 620 |
+
|
| 621 |
+
def test_argument_custom_class(runner):
|
| 622 |
+
class CustomArgument(click.Argument):
|
| 623 |
+
def get_default(self, ctx, call=True):
|
| 624 |
+
"""a dumb override of a default value for testing"""
|
| 625 |
+
return "I am a default"
|
| 626 |
+
|
| 627 |
+
@click.command()
|
| 628 |
+
@click.argument("testarg", cls=CustomArgument, default="you wont see me")
|
| 629 |
+
def cmd(testarg):
|
| 630 |
+
click.echo(testarg)
|
| 631 |
+
|
| 632 |
+
result = runner.invoke(cmd)
|
| 633 |
+
assert "I am a default" in result.output
|
| 634 |
+
assert "you wont see me" not in result.output
|
| 635 |
+
|
| 636 |
+
|
| 637 |
+
def test_option_custom_class(runner):
|
| 638 |
+
class CustomOption(click.Option):
|
| 639 |
+
def get_help_record(self, ctx):
|
| 640 |
+
"""a dumb override of a help text for testing"""
|
| 641 |
+
return ("--help", "I am a help text")
|
| 642 |
+
|
| 643 |
+
@click.command()
|
| 644 |
+
@click.option("--testoption", cls=CustomOption, help="you wont see me")
|
| 645 |
+
def cmd(testoption):
|
| 646 |
+
click.echo(testoption)
|
| 647 |
+
|
| 648 |
+
result = runner.invoke(cmd, ["--help"])
|
| 649 |
+
assert "I am a help text" in result.output
|
| 650 |
+
assert "you wont see me" not in result.output
|
| 651 |
+
|
| 652 |
+
|
| 653 |
+
def test_option_custom_class_reusable(runner):
|
| 654 |
+
"""Ensure we can reuse a custom class option. See Issue #926"""
|
| 655 |
+
|
| 656 |
+
class CustomOption(click.Option):
|
| 657 |
+
def get_help_record(self, ctx):
|
| 658 |
+
"""a dumb override of a help text for testing"""
|
| 659 |
+
return ("--help", "I am a help text")
|
| 660 |
+
|
| 661 |
+
# Assign to a variable to re-use the decorator.
|
| 662 |
+
testoption = click.option("--testoption", cls=CustomOption, help="you wont see me")
|
| 663 |
+
|
| 664 |
+
@click.command()
|
| 665 |
+
@testoption
|
| 666 |
+
def cmd1(testoption):
|
| 667 |
+
click.echo(testoption)
|
| 668 |
+
|
| 669 |
+
@click.command()
|
| 670 |
+
@testoption
|
| 671 |
+
def cmd2(testoption):
|
| 672 |
+
click.echo(testoption)
|
| 673 |
+
|
| 674 |
+
# Both of the commands should have the --help option now.
|
| 675 |
+
for cmd in (cmd1, cmd2):
|
| 676 |
+
result = runner.invoke(cmd, ["--help"])
|
| 677 |
+
assert "I am a help text" in result.output
|
| 678 |
+
assert "you wont see me" not in result.output
|
| 679 |
+
|
| 680 |
+
|
| 681 |
+
def test_bool_flag_with_type(runner):
|
| 682 |
+
@click.command()
|
| 683 |
+
@click.option("--shout/--no-shout", default=False, type=bool)
|
| 684 |
+
def cmd(shout):
|
| 685 |
+
pass
|
| 686 |
+
|
| 687 |
+
result = runner.invoke(cmd)
|
| 688 |
+
assert not result.exception
|
| 689 |
+
|
| 690 |
+
|
| 691 |
+
def test_aliases_for_flags(runner):
|
| 692 |
+
@click.command()
|
| 693 |
+
@click.option("--warnings/--no-warnings", " /-W", default=True)
|
| 694 |
+
def cli(warnings):
|
| 695 |
+
click.echo(warnings)
|
| 696 |
+
|
| 697 |
+
result = runner.invoke(cli, ["--warnings"])
|
| 698 |
+
assert result.output == "True\n"
|
| 699 |
+
result = runner.invoke(cli, ["--no-warnings"])
|
| 700 |
+
assert result.output == "False\n"
|
| 701 |
+
result = runner.invoke(cli, ["-W"])
|
| 702 |
+
assert result.output == "False\n"
|
| 703 |
+
|
| 704 |
+
@click.command()
|
| 705 |
+
@click.option("--warnings/--no-warnings", "-w", default=True)
|
| 706 |
+
def cli_alt(warnings):
|
| 707 |
+
click.echo(warnings)
|
| 708 |
+
|
| 709 |
+
result = runner.invoke(cli_alt, ["--warnings"])
|
| 710 |
+
assert result.output == "True\n"
|
| 711 |
+
result = runner.invoke(cli_alt, ["--no-warnings"])
|
| 712 |
+
assert result.output == "False\n"
|
| 713 |
+
result = runner.invoke(cli_alt, ["-w"])
|
| 714 |
+
assert result.output == "True\n"
|
| 715 |
+
|
| 716 |
+
|
| 717 |
+
@pytest.mark.parametrize(
|
| 718 |
+
"option_args,expected",
|
| 719 |
+
[
|
| 720 |
+
(["--aggressive", "--all", "-a"], "aggressive"),
|
| 721 |
+
(["--first", "--second", "--third", "-a", "-b", "-c"], "first"),
|
| 722 |
+
(["--apple", "--banana", "--cantaloupe", "-a", "-b", "-c"], "apple"),
|
| 723 |
+
(["--cantaloupe", "--banana", "--apple", "-c", "-b", "-a"], "cantaloupe"),
|
| 724 |
+
(["-a", "-b", "-c"], "a"),
|
| 725 |
+
(["-c", "-b", "-a"], "c"),
|
| 726 |
+
(["-a", "--apple", "-b", "--banana", "-c", "--cantaloupe"], "apple"),
|
| 727 |
+
(["-c", "-a", "--cantaloupe", "-b", "--banana", "--apple"], "cantaloupe"),
|
| 728 |
+
(["--from", "-f", "_from"], "_from"),
|
| 729 |
+
(["--return", "-r", "_ret"], "_ret"),
|
| 730 |
+
],
|
| 731 |
+
)
|
| 732 |
+
def test_option_names(runner, option_args, expected):
|
| 733 |
+
@click.command()
|
| 734 |
+
@click.option(*option_args, is_flag=True)
|
| 735 |
+
def cmd(**kwargs):
|
| 736 |
+
click.echo(str(kwargs[expected]))
|
| 737 |
+
|
| 738 |
+
assert cmd.params[0].name == expected
|
| 739 |
+
|
| 740 |
+
for form in option_args:
|
| 741 |
+
if form.startswith("-"):
|
| 742 |
+
result = runner.invoke(cmd, [form])
|
| 743 |
+
assert result.output == "True\n"
|
| 744 |
+
|
| 745 |
+
|
| 746 |
+
def test_flag_duplicate_names(runner):
|
| 747 |
+
with pytest.raises(ValueError, match="cannot use the same flag for true/false"):
|
| 748 |
+
click.Option(["--foo/--foo"], default=False)
|
| 749 |
+
|
| 750 |
+
|
| 751 |
+
@pytest.mark.parametrize(("default", "expect"), [(False, "no-cache"), (True, "cache")])
|
| 752 |
+
def test_show_default_boolean_flag_name(runner, default, expect):
|
| 753 |
+
"""When a boolean flag has distinct True/False opts, it should show
|
| 754 |
+
the default opt name instead of the default value. It should only
|
| 755 |
+
show one name even if multiple are declared.
|
| 756 |
+
"""
|
| 757 |
+
opt = click.Option(
|
| 758 |
+
("--cache/--no-cache", "--c/--nc"),
|
| 759 |
+
default=default,
|
| 760 |
+
show_default=True,
|
| 761 |
+
help="Enable/Disable the cache.",
|
| 762 |
+
)
|
| 763 |
+
ctx = click.Context(click.Command("test"))
|
| 764 |
+
assert opt.get_help_extra(ctx) == {"default": expect}
|
| 765 |
+
message = opt.get_help_record(ctx)[1]
|
| 766 |
+
assert f"[default: {expect}]" in message
|
| 767 |
+
|
| 768 |
+
|
| 769 |
+
def test_show_true_default_boolean_flag_value(runner):
|
| 770 |
+
"""When a boolean flag only has one opt and its default is True,
|
| 771 |
+
it will show the default value, not the opt name.
|
| 772 |
+
"""
|
| 773 |
+
opt = click.Option(
|
| 774 |
+
("--cache",),
|
| 775 |
+
is_flag=True,
|
| 776 |
+
show_default=True,
|
| 777 |
+
default=True,
|
| 778 |
+
help="Enable the cache.",
|
| 779 |
+
)
|
| 780 |
+
ctx = click.Context(click.Command("test"))
|
| 781 |
+
assert opt.get_help_extra(ctx) == {"default": "True"}
|
| 782 |
+
message = opt.get_help_record(ctx)[1]
|
| 783 |
+
assert "[default: True]" in message
|
| 784 |
+
|
| 785 |
+
|
| 786 |
+
@pytest.mark.parametrize("default", [False, None])
|
| 787 |
+
def test_hide_false_default_boolean_flag_value(runner, default):
|
| 788 |
+
"""When a boolean flag only has one opt and its default is False or
|
| 789 |
+
None, it will not show the default
|
| 790 |
+
"""
|
| 791 |
+
opt = click.Option(
|
| 792 |
+
("--cache",),
|
| 793 |
+
is_flag=True,
|
| 794 |
+
show_default=True,
|
| 795 |
+
default=default,
|
| 796 |
+
help="Enable the cache.",
|
| 797 |
+
)
|
| 798 |
+
ctx = click.Context(click.Command("test"))
|
| 799 |
+
assert opt.get_help_extra(ctx) == {}
|
| 800 |
+
message = opt.get_help_record(ctx)[1]
|
| 801 |
+
assert "[default: " not in message
|
| 802 |
+
|
| 803 |
+
|
| 804 |
+
def test_show_default_string(runner):
|
| 805 |
+
"""When show_default is a string show that value as default."""
|
| 806 |
+
opt = click.Option(["--limit"], show_default="unlimited")
|
| 807 |
+
ctx = click.Context(click.Command("cli"))
|
| 808 |
+
assert opt.get_help_extra(ctx) == {"default": "(unlimited)"}
|
| 809 |
+
message = opt.get_help_record(ctx)[1]
|
| 810 |
+
assert "[default: (unlimited)]" in message
|
| 811 |
+
|
| 812 |
+
|
| 813 |
+
def test_show_default_with_empty_string(runner):
|
| 814 |
+
"""When show_default is True and default is set to an empty string."""
|
| 815 |
+
opt = click.Option(["--limit"], default="", show_default=True)
|
| 816 |
+
ctx = click.Context(click.Command("cli"))
|
| 817 |
+
message = opt.get_help_record(ctx)[1]
|
| 818 |
+
assert '[default: ""]' in message
|
| 819 |
+
|
| 820 |
+
|
| 821 |
+
def test_do_not_show_no_default(runner):
|
| 822 |
+
"""When show_default is True and no default is set do not show None."""
|
| 823 |
+
opt = click.Option(["--limit"], show_default=True)
|
| 824 |
+
ctx = click.Context(click.Command("cli"))
|
| 825 |
+
assert opt.get_help_extra(ctx) == {}
|
| 826 |
+
message = opt.get_help_record(ctx)[1]
|
| 827 |
+
assert "[default: None]" not in message
|
| 828 |
+
|
| 829 |
+
|
| 830 |
+
def test_do_not_show_default_empty_multiple():
|
| 831 |
+
"""When show_default is True and multiple=True is set, it should not
|
| 832 |
+
print empty default value in --help output.
|
| 833 |
+
"""
|
| 834 |
+
opt = click.Option(["-a"], multiple=True, help="values", show_default=True)
|
| 835 |
+
ctx = click.Context(click.Command("cli"))
|
| 836 |
+
assert opt.get_help_extra(ctx) == {}
|
| 837 |
+
message = opt.get_help_record(ctx)[1]
|
| 838 |
+
assert message == "values"
|
| 839 |
+
|
| 840 |
+
|
| 841 |
+
@pytest.mark.parametrize(
|
| 842 |
+
("ctx_value", "opt_value", "extra_value", "expect"),
|
| 843 |
+
[
|
| 844 |
+
(None, None, {}, False),
|
| 845 |
+
(None, False, {}, False),
|
| 846 |
+
(None, True, {"default": "1"}, True),
|
| 847 |
+
(False, None, {}, False),
|
| 848 |
+
(False, False, {}, False),
|
| 849 |
+
(False, True, {"default": "1"}, True),
|
| 850 |
+
(True, None, {"default": "1"}, True),
|
| 851 |
+
(True, False, {}, False),
|
| 852 |
+
(True, True, {"default": "1"}, True),
|
| 853 |
+
(False, "one", {"default": "(one)"}, True),
|
| 854 |
+
],
|
| 855 |
+
)
|
| 856 |
+
def test_show_default_precedence(ctx_value, opt_value, extra_value, expect):
|
| 857 |
+
ctx = click.Context(click.Command("test"), show_default=ctx_value)
|
| 858 |
+
opt = click.Option("-a", default=1, help="value", show_default=opt_value)
|
| 859 |
+
assert opt.get_help_extra(ctx) == extra_value
|
| 860 |
+
help = opt.get_help_record(ctx)[1]
|
| 861 |
+
assert ("default:" in help) is expect
|
| 862 |
+
|
| 863 |
+
|
| 864 |
+
@pytest.mark.parametrize(
|
| 865 |
+
("args", "expect"),
|
| 866 |
+
[
|
| 867 |
+
(None, (None, None, ())),
|
| 868 |
+
(["--opt"], ("flag", None, ())),
|
| 869 |
+
(["--opt", "-a", 42], ("flag", "42", ())),
|
| 870 |
+
(["--opt", "test", "-a", 42], ("test", "42", ())),
|
| 871 |
+
(["--opt=test", "-a", 42], ("test", "42", ())),
|
| 872 |
+
(["-o"], ("flag", None, ())),
|
| 873 |
+
(["-o", "-a", 42], ("flag", "42", ())),
|
| 874 |
+
(["-o", "test", "-a", 42], ("test", "42", ())),
|
| 875 |
+
(["-otest", "-a", 42], ("test", "42", ())),
|
| 876 |
+
(["a", "b", "c"], (None, None, ("a", "b", "c"))),
|
| 877 |
+
(["--opt", "a", "b", "c"], ("a", None, ("b", "c"))),
|
| 878 |
+
(["--opt", "test"], ("test", None, ())),
|
| 879 |
+
(["-otest", "a", "b", "c"], ("test", None, ("a", "b", "c"))),
|
| 880 |
+
(["--opt=test", "a", "b", "c"], ("test", None, ("a", "b", "c"))),
|
| 881 |
+
],
|
| 882 |
+
)
|
| 883 |
+
def test_option_with_optional_value(runner, args, expect):
|
| 884 |
+
@click.command()
|
| 885 |
+
@click.option("-o", "--opt", is_flag=False, flag_value="flag")
|
| 886 |
+
@click.option("-a")
|
| 887 |
+
@click.argument("b", nargs=-1)
|
| 888 |
+
def cli(opt, a, b):
|
| 889 |
+
return opt, a, b
|
| 890 |
+
|
| 891 |
+
result = runner.invoke(cli, args, standalone_mode=False, catch_exceptions=False)
|
| 892 |
+
assert result.return_value == expect
|
| 893 |
+
|
| 894 |
+
|
| 895 |
+
def test_multiple_option_with_optional_value(runner):
|
| 896 |
+
cli = click.Command(
|
| 897 |
+
"cli",
|
| 898 |
+
params=[
|
| 899 |
+
click.Option(["-f"], is_flag=False, flag_value="flag", multiple=True),
|
| 900 |
+
click.Option(["-a"]),
|
| 901 |
+
click.Argument(["b"], nargs=-1),
|
| 902 |
+
],
|
| 903 |
+
callback=lambda **kwargs: kwargs,
|
| 904 |
+
)
|
| 905 |
+
result = runner.invoke(
|
| 906 |
+
cli,
|
| 907 |
+
["-f", "-f", "other", "-f", "-a", "1", "a", "b"],
|
| 908 |
+
standalone_mode=False,
|
| 909 |
+
catch_exceptions=False,
|
| 910 |
+
)
|
| 911 |
+
assert result.return_value == {
|
| 912 |
+
"f": ("flag", "other", "flag"),
|
| 913 |
+
"a": "1",
|
| 914 |
+
"b": ("a", "b"),
|
| 915 |
+
}
|
| 916 |
+
|
| 917 |
+
|
| 918 |
+
def test_type_from_flag_value():
|
| 919 |
+
param = click.Option(["-a", "x"], default=True, flag_value=4)
|
| 920 |
+
assert param.type is click.INT
|
| 921 |
+
param = click.Option(["-b", "x"], flag_value=8)
|
| 922 |
+
assert param.type is click.INT
|
| 923 |
+
|
| 924 |
+
|
| 925 |
+
@pytest.mark.parametrize(
|
| 926 |
+
("option", "expected"),
|
| 927 |
+
[
|
| 928 |
+
# Not boolean flags
|
| 929 |
+
pytest.param(Option(["-a"], type=int), False, id="int option"),
|
| 930 |
+
pytest.param(Option(["-a"], type=bool), False, id="bool non-flag [None]"),
|
| 931 |
+
pytest.param(Option(["-a"], default=True), False, id="bool non-flag [True]"),
|
| 932 |
+
pytest.param(Option(["-a"], default=False), False, id="bool non-flag [False]"),
|
| 933 |
+
pytest.param(Option(["-a"], flag_value=1), False, id="non-bool flag_value"),
|
| 934 |
+
# Boolean flags
|
| 935 |
+
pytest.param(Option(["-a"], is_flag=True), True, id="is_flag=True"),
|
| 936 |
+
pytest.param(Option(["-a/-A"]), True, id="secondary option [implicit flag]"),
|
| 937 |
+
pytest.param(Option(["-a"], flag_value=True), True, id="bool flag_value"),
|
| 938 |
+
],
|
| 939 |
+
)
|
| 940 |
+
def test_is_bool_flag_is_correctly_set(option, expected):
|
| 941 |
+
assert option.is_bool_flag is expected
|
| 942 |
+
|
| 943 |
+
|
| 944 |
+
@pytest.mark.parametrize(
|
| 945 |
+
("kwargs", "message"),
|
| 946 |
+
[
|
| 947 |
+
({"count": True, "multiple": True}, "'count' is not valid with 'multiple'."),
|
| 948 |
+
({"count": True, "is_flag": True}, "'count' is not valid with 'is_flag'."),
|
| 949 |
+
],
|
| 950 |
+
)
|
| 951 |
+
def test_invalid_flag_combinations(runner, kwargs, message):
|
| 952 |
+
with pytest.raises(TypeError) as e:
|
| 953 |
+
click.Option(["-a"], **kwargs)
|
| 954 |
+
|
| 955 |
+
assert message in str(e.value)
|
| 956 |
+
|
| 957 |
+
|
| 958 |
+
@pytest.mark.parametrize(
|
| 959 |
+
("choices", "metavars"),
|
| 960 |
+
[
|
| 961 |
+
pytest.param(["foo", "bar"], "[TEXT]", id="text choices"),
|
| 962 |
+
pytest.param([1, 2], "[INTEGER]", id="int choices"),
|
| 963 |
+
pytest.param([1.0, 2.0], "[FLOAT]", id="float choices"),
|
| 964 |
+
pytest.param([True, False], "[BOOLEAN]", id="bool choices"),
|
| 965 |
+
pytest.param(["foo", 1], "[TEXT|INTEGER]", id="text/int choices"),
|
| 966 |
+
],
|
| 967 |
+
)
|
| 968 |
+
def test_usage_show_choices(runner, choices, metavars):
|
| 969 |
+
"""When show_choices=False is set, the --help output
|
| 970 |
+
should print choice metavars instead of values.
|
| 971 |
+
"""
|
| 972 |
+
|
| 973 |
+
@click.command()
|
| 974 |
+
@click.option("-g", type=click.Choice(choices))
|
| 975 |
+
def cli_with_choices(g):
|
| 976 |
+
pass
|
| 977 |
+
|
| 978 |
+
@click.command()
|
| 979 |
+
@click.option(
|
| 980 |
+
"-g",
|
| 981 |
+
type=click.Choice(choices),
|
| 982 |
+
show_choices=False,
|
| 983 |
+
)
|
| 984 |
+
def cli_without_choices(g):
|
| 985 |
+
pass
|
| 986 |
+
|
| 987 |
+
result = runner.invoke(cli_with_choices, ["--help"])
|
| 988 |
+
assert f"[{'|'.join([str(i) for i in choices])}]" in result.output
|
| 989 |
+
|
| 990 |
+
result = runner.invoke(cli_without_choices, ["--help"])
|
| 991 |
+
assert metavars in result.output
|
| 992 |
+
|
| 993 |
+
|
| 994 |
+
@pytest.mark.parametrize(
|
| 995 |
+
"opts_one,opts_two",
|
| 996 |
+
[
|
| 997 |
+
# No duplicate shortnames
|
| 998 |
+
(
|
| 999 |
+
("-a", "--aardvark"),
|
| 1000 |
+
("-a", "--avocado"),
|
| 1001 |
+
),
|
| 1002 |
+
# No duplicate long names
|
| 1003 |
+
(
|
| 1004 |
+
("-a", "--aardvark"),
|
| 1005 |
+
("-b", "--aardvark"),
|
| 1006 |
+
),
|
| 1007 |
+
],
|
| 1008 |
+
)
|
| 1009 |
+
def test_duplicate_names_warning(runner, opts_one, opts_two):
|
| 1010 |
+
@click.command()
|
| 1011 |
+
@click.option(*opts_one)
|
| 1012 |
+
@click.option(*opts_two)
|
| 1013 |
+
def cli(one, two):
|
| 1014 |
+
pass
|
| 1015 |
+
|
| 1016 |
+
with pytest.warns(UserWarning):
|
| 1017 |
+
runner.invoke(cli, [])
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_parser.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
|
| 3 |
+
import click
|
| 4 |
+
from click.parser import _OptionParser
|
| 5 |
+
from click.shell_completion import split_arg_string
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
@pytest.mark.parametrize(
|
| 9 |
+
("value", "expect"),
|
| 10 |
+
[
|
| 11 |
+
("cli a b c", ["cli", "a", "b", "c"]),
|
| 12 |
+
("cli 'my file", ["cli", "my file"]),
|
| 13 |
+
("cli 'my file'", ["cli", "my file"]),
|
| 14 |
+
("cli my\\", ["cli", "my"]),
|
| 15 |
+
("cli my\\ file", ["cli", "my file"]),
|
| 16 |
+
],
|
| 17 |
+
)
|
| 18 |
+
def test_split_arg_string(value, expect):
|
| 19 |
+
assert split_arg_string(value) == expect
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def test_parser_default_prefixes():
|
| 23 |
+
parser = _OptionParser()
|
| 24 |
+
assert parser._opt_prefixes == {"-", "--"}
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def test_parser_collects_prefixes():
|
| 28 |
+
ctx = click.Context(click.Command("test"))
|
| 29 |
+
parser = _OptionParser(ctx)
|
| 30 |
+
click.Option("+p", is_flag=True).add_to_parser(parser, ctx)
|
| 31 |
+
click.Option("!e", is_flag=True).add_to_parser(parser, ctx)
|
| 32 |
+
assert parser._opt_prefixes == {"-", "--", "+", "!"}
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_shell_completion.py
ADDED
|
@@ -0,0 +1,442 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import warnings
|
| 2 |
+
|
| 3 |
+
import pytest
|
| 4 |
+
|
| 5 |
+
import click.shell_completion
|
| 6 |
+
from click.core import Argument
|
| 7 |
+
from click.core import Command
|
| 8 |
+
from click.core import Group
|
| 9 |
+
from click.core import Option
|
| 10 |
+
from click.shell_completion import add_completion_class
|
| 11 |
+
from click.shell_completion import CompletionItem
|
| 12 |
+
from click.shell_completion import ShellComplete
|
| 13 |
+
from click.types import Choice
|
| 14 |
+
from click.types import File
|
| 15 |
+
from click.types import Path
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def _get_completions(cli, args, incomplete):
|
| 19 |
+
comp = ShellComplete(cli, {}, cli.name, "_CLICK_COMPLETE")
|
| 20 |
+
return comp.get_completions(args, incomplete)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def _get_words(cli, args, incomplete):
|
| 24 |
+
return [c.value for c in _get_completions(cli, args, incomplete)]
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def test_command():
|
| 28 |
+
cli = Command("cli", params=[Option(["-t", "--test"])])
|
| 29 |
+
assert _get_words(cli, [], "") == []
|
| 30 |
+
assert _get_words(cli, [], "-") == ["-t", "--test", "--help"]
|
| 31 |
+
assert _get_words(cli, [], "--") == ["--test", "--help"]
|
| 32 |
+
assert _get_words(cli, [], "--t") == ["--test"]
|
| 33 |
+
# -t has been seen, so --test isn't suggested
|
| 34 |
+
assert _get_words(cli, ["-t", "a"], "-") == ["--help"]
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def test_group():
|
| 38 |
+
cli = Group("cli", params=[Option(["-a"])], commands=[Command("x"), Command("y")])
|
| 39 |
+
assert _get_words(cli, [], "") == ["x", "y"]
|
| 40 |
+
assert _get_words(cli, [], "-") == ["-a", "--help"]
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def test_group_command_same_option():
|
| 44 |
+
cli = Group(
|
| 45 |
+
"cli", params=[Option(["-a"])], commands=[Command("x", params=[Option(["-a"])])]
|
| 46 |
+
)
|
| 47 |
+
assert _get_words(cli, [], "-") == ["-a", "--help"]
|
| 48 |
+
assert _get_words(cli, ["-a", "a"], "-") == ["--help"]
|
| 49 |
+
assert _get_words(cli, ["-a", "a", "x"], "-") == ["-a", "--help"]
|
| 50 |
+
assert _get_words(cli, ["-a", "a", "x", "-a", "a"], "-") == ["--help"]
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def test_chained():
|
| 54 |
+
cli = Group(
|
| 55 |
+
"cli",
|
| 56 |
+
chain=True,
|
| 57 |
+
commands=[
|
| 58 |
+
Command("set", params=[Option(["-y"])]),
|
| 59 |
+
Command("start"),
|
| 60 |
+
Group("get", commands=[Command("full")]),
|
| 61 |
+
],
|
| 62 |
+
)
|
| 63 |
+
assert _get_words(cli, [], "") == ["get", "set", "start"]
|
| 64 |
+
assert _get_words(cli, [], "s") == ["set", "start"]
|
| 65 |
+
assert _get_words(cli, ["set", "start"], "") == ["get"]
|
| 66 |
+
# subcommands and parent subcommands
|
| 67 |
+
assert _get_words(cli, ["get"], "") == ["full", "set", "start"]
|
| 68 |
+
assert _get_words(cli, ["get", "full"], "") == ["set", "start"]
|
| 69 |
+
assert _get_words(cli, ["get"], "s") == ["set", "start"]
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def test_help_option():
|
| 73 |
+
cli = Group("cli", commands=[Command("with"), Command("no", add_help_option=False)])
|
| 74 |
+
assert _get_words(cli, ["with"], "--") == ["--help"]
|
| 75 |
+
assert _get_words(cli, ["no"], "--") == []
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def test_argument_order():
|
| 79 |
+
cli = Command(
|
| 80 |
+
"cli",
|
| 81 |
+
params=[
|
| 82 |
+
Argument(["plain"]),
|
| 83 |
+
Argument(["c1"], type=Choice(["a1", "a2", "b"])),
|
| 84 |
+
Argument(["c2"], type=Choice(["c1", "c2", "d"])),
|
| 85 |
+
],
|
| 86 |
+
)
|
| 87 |
+
# first argument has no completions
|
| 88 |
+
assert _get_words(cli, [], "") == []
|
| 89 |
+
assert _get_words(cli, [], "a") == []
|
| 90 |
+
# first argument filled, now completion can happen
|
| 91 |
+
assert _get_words(cli, ["x"], "a") == ["a1", "a2"]
|
| 92 |
+
assert _get_words(cli, ["x", "b"], "d") == ["d"]
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def test_argument_default():
|
| 96 |
+
cli = Command(
|
| 97 |
+
"cli",
|
| 98 |
+
add_help_option=False,
|
| 99 |
+
params=[
|
| 100 |
+
Argument(["a"], type=Choice(["a"]), default="a"),
|
| 101 |
+
Argument(["b"], type=Choice(["b"]), default="b"),
|
| 102 |
+
],
|
| 103 |
+
)
|
| 104 |
+
assert _get_words(cli, [], "") == ["a"]
|
| 105 |
+
assert _get_words(cli, ["a"], "b") == ["b"]
|
| 106 |
+
# ignore type validation
|
| 107 |
+
assert _get_words(cli, ["x"], "b") == ["b"]
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def test_type_choice():
|
| 111 |
+
cli = Command("cli", params=[Option(["-c"], type=Choice(["a1", "a2", "b"]))])
|
| 112 |
+
assert _get_words(cli, ["-c"], "") == ["a1", "a2", "b"]
|
| 113 |
+
assert _get_words(cli, ["-c"], "a") == ["a1", "a2"]
|
| 114 |
+
assert _get_words(cli, ["-c"], "a2") == ["a2"]
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def test_choice_special_characters():
|
| 118 |
+
cli = Command("cli", params=[Option(["-c"], type=Choice(["!1", "!2", "+3"]))])
|
| 119 |
+
assert _get_words(cli, ["-c"], "") == ["!1", "!2", "+3"]
|
| 120 |
+
assert _get_words(cli, ["-c"], "!") == ["!1", "!2"]
|
| 121 |
+
assert _get_words(cli, ["-c"], "!2") == ["!2"]
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def test_choice_conflicting_prefix():
|
| 125 |
+
cli = Command(
|
| 126 |
+
"cli",
|
| 127 |
+
params=[
|
| 128 |
+
Option(["-c"], type=Choice(["!1", "!2", "+3"])),
|
| 129 |
+
Option(["+p"], is_flag=True),
|
| 130 |
+
],
|
| 131 |
+
)
|
| 132 |
+
assert _get_words(cli, ["-c"], "") == ["!1", "!2", "+3"]
|
| 133 |
+
assert _get_words(cli, ["-c"], "+") == ["+p"]
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def test_option_count():
|
| 137 |
+
cli = Command("cli", params=[Option(["-c"], count=True)])
|
| 138 |
+
assert _get_words(cli, ["-c"], "") == []
|
| 139 |
+
assert _get_words(cli, ["-c"], "-") == ["--help"]
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def test_option_optional():
|
| 143 |
+
cli = Command(
|
| 144 |
+
"cli",
|
| 145 |
+
add_help_option=False,
|
| 146 |
+
params=[
|
| 147 |
+
Option(["--name"], is_flag=False, flag_value="value"),
|
| 148 |
+
Option(["--flag"], is_flag=True),
|
| 149 |
+
],
|
| 150 |
+
)
|
| 151 |
+
assert _get_words(cli, ["--name"], "") == []
|
| 152 |
+
assert _get_words(cli, ["--name"], "-") == ["--flag"]
|
| 153 |
+
assert _get_words(cli, ["--name", "--flag"], "-") == []
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
@pytest.mark.parametrize(
|
| 157 |
+
("type", "expect"),
|
| 158 |
+
[(File(), "file"), (Path(), "file"), (Path(file_okay=False), "dir")],
|
| 159 |
+
)
|
| 160 |
+
def test_path_types(type, expect):
|
| 161 |
+
cli = Command("cli", params=[Option(["-f"], type=type)])
|
| 162 |
+
out = _get_completions(cli, ["-f"], "ab")
|
| 163 |
+
assert len(out) == 1
|
| 164 |
+
c = out[0]
|
| 165 |
+
assert c.value == "ab"
|
| 166 |
+
assert c.type == expect
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def test_absolute_path():
|
| 170 |
+
cli = Command("cli", params=[Option(["-f"], type=Path())])
|
| 171 |
+
out = _get_completions(cli, ["-f"], "/ab")
|
| 172 |
+
assert len(out) == 1
|
| 173 |
+
c = out[0]
|
| 174 |
+
assert c.value == "/ab"
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
def test_option_flag():
|
| 178 |
+
cli = Command(
|
| 179 |
+
"cli",
|
| 180 |
+
add_help_option=False,
|
| 181 |
+
params=[
|
| 182 |
+
Option(["--on/--off"]),
|
| 183 |
+
Argument(["a"], type=Choice(["a1", "a2", "b"])),
|
| 184 |
+
],
|
| 185 |
+
)
|
| 186 |
+
assert _get_words(cli, [], "--") == ["--on", "--off"]
|
| 187 |
+
# flag option doesn't take value, use choice argument
|
| 188 |
+
assert _get_words(cli, ["--on"], "a") == ["a1", "a2"]
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
def test_option_custom():
|
| 192 |
+
def custom(ctx, param, incomplete):
|
| 193 |
+
return [incomplete.upper()]
|
| 194 |
+
|
| 195 |
+
cli = Command(
|
| 196 |
+
"cli",
|
| 197 |
+
params=[
|
| 198 |
+
Argument(["x"]),
|
| 199 |
+
Argument(["y"]),
|
| 200 |
+
Argument(["z"], shell_complete=custom),
|
| 201 |
+
],
|
| 202 |
+
)
|
| 203 |
+
assert _get_words(cli, ["a", "b"], "") == [""]
|
| 204 |
+
assert _get_words(cli, ["a", "b"], "c") == ["C"]
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
def test_option_multiple():
|
| 208 |
+
cli = Command(
|
| 209 |
+
"type",
|
| 210 |
+
params=[Option(["-m"], type=Choice(["a", "b"]), multiple=True), Option(["-f"])],
|
| 211 |
+
)
|
| 212 |
+
assert _get_words(cli, ["-m"], "") == ["a", "b"]
|
| 213 |
+
assert "-m" in _get_words(cli, ["-m", "a"], "-")
|
| 214 |
+
assert _get_words(cli, ["-m", "a", "-m"], "") == ["a", "b"]
|
| 215 |
+
# used single options aren't suggested again
|
| 216 |
+
assert "-c" not in _get_words(cli, ["-c", "f"], "-")
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
def test_option_nargs():
|
| 220 |
+
cli = Command("cli", params=[Option(["-c"], type=Choice(["a", "b"]), nargs=2)])
|
| 221 |
+
assert _get_words(cli, ["-c"], "") == ["a", "b"]
|
| 222 |
+
assert _get_words(cli, ["-c", "a"], "") == ["a", "b"]
|
| 223 |
+
assert _get_words(cli, ["-c", "a", "b"], "") == []
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
def test_argument_nargs():
|
| 227 |
+
cli = Command(
|
| 228 |
+
"cli",
|
| 229 |
+
params=[
|
| 230 |
+
Argument(["x"], type=Choice(["a", "b"]), nargs=2),
|
| 231 |
+
Argument(["y"], type=Choice(["c", "d"]), nargs=-1),
|
| 232 |
+
Option(["-z"]),
|
| 233 |
+
],
|
| 234 |
+
)
|
| 235 |
+
assert _get_words(cli, [], "") == ["a", "b"]
|
| 236 |
+
assert _get_words(cli, ["a"], "") == ["a", "b"]
|
| 237 |
+
assert _get_words(cli, ["a", "b"], "") == ["c", "d"]
|
| 238 |
+
assert _get_words(cli, ["a", "b", "c"], "") == ["c", "d"]
|
| 239 |
+
assert _get_words(cli, ["a", "b", "c", "d"], "") == ["c", "d"]
|
| 240 |
+
assert _get_words(cli, ["a", "-z", "1"], "") == ["a", "b"]
|
| 241 |
+
assert _get_words(cli, ["a", "-z", "1", "b"], "") == ["c", "d"]
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
def test_double_dash():
|
| 245 |
+
cli = Command(
|
| 246 |
+
"cli",
|
| 247 |
+
add_help_option=False,
|
| 248 |
+
params=[
|
| 249 |
+
Option(["--opt"]),
|
| 250 |
+
Argument(["name"], type=Choice(["name", "--", "-o", "--opt"])),
|
| 251 |
+
],
|
| 252 |
+
)
|
| 253 |
+
assert _get_words(cli, [], "-") == ["--opt"]
|
| 254 |
+
assert _get_words(cli, ["value"], "-") == ["--opt"]
|
| 255 |
+
assert _get_words(cli, [], "") == ["name", "--", "-o", "--opt"]
|
| 256 |
+
assert _get_words(cli, ["--"], "") == ["name", "--", "-o", "--opt"]
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
def test_hidden():
|
| 260 |
+
cli = Group(
|
| 261 |
+
"cli",
|
| 262 |
+
commands=[
|
| 263 |
+
Command(
|
| 264 |
+
"hidden",
|
| 265 |
+
add_help_option=False,
|
| 266 |
+
hidden=True,
|
| 267 |
+
params=[
|
| 268 |
+
Option(["-a"]),
|
| 269 |
+
Option(["-b"], type=Choice(["a", "b"]), hidden=True),
|
| 270 |
+
],
|
| 271 |
+
)
|
| 272 |
+
],
|
| 273 |
+
)
|
| 274 |
+
assert "hidden" not in _get_words(cli, [], "")
|
| 275 |
+
assert "hidden" not in _get_words(cli, [], "hidden")
|
| 276 |
+
assert _get_words(cli, ["hidden"], "-") == ["-a"]
|
| 277 |
+
assert _get_words(cli, ["hidden", "-b"], "") == ["a", "b"]
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
def test_add_different_name():
|
| 281 |
+
cli = Group("cli", commands={"renamed": Command("original")})
|
| 282 |
+
words = _get_words(cli, [], "")
|
| 283 |
+
assert "renamed" in words
|
| 284 |
+
assert "original" not in words
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
def test_completion_item_data():
|
| 288 |
+
c = CompletionItem("test", a=1)
|
| 289 |
+
assert c.a == 1
|
| 290 |
+
assert c.b is None
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
@pytest.fixture()
|
| 294 |
+
def _patch_for_completion(monkeypatch):
|
| 295 |
+
monkeypatch.setattr(
|
| 296 |
+
"click.shell_completion.BashComplete._check_version", lambda self: True
|
| 297 |
+
)
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
@pytest.mark.parametrize("shell", ["bash", "zsh", "fish"])
|
| 301 |
+
@pytest.mark.usefixtures("_patch_for_completion")
|
| 302 |
+
def test_full_source(runner, shell):
|
| 303 |
+
cli = Group("cli", commands=[Command("a"), Command("b")])
|
| 304 |
+
result = runner.invoke(cli, env={"_CLI_COMPLETE": f"{shell}_source"})
|
| 305 |
+
assert f"_CLI_COMPLETE={shell}_complete" in result.output
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
@pytest.mark.parametrize(
|
| 309 |
+
("shell", "env", "expect"),
|
| 310 |
+
[
|
| 311 |
+
("bash", {"COMP_WORDS": "", "COMP_CWORD": "0"}, "plain,a\nplain,b\n"),
|
| 312 |
+
("bash", {"COMP_WORDS": "a b", "COMP_CWORD": "1"}, "plain,b\n"),
|
| 313 |
+
("zsh", {"COMP_WORDS": "", "COMP_CWORD": "0"}, "plain\na\n_\nplain\nb\nbee\n"),
|
| 314 |
+
("zsh", {"COMP_WORDS": "a b", "COMP_CWORD": "1"}, "plain\nb\nbee\n"),
|
| 315 |
+
("fish", {"COMP_WORDS": "", "COMP_CWORD": ""}, "plain,a\nplain,b\tbee\n"),
|
| 316 |
+
("fish", {"COMP_WORDS": "a b", "COMP_CWORD": "b"}, "plain,b\tbee\n"),
|
| 317 |
+
],
|
| 318 |
+
)
|
| 319 |
+
@pytest.mark.usefixtures("_patch_for_completion")
|
| 320 |
+
def test_full_complete(runner, shell, env, expect):
|
| 321 |
+
cli = Group("cli", commands=[Command("a"), Command("b", help="bee")])
|
| 322 |
+
env["_CLI_COMPLETE"] = f"{shell}_complete"
|
| 323 |
+
result = runner.invoke(cli, env=env)
|
| 324 |
+
assert result.output == expect
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
@pytest.mark.usefixtures("_patch_for_completion")
|
| 328 |
+
def test_context_settings(runner):
|
| 329 |
+
def complete(ctx, param, incomplete):
|
| 330 |
+
return ctx.obj["choices"]
|
| 331 |
+
|
| 332 |
+
cli = Command("cli", params=[Argument("x", shell_complete=complete)])
|
| 333 |
+
result = runner.invoke(
|
| 334 |
+
cli,
|
| 335 |
+
obj={"choices": ["a", "b"]},
|
| 336 |
+
env={"COMP_WORDS": "", "COMP_CWORD": "0", "_CLI_COMPLETE": "bash_complete"},
|
| 337 |
+
)
|
| 338 |
+
assert result.output == "plain,a\nplain,b\n"
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
@pytest.mark.parametrize(("value", "expect"), [(False, ["Au", "al"]), (True, ["al"])])
|
| 342 |
+
def test_choice_case_sensitive(value, expect):
|
| 343 |
+
cli = Command(
|
| 344 |
+
"cli",
|
| 345 |
+
params=[Option(["-a"], type=Choice(["Au", "al", "Bc"], case_sensitive=value))],
|
| 346 |
+
)
|
| 347 |
+
completions = _get_words(cli, ["-a"], "a")
|
| 348 |
+
assert completions == expect
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
@pytest.fixture()
|
| 352 |
+
def _restore_available_shells(tmpdir):
|
| 353 |
+
prev_available_shells = click.shell_completion._available_shells.copy()
|
| 354 |
+
click.shell_completion._available_shells.clear()
|
| 355 |
+
yield
|
| 356 |
+
click.shell_completion._available_shells.clear()
|
| 357 |
+
click.shell_completion._available_shells.update(prev_available_shells)
|
| 358 |
+
|
| 359 |
+
|
| 360 |
+
@pytest.mark.usefixtures("_restore_available_shells")
|
| 361 |
+
def test_add_completion_class():
|
| 362 |
+
# At first, "mysh" is not in available shells
|
| 363 |
+
assert "mysh" not in click.shell_completion._available_shells
|
| 364 |
+
|
| 365 |
+
class MyshComplete(ShellComplete):
|
| 366 |
+
name = "mysh"
|
| 367 |
+
source_template = "dummy source"
|
| 368 |
+
|
| 369 |
+
# "mysh" still not in available shells because it is not registered
|
| 370 |
+
assert "mysh" not in click.shell_completion._available_shells
|
| 371 |
+
|
| 372 |
+
# Adding a completion class should return that class
|
| 373 |
+
assert add_completion_class(MyshComplete) is MyshComplete
|
| 374 |
+
|
| 375 |
+
# Now, "mysh" is finally in available shells
|
| 376 |
+
assert "mysh" in click.shell_completion._available_shells
|
| 377 |
+
assert click.shell_completion._available_shells["mysh"] is MyshComplete
|
| 378 |
+
|
| 379 |
+
|
| 380 |
+
@pytest.mark.usefixtures("_restore_available_shells")
|
| 381 |
+
def test_add_completion_class_with_name():
|
| 382 |
+
# At first, "mysh" is not in available shells
|
| 383 |
+
assert "mysh" not in click.shell_completion._available_shells
|
| 384 |
+
assert "not_mysh" not in click.shell_completion._available_shells
|
| 385 |
+
|
| 386 |
+
class MyshComplete(ShellComplete):
|
| 387 |
+
name = "not_mysh"
|
| 388 |
+
source_template = "dummy source"
|
| 389 |
+
|
| 390 |
+
# "mysh" and "not_mysh" are still not in available shells because
|
| 391 |
+
# it is not registered yet
|
| 392 |
+
assert "mysh" not in click.shell_completion._available_shells
|
| 393 |
+
assert "not_mysh" not in click.shell_completion._available_shells
|
| 394 |
+
|
| 395 |
+
# Adding a completion class should return that class.
|
| 396 |
+
# Because we are using the "name" parameter, the name isn't taken
|
| 397 |
+
# from the class.
|
| 398 |
+
assert add_completion_class(MyshComplete, name="mysh") is MyshComplete
|
| 399 |
+
|
| 400 |
+
# Now, "mysh" is finally in available shells
|
| 401 |
+
assert "mysh" in click.shell_completion._available_shells
|
| 402 |
+
assert "not_mysh" not in click.shell_completion._available_shells
|
| 403 |
+
assert click.shell_completion._available_shells["mysh"] is MyshComplete
|
| 404 |
+
|
| 405 |
+
|
| 406 |
+
@pytest.mark.usefixtures("_restore_available_shells")
|
| 407 |
+
def test_add_completion_class_decorator():
|
| 408 |
+
# At first, "mysh" is not in available shells
|
| 409 |
+
assert "mysh" not in click.shell_completion._available_shells
|
| 410 |
+
|
| 411 |
+
@add_completion_class
|
| 412 |
+
class MyshComplete(ShellComplete):
|
| 413 |
+
name = "mysh"
|
| 414 |
+
source_template = "dummy source"
|
| 415 |
+
|
| 416 |
+
# Using `add_completion_class` as a decorator adds the new shell immediately
|
| 417 |
+
assert "mysh" in click.shell_completion._available_shells
|
| 418 |
+
assert click.shell_completion._available_shells["mysh"] is MyshComplete
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
# Don't make the ResourceWarning give an error
|
| 422 |
+
@pytest.mark.filterwarnings("default")
|
| 423 |
+
def test_files_closed(runner) -> None:
|
| 424 |
+
with runner.isolated_filesystem():
|
| 425 |
+
config_file = "foo.txt"
|
| 426 |
+
with open(config_file, "w") as f:
|
| 427 |
+
f.write("bar")
|
| 428 |
+
|
| 429 |
+
@click.group()
|
| 430 |
+
@click.option(
|
| 431 |
+
"--config-file",
|
| 432 |
+
default=config_file,
|
| 433 |
+
type=click.File(mode="r"),
|
| 434 |
+
)
|
| 435 |
+
@click.pass_context
|
| 436 |
+
def cli(ctx, config_file):
|
| 437 |
+
pass
|
| 438 |
+
|
| 439 |
+
with warnings.catch_warnings(record=True) as current_warnings:
|
| 440 |
+
assert not current_warnings, "There should be no warnings to start"
|
| 441 |
+
_get_completions(cli, args=[], incomplete="")
|
| 442 |
+
assert not current_warnings, "There should be no warnings after either"
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_termui.py
ADDED
|
@@ -0,0 +1,487 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import platform
|
| 2 |
+
import tempfile
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
import pytest
|
| 6 |
+
|
| 7 |
+
import click._termui_impl
|
| 8 |
+
from click._compat import WIN
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class FakeClock:
|
| 12 |
+
def __init__(self):
|
| 13 |
+
self.now = time.time()
|
| 14 |
+
|
| 15 |
+
def advance_time(self, seconds=1):
|
| 16 |
+
self.now += seconds
|
| 17 |
+
|
| 18 |
+
def time(self):
|
| 19 |
+
return self.now
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _create_progress(length=10, **kwargs):
|
| 23 |
+
progress = click.progressbar(tuple(range(length)))
|
| 24 |
+
for key, value in kwargs.items():
|
| 25 |
+
setattr(progress, key, value)
|
| 26 |
+
return progress
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def test_progressbar_strip_regression(runner, monkeypatch):
|
| 30 |
+
label = " padded line"
|
| 31 |
+
|
| 32 |
+
@click.command()
|
| 33 |
+
def cli():
|
| 34 |
+
with _create_progress(label=label) as progress:
|
| 35 |
+
for _ in progress:
|
| 36 |
+
pass
|
| 37 |
+
|
| 38 |
+
monkeypatch.setattr(click._termui_impl, "isatty", lambda _: True)
|
| 39 |
+
assert (
|
| 40 |
+
label
|
| 41 |
+
in runner.invoke(cli, [], standalone_mode=False, catch_exceptions=False).output
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def test_progressbar_length_hint(runner, monkeypatch):
|
| 46 |
+
class Hinted:
|
| 47 |
+
def __init__(self, n):
|
| 48 |
+
self.items = list(range(n))
|
| 49 |
+
|
| 50 |
+
def __length_hint__(self):
|
| 51 |
+
return len(self.items)
|
| 52 |
+
|
| 53 |
+
def __iter__(self):
|
| 54 |
+
return self
|
| 55 |
+
|
| 56 |
+
def __next__(self):
|
| 57 |
+
if self.items:
|
| 58 |
+
return self.items.pop()
|
| 59 |
+
else:
|
| 60 |
+
raise StopIteration
|
| 61 |
+
|
| 62 |
+
next = __next__
|
| 63 |
+
|
| 64 |
+
@click.command()
|
| 65 |
+
def cli():
|
| 66 |
+
with click.progressbar(Hinted(10), label="test") as progress:
|
| 67 |
+
for _ in progress:
|
| 68 |
+
pass
|
| 69 |
+
|
| 70 |
+
monkeypatch.setattr(click._termui_impl, "isatty", lambda _: True)
|
| 71 |
+
result = runner.invoke(cli, [])
|
| 72 |
+
assert result.exception is None
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def test_progressbar_no_tty(runner, monkeypatch):
|
| 76 |
+
@click.command()
|
| 77 |
+
def cli():
|
| 78 |
+
with _create_progress(label="working") as progress:
|
| 79 |
+
for _ in progress:
|
| 80 |
+
pass
|
| 81 |
+
|
| 82 |
+
monkeypatch.setattr(click._termui_impl, "isatty", lambda _: False)
|
| 83 |
+
assert runner.invoke(cli, []).output == "working\n"
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def test_progressbar_hidden_manual(runner, monkeypatch):
|
| 87 |
+
@click.command()
|
| 88 |
+
def cli():
|
| 89 |
+
with _create_progress(label="see nothing", hidden=True) as progress:
|
| 90 |
+
for _ in progress:
|
| 91 |
+
pass
|
| 92 |
+
|
| 93 |
+
monkeypatch.setattr(click._termui_impl, "isatty", lambda _: True)
|
| 94 |
+
assert runner.invoke(cli, []).output == ""
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
@pytest.mark.parametrize("avg, expected", [([], 0.0), ([1, 4], 2.5)])
|
| 98 |
+
def test_progressbar_time_per_iteration(runner, avg, expected):
|
| 99 |
+
with _create_progress(2, avg=avg) as progress:
|
| 100 |
+
assert progress.time_per_iteration == expected
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
@pytest.mark.parametrize("finished, expected", [(False, 5), (True, 0)])
|
| 104 |
+
def test_progressbar_eta(runner, finished, expected):
|
| 105 |
+
with _create_progress(2, finished=finished, avg=[1, 4]) as progress:
|
| 106 |
+
assert progress.eta == expected
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
@pytest.mark.parametrize(
|
| 110 |
+
"eta, expected",
|
| 111 |
+
[
|
| 112 |
+
(0, "00:00:00"),
|
| 113 |
+
(30, "00:00:30"),
|
| 114 |
+
(90, "00:01:30"),
|
| 115 |
+
(900, "00:15:00"),
|
| 116 |
+
(9000, "02:30:00"),
|
| 117 |
+
(99999999999, "1157407d 09:46:39"),
|
| 118 |
+
(None, ""),
|
| 119 |
+
],
|
| 120 |
+
)
|
| 121 |
+
def test_progressbar_format_eta(runner, eta, expected):
|
| 122 |
+
with _create_progress(1, eta_known=eta is not None, avg=[eta]) as progress:
|
| 123 |
+
assert progress.format_eta() == expected
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
@pytest.mark.parametrize("pos, length", [(0, 5), (-1, 1), (5, 5), (6, 5), (4, 0)])
|
| 127 |
+
def test_progressbar_format_pos(runner, pos, length):
|
| 128 |
+
with _create_progress(length, pos=pos) as progress:
|
| 129 |
+
result = progress.format_pos()
|
| 130 |
+
assert result == f"{pos}/{length}"
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
@pytest.mark.parametrize(
|
| 134 |
+
"length, finished, pos, avg, expected",
|
| 135 |
+
[
|
| 136 |
+
(8, False, 7, 0, "#######-"),
|
| 137 |
+
(0, True, 8, 0, "########"),
|
| 138 |
+
],
|
| 139 |
+
)
|
| 140 |
+
def test_progressbar_format_bar(runner, length, finished, pos, avg, expected):
|
| 141 |
+
with _create_progress(
|
| 142 |
+
length, width=8, pos=pos, finished=finished, avg=[avg]
|
| 143 |
+
) as progress:
|
| 144 |
+
assert progress.format_bar() == expected
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
@pytest.mark.parametrize(
|
| 148 |
+
"length, show_percent, show_pos, pos, expected",
|
| 149 |
+
[
|
| 150 |
+
(0, True, True, 0, " [--------] 0/0 0%"),
|
| 151 |
+
(0, False, True, 0, " [--------] 0/0"),
|
| 152 |
+
(0, False, False, 0, " [--------]"),
|
| 153 |
+
(0, False, False, 0, " [--------]"),
|
| 154 |
+
(8, True, True, 8, " [########] 8/8 100%"),
|
| 155 |
+
],
|
| 156 |
+
)
|
| 157 |
+
def test_progressbar_format_progress_line(
|
| 158 |
+
runner, length, show_percent, show_pos, pos, expected
|
| 159 |
+
):
|
| 160 |
+
with _create_progress(
|
| 161 |
+
length,
|
| 162 |
+
width=8,
|
| 163 |
+
show_percent=show_percent,
|
| 164 |
+
pos=pos,
|
| 165 |
+
show_pos=show_pos,
|
| 166 |
+
) as progress:
|
| 167 |
+
assert progress.format_progress_line() == expected
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
@pytest.mark.parametrize("test_item", ["test", None])
|
| 171 |
+
def test_progressbar_format_progress_line_with_show_func(runner, test_item):
|
| 172 |
+
def item_show_func(item):
|
| 173 |
+
return item
|
| 174 |
+
|
| 175 |
+
with _create_progress(
|
| 176 |
+
item_show_func=item_show_func, current_item=test_item
|
| 177 |
+
) as progress:
|
| 178 |
+
if test_item:
|
| 179 |
+
assert progress.format_progress_line().endswith(test_item)
|
| 180 |
+
else:
|
| 181 |
+
assert progress.format_progress_line().endswith(progress.format_pct())
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
def test_progressbar_init_exceptions(runner):
|
| 185 |
+
with pytest.raises(TypeError, match="iterable or length is required"):
|
| 186 |
+
click.progressbar()
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def test_progressbar_iter_outside_with_exceptions(runner):
|
| 190 |
+
progress = click.progressbar(length=2)
|
| 191 |
+
|
| 192 |
+
with pytest.raises(RuntimeError, match="with block"):
|
| 193 |
+
iter(progress)
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def test_progressbar_is_iterator(runner, monkeypatch):
|
| 197 |
+
@click.command()
|
| 198 |
+
def cli():
|
| 199 |
+
with click.progressbar(range(10), label="test") as progress:
|
| 200 |
+
while True:
|
| 201 |
+
try:
|
| 202 |
+
next(progress)
|
| 203 |
+
except StopIteration:
|
| 204 |
+
break
|
| 205 |
+
|
| 206 |
+
monkeypatch.setattr(click._termui_impl, "isatty", lambda _: True)
|
| 207 |
+
result = runner.invoke(cli, [])
|
| 208 |
+
assert result.exception is None
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
def test_choices_list_in_prompt(runner, monkeypatch):
|
| 212 |
+
@click.command()
|
| 213 |
+
@click.option(
|
| 214 |
+
"-g", type=click.Choice(["none", "day", "week", "month"]), prompt=True
|
| 215 |
+
)
|
| 216 |
+
def cli_with_choices(g):
|
| 217 |
+
pass
|
| 218 |
+
|
| 219 |
+
@click.command()
|
| 220 |
+
@click.option(
|
| 221 |
+
"-g",
|
| 222 |
+
type=click.Choice(["none", "day", "week", "month"]),
|
| 223 |
+
prompt=True,
|
| 224 |
+
show_choices=False,
|
| 225 |
+
)
|
| 226 |
+
def cli_without_choices(g):
|
| 227 |
+
pass
|
| 228 |
+
|
| 229 |
+
result = runner.invoke(cli_with_choices, [], input="none")
|
| 230 |
+
assert "(none, day, week, month)" in result.output
|
| 231 |
+
|
| 232 |
+
result = runner.invoke(cli_without_choices, [], input="none")
|
| 233 |
+
assert "(none, day, week, month)" not in result.output
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
@pytest.mark.parametrize(
|
| 237 |
+
"file_kwargs", [{"mode": "rt"}, {"mode": "rb"}, {"lazy": True}]
|
| 238 |
+
)
|
| 239 |
+
def test_file_prompt_default_format(runner, file_kwargs):
|
| 240 |
+
@click.command()
|
| 241 |
+
@click.option("-f", default=__file__, prompt="file", type=click.File(**file_kwargs))
|
| 242 |
+
def cli(f):
|
| 243 |
+
click.echo(f.name)
|
| 244 |
+
|
| 245 |
+
result = runner.invoke(cli)
|
| 246 |
+
assert result.output == f"file [{__file__}]: \n{__file__}\n"
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def test_secho(runner):
|
| 250 |
+
with runner.isolation() as outstreams:
|
| 251 |
+
click.secho(None, nl=False)
|
| 252 |
+
bytes = outstreams[0].getvalue()
|
| 253 |
+
assert bytes == b""
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
@pytest.mark.skipif(platform.system() == "Windows", reason="No style on Windows.")
|
| 257 |
+
@pytest.mark.parametrize(
|
| 258 |
+
("value", "expect"), [(123, b"\x1b[45m123\x1b[0m"), (b"test", b"test")]
|
| 259 |
+
)
|
| 260 |
+
def test_secho_non_text(runner, value, expect):
|
| 261 |
+
with runner.isolation() as (out, _, _):
|
| 262 |
+
click.secho(value, nl=False, color=True, bg="magenta")
|
| 263 |
+
result = out.getvalue()
|
| 264 |
+
assert result == expect
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def test_progressbar_yields_all_items(runner):
|
| 268 |
+
with click.progressbar(range(3)) as progress:
|
| 269 |
+
assert len(list(progress)) == 3
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
def test_progressbar_update(runner, monkeypatch):
|
| 273 |
+
fake_clock = FakeClock()
|
| 274 |
+
|
| 275 |
+
@click.command()
|
| 276 |
+
def cli():
|
| 277 |
+
with click.progressbar(range(4)) as progress:
|
| 278 |
+
for _ in progress:
|
| 279 |
+
fake_clock.advance_time()
|
| 280 |
+
print("")
|
| 281 |
+
|
| 282 |
+
monkeypatch.setattr(time, "time", fake_clock.time)
|
| 283 |
+
monkeypatch.setattr(click._termui_impl, "isatty", lambda _: True)
|
| 284 |
+
output = runner.invoke(cli, []).output
|
| 285 |
+
|
| 286 |
+
lines = [line for line in output.split("\n") if "[" in line]
|
| 287 |
+
|
| 288 |
+
assert " 0%" in lines[0]
|
| 289 |
+
assert " 25% 00:00:03" in lines[1]
|
| 290 |
+
assert " 50% 00:00:02" in lines[2]
|
| 291 |
+
assert " 75% 00:00:01" in lines[3]
|
| 292 |
+
assert "100% " in lines[4]
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
def test_progressbar_item_show_func(runner, monkeypatch):
|
| 296 |
+
"""item_show_func should show the current item being yielded."""
|
| 297 |
+
|
| 298 |
+
@click.command()
|
| 299 |
+
def cli():
|
| 300 |
+
with click.progressbar(range(3), item_show_func=lambda x: str(x)) as progress:
|
| 301 |
+
for item in progress:
|
| 302 |
+
click.echo(f" item {item}")
|
| 303 |
+
|
| 304 |
+
monkeypatch.setattr(click._termui_impl, "isatty", lambda _: True)
|
| 305 |
+
lines = runner.invoke(cli).output.splitlines()
|
| 306 |
+
|
| 307 |
+
for i, line in enumerate(x for x in lines if "item" in x):
|
| 308 |
+
assert f"{i} item {i}" in line
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
def test_progressbar_update_with_item_show_func(runner, monkeypatch):
|
| 312 |
+
@click.command()
|
| 313 |
+
def cli():
|
| 314 |
+
with click.progressbar(
|
| 315 |
+
length=6, item_show_func=lambda x: f"Custom {x}"
|
| 316 |
+
) as progress:
|
| 317 |
+
while not progress.finished:
|
| 318 |
+
progress.update(2, progress.pos)
|
| 319 |
+
click.echo()
|
| 320 |
+
|
| 321 |
+
monkeypatch.setattr(click._termui_impl, "isatty", lambda _: True)
|
| 322 |
+
output = runner.invoke(cli, []).output
|
| 323 |
+
|
| 324 |
+
lines = [line for line in output.split("\n") if "[" in line]
|
| 325 |
+
|
| 326 |
+
assert "Custom 0" in lines[0]
|
| 327 |
+
assert "Custom 2" in lines[1]
|
| 328 |
+
assert "Custom 4" in lines[2]
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
def test_progress_bar_update_min_steps(runner):
|
| 332 |
+
bar = _create_progress(update_min_steps=5)
|
| 333 |
+
bar.update(3)
|
| 334 |
+
assert bar._completed_intervals == 3
|
| 335 |
+
assert bar.pos == 0
|
| 336 |
+
bar.update(2)
|
| 337 |
+
assert bar._completed_intervals == 0
|
| 338 |
+
assert bar.pos == 5
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
@pytest.mark.parametrize("key_char", ("h", "H", "é", "À", " ", "字", "àH", "àR"))
|
| 342 |
+
@pytest.mark.parametrize("echo", [True, False])
|
| 343 |
+
@pytest.mark.skipif(not WIN, reason="Tests user-input using the msvcrt module.")
|
| 344 |
+
def test_getchar_windows(runner, monkeypatch, key_char, echo):
|
| 345 |
+
monkeypatch.setattr(click._termui_impl.msvcrt, "getwche", lambda: key_char)
|
| 346 |
+
monkeypatch.setattr(click._termui_impl.msvcrt, "getwch", lambda: key_char)
|
| 347 |
+
monkeypatch.setattr(click.termui, "_getchar", None)
|
| 348 |
+
assert click.getchar(echo) == key_char
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
@pytest.mark.parametrize(
|
| 352 |
+
"special_key_char, key_char", [("\x00", "a"), ("\x00", "b"), ("\xe0", "c")]
|
| 353 |
+
)
|
| 354 |
+
@pytest.mark.skipif(
|
| 355 |
+
not WIN, reason="Tests special character inputs using the msvcrt module."
|
| 356 |
+
)
|
| 357 |
+
def test_getchar_special_key_windows(runner, monkeypatch, special_key_char, key_char):
|
| 358 |
+
ordered_inputs = [key_char, special_key_char]
|
| 359 |
+
monkeypatch.setattr(
|
| 360 |
+
click._termui_impl.msvcrt, "getwch", lambda: ordered_inputs.pop()
|
| 361 |
+
)
|
| 362 |
+
monkeypatch.setattr(click.termui, "_getchar", None)
|
| 363 |
+
assert click.getchar() == f"{special_key_char}{key_char}"
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
@pytest.mark.parametrize(
|
| 367 |
+
("key_char", "exc"), [("\x03", KeyboardInterrupt), ("\x1a", EOFError)]
|
| 368 |
+
)
|
| 369 |
+
@pytest.mark.skipif(not WIN, reason="Tests user-input using the msvcrt module.")
|
| 370 |
+
def test_getchar_windows_exceptions(runner, monkeypatch, key_char, exc):
|
| 371 |
+
monkeypatch.setattr(click._termui_impl.msvcrt, "getwch", lambda: key_char)
|
| 372 |
+
monkeypatch.setattr(click.termui, "_getchar", None)
|
| 373 |
+
|
| 374 |
+
with pytest.raises(exc):
|
| 375 |
+
click.getchar()
|
| 376 |
+
|
| 377 |
+
|
| 378 |
+
@pytest.mark.skipif(platform.system() == "Windows", reason="No sed on Windows.")
|
| 379 |
+
def test_fast_edit(runner):
|
| 380 |
+
result = click.edit("a\nb", editor="sed -i~ 's/$/Test/'")
|
| 381 |
+
assert result == "aTest\nbTest\n"
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
@pytest.mark.skipif(platform.system() == "Windows", reason="No sed on Windows.")
|
| 385 |
+
def test_edit(runner):
|
| 386 |
+
with tempfile.NamedTemporaryFile(mode="w") as named_tempfile:
|
| 387 |
+
named_tempfile.write("a\nb")
|
| 388 |
+
named_tempfile.flush()
|
| 389 |
+
|
| 390 |
+
result = click.edit(filename=named_tempfile.name, editor="sed -i~ 's/$/Test/'")
|
| 391 |
+
assert result is None
|
| 392 |
+
|
| 393 |
+
# We need ot reopen the file as it becomes unreadable after the edit.
|
| 394 |
+
with open(named_tempfile.name) as reopened_file:
|
| 395 |
+
assert reopened_file.read() == "aTest\nbTest"
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
@pytest.mark.parametrize(
|
| 399 |
+
("prompt_required", "required", "args", "expect"),
|
| 400 |
+
[
|
| 401 |
+
(True, False, None, "prompt"),
|
| 402 |
+
(True, False, ["-v"], "Option '-v' requires an argument."),
|
| 403 |
+
(False, True, None, "prompt"),
|
| 404 |
+
(False, True, ["-v"], "prompt"),
|
| 405 |
+
],
|
| 406 |
+
)
|
| 407 |
+
def test_prompt_required_with_required(runner, prompt_required, required, args, expect):
|
| 408 |
+
@click.command()
|
| 409 |
+
@click.option("-v", prompt=True, prompt_required=prompt_required, required=required)
|
| 410 |
+
def cli(v):
|
| 411 |
+
click.echo(str(v))
|
| 412 |
+
|
| 413 |
+
result = runner.invoke(cli, args, input="prompt")
|
| 414 |
+
assert expect in result.output
|
| 415 |
+
|
| 416 |
+
|
| 417 |
+
@pytest.mark.parametrize(
|
| 418 |
+
("args", "expect"),
|
| 419 |
+
[
|
| 420 |
+
# Flag not passed, don't prompt.
|
| 421 |
+
pytest.param(None, None, id="no flag"),
|
| 422 |
+
# Flag and value passed, don't prompt.
|
| 423 |
+
pytest.param(["-v", "value"], "value", id="short sep value"),
|
| 424 |
+
pytest.param(["--value", "value"], "value", id="long sep value"),
|
| 425 |
+
pytest.param(["-vvalue"], "value", id="short join value"),
|
| 426 |
+
pytest.param(["--value=value"], "value", id="long join value"),
|
| 427 |
+
# Flag without value passed, prompt.
|
| 428 |
+
pytest.param(["-v"], "prompt", id="short no value"),
|
| 429 |
+
pytest.param(["--value"], "prompt", id="long no value"),
|
| 430 |
+
# Don't use next option flag as value.
|
| 431 |
+
pytest.param(["-v", "-o", "42"], ("prompt", "42"), id="no value opt"),
|
| 432 |
+
],
|
| 433 |
+
)
|
| 434 |
+
def test_prompt_required_false(runner, args, expect):
|
| 435 |
+
@click.command()
|
| 436 |
+
@click.option("-v", "--value", prompt=True, prompt_required=False)
|
| 437 |
+
@click.option("-o")
|
| 438 |
+
def cli(value, o):
|
| 439 |
+
if o is not None:
|
| 440 |
+
return value, o
|
| 441 |
+
|
| 442 |
+
return value
|
| 443 |
+
|
| 444 |
+
result = runner.invoke(cli, args=args, input="prompt", standalone_mode=False)
|
| 445 |
+
assert result.exception is None
|
| 446 |
+
assert result.return_value == expect
|
| 447 |
+
|
| 448 |
+
|
| 449 |
+
@pytest.mark.parametrize(
|
| 450 |
+
("prompt", "input", "default", "expect"),
|
| 451 |
+
[
|
| 452 |
+
(True, "password\npassword", None, "password"),
|
| 453 |
+
("Confirm Password", "password\npassword\n", None, "password"),
|
| 454 |
+
(True, "", "", ""),
|
| 455 |
+
(False, None, None, None),
|
| 456 |
+
],
|
| 457 |
+
)
|
| 458 |
+
def test_confirmation_prompt(runner, prompt, input, default, expect):
|
| 459 |
+
@click.command()
|
| 460 |
+
@click.option(
|
| 461 |
+
"--password",
|
| 462 |
+
prompt=prompt,
|
| 463 |
+
hide_input=True,
|
| 464 |
+
default=default,
|
| 465 |
+
confirmation_prompt=prompt,
|
| 466 |
+
)
|
| 467 |
+
def cli(password):
|
| 468 |
+
return password
|
| 469 |
+
|
| 470 |
+
result = runner.invoke(cli, input=input, standalone_mode=False)
|
| 471 |
+
assert result.exception is None
|
| 472 |
+
assert result.return_value == expect
|
| 473 |
+
|
| 474 |
+
if prompt == "Confirm Password":
|
| 475 |
+
assert "Confirm Password: " in result.output
|
| 476 |
+
|
| 477 |
+
|
| 478 |
+
def test_false_show_default_cause_no_default_display_in_prompt(runner):
|
| 479 |
+
@click.command()
|
| 480 |
+
@click.option("--arg1", show_default=False, prompt=True, default="my-default-value")
|
| 481 |
+
def cmd(arg1):
|
| 482 |
+
pass
|
| 483 |
+
|
| 484 |
+
# Confirm that the default value is not included in the output when `show_default`
|
| 485 |
+
# is False
|
| 486 |
+
result = runner.invoke(cmd, input="my-input", standalone_mode=False)
|
| 487 |
+
assert "my-default-value" not in result.output
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_testing.py
ADDED
|
@@ -0,0 +1,430 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
from io import BytesIO
|
| 4 |
+
|
| 5 |
+
import pytest
|
| 6 |
+
|
| 7 |
+
import click
|
| 8 |
+
from click.exceptions import ClickException
|
| 9 |
+
from click.testing import CliRunner
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def test_runner():
|
| 13 |
+
@click.command()
|
| 14 |
+
def test():
|
| 15 |
+
i = click.get_binary_stream("stdin")
|
| 16 |
+
o = click.get_binary_stream("stdout")
|
| 17 |
+
while True:
|
| 18 |
+
chunk = i.read(4096)
|
| 19 |
+
if not chunk:
|
| 20 |
+
break
|
| 21 |
+
o.write(chunk)
|
| 22 |
+
o.flush()
|
| 23 |
+
|
| 24 |
+
runner = CliRunner()
|
| 25 |
+
result = runner.invoke(test, input="Hello World!\n")
|
| 26 |
+
assert not result.exception
|
| 27 |
+
assert result.output == "Hello World!\n"
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def test_echo_stdin_stream():
|
| 31 |
+
@click.command()
|
| 32 |
+
def test():
|
| 33 |
+
i = click.get_binary_stream("stdin")
|
| 34 |
+
o = click.get_binary_stream("stdout")
|
| 35 |
+
while True:
|
| 36 |
+
chunk = i.read(4096)
|
| 37 |
+
if not chunk:
|
| 38 |
+
break
|
| 39 |
+
o.write(chunk)
|
| 40 |
+
o.flush()
|
| 41 |
+
|
| 42 |
+
runner = CliRunner(echo_stdin=True)
|
| 43 |
+
result = runner.invoke(test, input="Hello World!\n")
|
| 44 |
+
assert not result.exception
|
| 45 |
+
assert result.output == "Hello World!\nHello World!\n"
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def test_echo_stdin_prompts():
|
| 49 |
+
@click.command()
|
| 50 |
+
def test_python_input():
|
| 51 |
+
foo = input("Foo: ")
|
| 52 |
+
click.echo(f"foo={foo}")
|
| 53 |
+
|
| 54 |
+
runner = CliRunner(echo_stdin=True)
|
| 55 |
+
result = runner.invoke(test_python_input, input="bar bar\n")
|
| 56 |
+
assert not result.exception
|
| 57 |
+
assert result.output == "Foo: bar bar\nfoo=bar bar\n"
|
| 58 |
+
|
| 59 |
+
@click.command()
|
| 60 |
+
@click.option("--foo", prompt=True)
|
| 61 |
+
def test_prompt(foo):
|
| 62 |
+
click.echo(f"foo={foo}")
|
| 63 |
+
|
| 64 |
+
result = runner.invoke(test_prompt, input="bar bar\n")
|
| 65 |
+
assert not result.exception
|
| 66 |
+
assert result.output == "Foo: bar bar\nfoo=bar bar\n"
|
| 67 |
+
|
| 68 |
+
@click.command()
|
| 69 |
+
@click.option("--foo", prompt=True, hide_input=True)
|
| 70 |
+
def test_hidden_prompt(foo):
|
| 71 |
+
click.echo(f"foo={foo}")
|
| 72 |
+
|
| 73 |
+
result = runner.invoke(test_hidden_prompt, input="bar bar\n")
|
| 74 |
+
assert not result.exception
|
| 75 |
+
assert result.output == "Foo: \nfoo=bar bar\n"
|
| 76 |
+
|
| 77 |
+
@click.command()
|
| 78 |
+
@click.option("--foo", prompt=True)
|
| 79 |
+
@click.option("--bar", prompt=True)
|
| 80 |
+
def test_multiple_prompts(foo, bar):
|
| 81 |
+
click.echo(f"foo={foo}, bar={bar}")
|
| 82 |
+
|
| 83 |
+
result = runner.invoke(test_multiple_prompts, input="one\ntwo\n")
|
| 84 |
+
assert not result.exception
|
| 85 |
+
assert result.output == "Foo: one\nBar: two\nfoo=one, bar=two\n"
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def test_runner_with_stream():
|
| 89 |
+
@click.command()
|
| 90 |
+
def test():
|
| 91 |
+
i = click.get_binary_stream("stdin")
|
| 92 |
+
o = click.get_binary_stream("stdout")
|
| 93 |
+
while True:
|
| 94 |
+
chunk = i.read(4096)
|
| 95 |
+
if not chunk:
|
| 96 |
+
break
|
| 97 |
+
o.write(chunk)
|
| 98 |
+
o.flush()
|
| 99 |
+
|
| 100 |
+
runner = CliRunner()
|
| 101 |
+
result = runner.invoke(test, input=BytesIO(b"Hello World!\n"))
|
| 102 |
+
assert not result.exception
|
| 103 |
+
assert result.output == "Hello World!\n"
|
| 104 |
+
|
| 105 |
+
runner = CliRunner(echo_stdin=True)
|
| 106 |
+
result = runner.invoke(test, input=BytesIO(b"Hello World!\n"))
|
| 107 |
+
assert not result.exception
|
| 108 |
+
assert result.output == "Hello World!\nHello World!\n"
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def test_prompts():
|
| 112 |
+
@click.command()
|
| 113 |
+
@click.option("--foo", prompt=True)
|
| 114 |
+
def test(foo):
|
| 115 |
+
click.echo(f"foo={foo}")
|
| 116 |
+
|
| 117 |
+
runner = CliRunner()
|
| 118 |
+
result = runner.invoke(test, input="wau wau\n")
|
| 119 |
+
assert not result.exception
|
| 120 |
+
assert result.output == "Foo: wau wau\nfoo=wau wau\n"
|
| 121 |
+
|
| 122 |
+
@click.command()
|
| 123 |
+
@click.option("--foo", prompt=True, hide_input=True)
|
| 124 |
+
def test(foo):
|
| 125 |
+
click.echo(f"foo={foo}")
|
| 126 |
+
|
| 127 |
+
runner = CliRunner()
|
| 128 |
+
result = runner.invoke(test, input="wau wau\n")
|
| 129 |
+
assert not result.exception
|
| 130 |
+
assert result.output == "Foo: \nfoo=wau wau\n"
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def test_getchar():
|
| 134 |
+
@click.command()
|
| 135 |
+
def continue_it():
|
| 136 |
+
click.echo(click.getchar())
|
| 137 |
+
|
| 138 |
+
runner = CliRunner()
|
| 139 |
+
result = runner.invoke(continue_it, input="y")
|
| 140 |
+
assert not result.exception
|
| 141 |
+
assert result.output == "y\n"
|
| 142 |
+
|
| 143 |
+
runner = CliRunner(echo_stdin=True)
|
| 144 |
+
result = runner.invoke(continue_it, input="y")
|
| 145 |
+
assert not result.exception
|
| 146 |
+
assert result.output == "y\n"
|
| 147 |
+
|
| 148 |
+
@click.command()
|
| 149 |
+
def getchar_echo():
|
| 150 |
+
click.echo(click.getchar(echo=True))
|
| 151 |
+
|
| 152 |
+
runner = CliRunner()
|
| 153 |
+
result = runner.invoke(getchar_echo, input="y")
|
| 154 |
+
assert not result.exception
|
| 155 |
+
assert result.output == "yy\n"
|
| 156 |
+
|
| 157 |
+
runner = CliRunner(echo_stdin=True)
|
| 158 |
+
result = runner.invoke(getchar_echo, input="y")
|
| 159 |
+
assert not result.exception
|
| 160 |
+
assert result.output == "yy\n"
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
def test_catch_exceptions():
|
| 164 |
+
class CustomError(Exception):
|
| 165 |
+
pass
|
| 166 |
+
|
| 167 |
+
@click.command()
|
| 168 |
+
def cli():
|
| 169 |
+
raise CustomError(1)
|
| 170 |
+
|
| 171 |
+
runner = CliRunner()
|
| 172 |
+
|
| 173 |
+
result = runner.invoke(cli)
|
| 174 |
+
assert isinstance(result.exception, CustomError)
|
| 175 |
+
assert type(result.exc_info) is tuple
|
| 176 |
+
assert len(result.exc_info) == 3
|
| 177 |
+
|
| 178 |
+
with pytest.raises(CustomError):
|
| 179 |
+
runner.invoke(cli, catch_exceptions=False)
|
| 180 |
+
|
| 181 |
+
CustomError = SystemExit
|
| 182 |
+
|
| 183 |
+
result = runner.invoke(cli)
|
| 184 |
+
assert result.exit_code == 1
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def test_with_color():
|
| 188 |
+
@click.command()
|
| 189 |
+
def cli():
|
| 190 |
+
click.secho("hello world", fg="blue")
|
| 191 |
+
|
| 192 |
+
runner = CliRunner()
|
| 193 |
+
|
| 194 |
+
result = runner.invoke(cli)
|
| 195 |
+
assert result.output == "hello world\n"
|
| 196 |
+
assert not result.exception
|
| 197 |
+
|
| 198 |
+
result = runner.invoke(cli, color=True)
|
| 199 |
+
assert result.output == f"{click.style('hello world', fg='blue')}\n"
|
| 200 |
+
assert not result.exception
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def test_with_color_errors():
|
| 204 |
+
class CLIError(ClickException):
|
| 205 |
+
def format_message(self) -> str:
|
| 206 |
+
return click.style(self.message, fg="red")
|
| 207 |
+
|
| 208 |
+
@click.command()
|
| 209 |
+
def cli():
|
| 210 |
+
raise CLIError("Red error")
|
| 211 |
+
|
| 212 |
+
runner = CliRunner()
|
| 213 |
+
|
| 214 |
+
result = runner.invoke(cli)
|
| 215 |
+
assert result.output == "Error: Red error\n"
|
| 216 |
+
assert result.exception
|
| 217 |
+
|
| 218 |
+
result = runner.invoke(cli, color=True)
|
| 219 |
+
assert result.output == f"Error: {click.style('Red error', fg='red')}\n"
|
| 220 |
+
assert result.exception
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def test_with_color_but_pause_not_blocking():
|
| 224 |
+
@click.command()
|
| 225 |
+
def cli():
|
| 226 |
+
click.pause()
|
| 227 |
+
|
| 228 |
+
runner = CliRunner()
|
| 229 |
+
result = runner.invoke(cli, color=True)
|
| 230 |
+
assert not result.exception
|
| 231 |
+
assert result.output == ""
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
def test_exit_code_and_output_from_sys_exit():
|
| 235 |
+
# See issue #362
|
| 236 |
+
@click.command()
|
| 237 |
+
def cli_string():
|
| 238 |
+
click.echo("hello world")
|
| 239 |
+
sys.exit("error")
|
| 240 |
+
|
| 241 |
+
@click.command()
|
| 242 |
+
@click.pass_context
|
| 243 |
+
def cli_string_ctx_exit(ctx):
|
| 244 |
+
click.echo("hello world")
|
| 245 |
+
ctx.exit("error")
|
| 246 |
+
|
| 247 |
+
@click.command()
|
| 248 |
+
def cli_int():
|
| 249 |
+
click.echo("hello world")
|
| 250 |
+
sys.exit(1)
|
| 251 |
+
|
| 252 |
+
@click.command()
|
| 253 |
+
@click.pass_context
|
| 254 |
+
def cli_int_ctx_exit(ctx):
|
| 255 |
+
click.echo("hello world")
|
| 256 |
+
ctx.exit(1)
|
| 257 |
+
|
| 258 |
+
@click.command()
|
| 259 |
+
def cli_float():
|
| 260 |
+
click.echo("hello world")
|
| 261 |
+
sys.exit(1.0)
|
| 262 |
+
|
| 263 |
+
@click.command()
|
| 264 |
+
@click.pass_context
|
| 265 |
+
def cli_float_ctx_exit(ctx):
|
| 266 |
+
click.echo("hello world")
|
| 267 |
+
ctx.exit(1.0)
|
| 268 |
+
|
| 269 |
+
@click.command()
|
| 270 |
+
def cli_no_error():
|
| 271 |
+
click.echo("hello world")
|
| 272 |
+
|
| 273 |
+
runner = CliRunner()
|
| 274 |
+
|
| 275 |
+
result = runner.invoke(cli_string)
|
| 276 |
+
assert result.exit_code == 1
|
| 277 |
+
assert result.output == "hello world\nerror\n"
|
| 278 |
+
|
| 279 |
+
result = runner.invoke(cli_string_ctx_exit)
|
| 280 |
+
assert result.exit_code == 1
|
| 281 |
+
assert result.output == "hello world\nerror\n"
|
| 282 |
+
|
| 283 |
+
result = runner.invoke(cli_int)
|
| 284 |
+
assert result.exit_code == 1
|
| 285 |
+
assert result.output == "hello world\n"
|
| 286 |
+
|
| 287 |
+
result = runner.invoke(cli_int_ctx_exit)
|
| 288 |
+
assert result.exit_code == 1
|
| 289 |
+
assert result.output == "hello world\n"
|
| 290 |
+
|
| 291 |
+
result = runner.invoke(cli_float)
|
| 292 |
+
assert result.exit_code == 1
|
| 293 |
+
assert result.output == "hello world\n1.0\n"
|
| 294 |
+
|
| 295 |
+
result = runner.invoke(cli_float_ctx_exit)
|
| 296 |
+
assert result.exit_code == 1
|
| 297 |
+
assert result.output == "hello world\n1.0\n"
|
| 298 |
+
|
| 299 |
+
result = runner.invoke(cli_no_error)
|
| 300 |
+
assert result.exit_code == 0
|
| 301 |
+
assert result.output == "hello world\n"
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
def test_env():
|
| 305 |
+
@click.command()
|
| 306 |
+
def cli_env():
|
| 307 |
+
click.echo(f"ENV={os.environ['TEST_CLICK_ENV']}")
|
| 308 |
+
|
| 309 |
+
runner = CliRunner()
|
| 310 |
+
|
| 311 |
+
env_orig = dict(os.environ)
|
| 312 |
+
env = dict(env_orig)
|
| 313 |
+
assert "TEST_CLICK_ENV" not in env
|
| 314 |
+
env["TEST_CLICK_ENV"] = "some_value"
|
| 315 |
+
result = runner.invoke(cli_env, env=env)
|
| 316 |
+
assert result.exit_code == 0
|
| 317 |
+
assert result.output == "ENV=some_value\n"
|
| 318 |
+
|
| 319 |
+
assert os.environ == env_orig
|
| 320 |
+
|
| 321 |
+
|
| 322 |
+
def test_stderr():
|
| 323 |
+
@click.command()
|
| 324 |
+
def cli_stderr():
|
| 325 |
+
click.echo("1 - stdout")
|
| 326 |
+
click.echo("2 - stderr", err=True)
|
| 327 |
+
click.echo("3 - stdout")
|
| 328 |
+
click.echo("4 - stderr", err=True)
|
| 329 |
+
|
| 330 |
+
runner_mix = CliRunner()
|
| 331 |
+
result_mix = runner_mix.invoke(cli_stderr)
|
| 332 |
+
|
| 333 |
+
assert result_mix.output == "1 - stdout\n2 - stderr\n3 - stdout\n4 - stderr\n"
|
| 334 |
+
assert result_mix.stdout == "1 - stdout\n3 - stdout\n"
|
| 335 |
+
assert result_mix.stderr == "2 - stderr\n4 - stderr\n"
|
| 336 |
+
|
| 337 |
+
@click.command()
|
| 338 |
+
def cli_empty_stderr():
|
| 339 |
+
click.echo("stdout")
|
| 340 |
+
|
| 341 |
+
runner = CliRunner()
|
| 342 |
+
result = runner.invoke(cli_empty_stderr)
|
| 343 |
+
|
| 344 |
+
assert result.output == "stdout\n"
|
| 345 |
+
assert result.stdout == "stdout\n"
|
| 346 |
+
assert result.stderr == ""
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
@pytest.mark.parametrize(
|
| 350 |
+
"args, expected_output",
|
| 351 |
+
[
|
| 352 |
+
(None, "bar\n"),
|
| 353 |
+
([], "bar\n"),
|
| 354 |
+
("", "bar\n"),
|
| 355 |
+
(["--foo", "one two"], "one two\n"),
|
| 356 |
+
('--foo "one two"', "one two\n"),
|
| 357 |
+
],
|
| 358 |
+
)
|
| 359 |
+
def test_args(args, expected_output):
|
| 360 |
+
@click.command()
|
| 361 |
+
@click.option("--foo", default="bar")
|
| 362 |
+
def cli_args(foo):
|
| 363 |
+
click.echo(foo)
|
| 364 |
+
|
| 365 |
+
runner = CliRunner()
|
| 366 |
+
result = runner.invoke(cli_args, args=args)
|
| 367 |
+
assert result.exit_code == 0
|
| 368 |
+
assert result.output == expected_output
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
def test_setting_prog_name_in_extra():
|
| 372 |
+
@click.command()
|
| 373 |
+
def cli():
|
| 374 |
+
click.echo("ok")
|
| 375 |
+
|
| 376 |
+
runner = CliRunner()
|
| 377 |
+
result = runner.invoke(cli, prog_name="foobar")
|
| 378 |
+
assert not result.exception
|
| 379 |
+
assert result.output == "ok\n"
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
def test_command_standalone_mode_returns_value():
|
| 383 |
+
@click.command()
|
| 384 |
+
def cli():
|
| 385 |
+
click.echo("ok")
|
| 386 |
+
return "Hello, World!"
|
| 387 |
+
|
| 388 |
+
runner = CliRunner()
|
| 389 |
+
result = runner.invoke(cli, standalone_mode=False)
|
| 390 |
+
assert result.output == "ok\n"
|
| 391 |
+
assert result.return_value == "Hello, World!"
|
| 392 |
+
assert result.exit_code == 0
|
| 393 |
+
|
| 394 |
+
|
| 395 |
+
def test_file_stdin_attrs(runner):
|
| 396 |
+
@click.command()
|
| 397 |
+
@click.argument("f", type=click.File())
|
| 398 |
+
def cli(f):
|
| 399 |
+
click.echo(f.name)
|
| 400 |
+
click.echo(f.mode, nl=False)
|
| 401 |
+
|
| 402 |
+
result = runner.invoke(cli, ["-"])
|
| 403 |
+
assert result.output == "<stdin>\nr"
|
| 404 |
+
|
| 405 |
+
|
| 406 |
+
def test_isolated_runner(runner):
|
| 407 |
+
with runner.isolated_filesystem() as d:
|
| 408 |
+
assert os.path.exists(d)
|
| 409 |
+
|
| 410 |
+
assert not os.path.exists(d)
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
def test_isolated_runner_custom_tempdir(runner, tmp_path):
|
| 414 |
+
with runner.isolated_filesystem(temp_dir=tmp_path) as d:
|
| 415 |
+
assert os.path.exists(d)
|
| 416 |
+
|
| 417 |
+
assert os.path.exists(d)
|
| 418 |
+
os.rmdir(d)
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
def test_isolation_stderr_errors():
|
| 422 |
+
"""Writing to stderr should escape invalid characters instead of
|
| 423 |
+
raising a UnicodeEncodeError.
|
| 424 |
+
"""
|
| 425 |
+
runner = CliRunner()
|
| 426 |
+
|
| 427 |
+
with runner.isolation() as (_, err, _):
|
| 428 |
+
click.echo("\udce2", err=True, nl=False)
|
| 429 |
+
|
| 430 |
+
assert err.getvalue() == b"\\udce2"
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_types.py
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os.path
|
| 2 |
+
import pathlib
|
| 3 |
+
import platform
|
| 4 |
+
import tempfile
|
| 5 |
+
|
| 6 |
+
import pytest
|
| 7 |
+
|
| 8 |
+
import click
|
| 9 |
+
from click import FileError
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@pytest.mark.parametrize(
|
| 13 |
+
("type", "value", "expect"),
|
| 14 |
+
[
|
| 15 |
+
(click.IntRange(0, 5), "3", 3),
|
| 16 |
+
(click.IntRange(5), "5", 5),
|
| 17 |
+
(click.IntRange(5), "100", 100),
|
| 18 |
+
(click.IntRange(max=5), "5", 5),
|
| 19 |
+
(click.IntRange(max=5), "-100", -100),
|
| 20 |
+
(click.IntRange(0, clamp=True), "-1", 0),
|
| 21 |
+
(click.IntRange(max=5, clamp=True), "6", 5),
|
| 22 |
+
(click.IntRange(0, min_open=True, clamp=True), "0", 1),
|
| 23 |
+
(click.IntRange(max=5, max_open=True, clamp=True), "5", 4),
|
| 24 |
+
(click.FloatRange(0.5, 1.5), "1.2", 1.2),
|
| 25 |
+
(click.FloatRange(0.5, min_open=True), "0.51", 0.51),
|
| 26 |
+
(click.FloatRange(max=1.5, max_open=True), "1.49", 1.49),
|
| 27 |
+
(click.FloatRange(0.5, clamp=True), "-0.0", 0.5),
|
| 28 |
+
(click.FloatRange(max=1.5, clamp=True), "inf", 1.5),
|
| 29 |
+
],
|
| 30 |
+
)
|
| 31 |
+
def test_range(type, value, expect):
|
| 32 |
+
assert type.convert(value, None, None) == expect
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
@pytest.mark.parametrize(
|
| 36 |
+
("type", "value", "expect"),
|
| 37 |
+
[
|
| 38 |
+
(click.IntRange(0, 5), "6", "6 is not in the range 0<=x<=5."),
|
| 39 |
+
(click.IntRange(5), "4", "4 is not in the range x>=5."),
|
| 40 |
+
(click.IntRange(max=5), "6", "6 is not in the range x<=5."),
|
| 41 |
+
(click.IntRange(0, 5, min_open=True), 0, "0<x<=5"),
|
| 42 |
+
(click.IntRange(0, 5, max_open=True), 5, "0<=x<5"),
|
| 43 |
+
(click.FloatRange(0.5, min_open=True), 0.5, "x>0.5"),
|
| 44 |
+
(click.FloatRange(max=1.5, max_open=True), 1.5, "x<1.5"),
|
| 45 |
+
],
|
| 46 |
+
)
|
| 47 |
+
def test_range_fail(type, value, expect):
|
| 48 |
+
with pytest.raises(click.BadParameter) as exc_info:
|
| 49 |
+
type.convert(value, None, None)
|
| 50 |
+
|
| 51 |
+
assert expect in exc_info.value.message
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def test_float_range_no_clamp_open():
|
| 55 |
+
with pytest.raises(TypeError):
|
| 56 |
+
click.FloatRange(0, 1, max_open=True, clamp=True)
|
| 57 |
+
|
| 58 |
+
sneaky = click.FloatRange(0, 1, max_open=True)
|
| 59 |
+
sneaky.clamp = True
|
| 60 |
+
|
| 61 |
+
with pytest.raises(RuntimeError):
|
| 62 |
+
sneaky.convert("1.5", None, None)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
@pytest.mark.parametrize(
|
| 66 |
+
("nargs", "multiple", "default", "expect"),
|
| 67 |
+
[
|
| 68 |
+
(2, False, None, None),
|
| 69 |
+
(2, False, (None, None), (None, None)),
|
| 70 |
+
(None, True, None, ()),
|
| 71 |
+
(None, True, (None, None), (None, None)),
|
| 72 |
+
(2, True, None, ()),
|
| 73 |
+
(2, True, [(None, None)], ((None, None),)),
|
| 74 |
+
(-1, None, None, ()),
|
| 75 |
+
],
|
| 76 |
+
)
|
| 77 |
+
def test_cast_multi_default(runner, nargs, multiple, default, expect):
|
| 78 |
+
if nargs == -1:
|
| 79 |
+
param = click.Argument(["a"], nargs=nargs, default=default)
|
| 80 |
+
else:
|
| 81 |
+
param = click.Option(["-a"], nargs=nargs, multiple=multiple, default=default)
|
| 82 |
+
|
| 83 |
+
cli = click.Command("cli", params=[param], callback=lambda a: a)
|
| 84 |
+
result = runner.invoke(cli, standalone_mode=False)
|
| 85 |
+
assert result.exception is None
|
| 86 |
+
assert result.return_value == expect
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
@pytest.mark.parametrize(
|
| 90 |
+
("cls", "expect"),
|
| 91 |
+
[
|
| 92 |
+
(None, "a/b/c.txt"),
|
| 93 |
+
(str, "a/b/c.txt"),
|
| 94 |
+
(bytes, b"a/b/c.txt"),
|
| 95 |
+
(pathlib.Path, pathlib.Path("a", "b", "c.txt")),
|
| 96 |
+
],
|
| 97 |
+
)
|
| 98 |
+
def test_path_type(runner, cls, expect):
|
| 99 |
+
cli = click.Command(
|
| 100 |
+
"cli",
|
| 101 |
+
params=[click.Argument(["p"], type=click.Path(path_type=cls))],
|
| 102 |
+
callback=lambda p: p,
|
| 103 |
+
)
|
| 104 |
+
result = runner.invoke(cli, ["a/b/c.txt"], standalone_mode=False)
|
| 105 |
+
assert result.exception is None
|
| 106 |
+
assert result.return_value == expect
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def _symlinks_supported():
|
| 110 |
+
with tempfile.TemporaryDirectory(prefix="click-pytest-") as tempdir:
|
| 111 |
+
target = os.path.join(tempdir, "target")
|
| 112 |
+
open(target, "w").close()
|
| 113 |
+
link = os.path.join(tempdir, "link")
|
| 114 |
+
|
| 115 |
+
try:
|
| 116 |
+
os.symlink(target, link)
|
| 117 |
+
return True
|
| 118 |
+
except OSError:
|
| 119 |
+
return False
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
@pytest.mark.skipif(
|
| 123 |
+
not _symlinks_supported(), reason="The current OS or FS doesn't support symlinks."
|
| 124 |
+
)
|
| 125 |
+
def test_path_resolve_symlink(tmp_path, runner):
|
| 126 |
+
test_file = tmp_path / "file"
|
| 127 |
+
test_file_str = os.fspath(test_file)
|
| 128 |
+
test_file.write_text("")
|
| 129 |
+
|
| 130 |
+
path_type = click.Path(resolve_path=True)
|
| 131 |
+
param = click.Argument(["a"], type=path_type)
|
| 132 |
+
ctx = click.Context(click.Command("cli", params=[param]))
|
| 133 |
+
|
| 134 |
+
test_dir = tmp_path / "dir"
|
| 135 |
+
test_dir.mkdir()
|
| 136 |
+
|
| 137 |
+
abs_link = test_dir / "abs"
|
| 138 |
+
abs_link.symlink_to(test_file)
|
| 139 |
+
abs_rv = path_type.convert(os.fspath(abs_link), param, ctx)
|
| 140 |
+
assert abs_rv == test_file_str
|
| 141 |
+
|
| 142 |
+
rel_link = test_dir / "rel"
|
| 143 |
+
rel_link.symlink_to(pathlib.Path("..") / "file")
|
| 144 |
+
rel_rv = path_type.convert(os.fspath(rel_link), param, ctx)
|
| 145 |
+
assert rel_rv == test_file_str
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def _non_utf8_filenames_supported():
|
| 149 |
+
with tempfile.TemporaryDirectory(prefix="click-pytest-") as tempdir:
|
| 150 |
+
try:
|
| 151 |
+
f = open(os.path.join(tempdir, "\udcff"), "w")
|
| 152 |
+
except OSError:
|
| 153 |
+
return False
|
| 154 |
+
|
| 155 |
+
f.close()
|
| 156 |
+
return True
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
@pytest.mark.skipif(
|
| 160 |
+
not _non_utf8_filenames_supported(),
|
| 161 |
+
reason="The current OS or FS doesn't support non-UTF-8 filenames.",
|
| 162 |
+
)
|
| 163 |
+
def test_path_surrogates(tmp_path, monkeypatch):
|
| 164 |
+
monkeypatch.chdir(tmp_path)
|
| 165 |
+
type = click.Path(exists=True)
|
| 166 |
+
path = pathlib.Path("\udcff")
|
| 167 |
+
|
| 168 |
+
with pytest.raises(click.BadParameter, match="'�' does not exist"):
|
| 169 |
+
type.convert(path, None, None)
|
| 170 |
+
|
| 171 |
+
type = click.Path(file_okay=False)
|
| 172 |
+
path.touch()
|
| 173 |
+
|
| 174 |
+
with pytest.raises(click.BadParameter, match="'�' is a file"):
|
| 175 |
+
type.convert(path, None, None)
|
| 176 |
+
|
| 177 |
+
path.unlink()
|
| 178 |
+
type = click.Path(dir_okay=False)
|
| 179 |
+
path.mkdir()
|
| 180 |
+
|
| 181 |
+
with pytest.raises(click.BadParameter, match="'�' is a directory"):
|
| 182 |
+
type.convert(path, None, None)
|
| 183 |
+
|
| 184 |
+
path.rmdir()
|
| 185 |
+
|
| 186 |
+
def no_access(*args, **kwargs):
|
| 187 |
+
"""Test environments may be running as root, so we have to fake the result of
|
| 188 |
+
the access tests that use os.access
|
| 189 |
+
"""
|
| 190 |
+
p = args[0]
|
| 191 |
+
assert p == path, f"unexpected os.access call on file not under test: {p!r}"
|
| 192 |
+
return False
|
| 193 |
+
|
| 194 |
+
path.touch()
|
| 195 |
+
type = click.Path(readable=True)
|
| 196 |
+
|
| 197 |
+
with pytest.raises(click.BadParameter, match="'�' is not readable"):
|
| 198 |
+
with monkeypatch.context() as m:
|
| 199 |
+
m.setattr(os, "access", no_access)
|
| 200 |
+
type.convert(path, None, None)
|
| 201 |
+
|
| 202 |
+
type = click.Path(readable=False, writable=True)
|
| 203 |
+
|
| 204 |
+
with pytest.raises(click.BadParameter, match="'�' is not writable"):
|
| 205 |
+
with monkeypatch.context() as m:
|
| 206 |
+
m.setattr(os, "access", no_access)
|
| 207 |
+
type.convert(path, None, None)
|
| 208 |
+
|
| 209 |
+
type = click.Path(readable=False, executable=True)
|
| 210 |
+
|
| 211 |
+
with pytest.raises(click.BadParameter, match="'�' is not executable"):
|
| 212 |
+
with monkeypatch.context() as m:
|
| 213 |
+
m.setattr(os, "access", no_access)
|
| 214 |
+
type.convert(path, None, None)
|
| 215 |
+
|
| 216 |
+
path.unlink()
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
@pytest.mark.parametrize(
|
| 220 |
+
"type",
|
| 221 |
+
[
|
| 222 |
+
click.File(mode="r"),
|
| 223 |
+
click.File(mode="r", lazy=True),
|
| 224 |
+
],
|
| 225 |
+
)
|
| 226 |
+
def test_file_surrogates(type, tmp_path):
|
| 227 |
+
path = tmp_path / "\udcff"
|
| 228 |
+
|
| 229 |
+
with pytest.raises(click.BadParameter, match="�': No such file or directory"):
|
| 230 |
+
type.convert(path, None, None)
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
def test_file_error_surrogates():
|
| 234 |
+
message = FileError(filename="\udcff").format_message()
|
| 235 |
+
assert message == "Could not open file '�': unknown error"
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
@pytest.mark.skipif(
|
| 239 |
+
platform.system() == "Windows", reason="Filepath syntax differences."
|
| 240 |
+
)
|
| 241 |
+
def test_invalid_path_with_esc_sequence():
|
| 242 |
+
with pytest.raises(click.BadParameter) as exc_info:
|
| 243 |
+
with tempfile.TemporaryDirectory(prefix="my\ndir") as tempdir:
|
| 244 |
+
click.Path(dir_okay=False).convert(tempdir, None, None)
|
| 245 |
+
|
| 246 |
+
assert "my\\ndir" in exc_info.value.message
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def test_choice_get_invalid_choice_message():
|
| 250 |
+
choice = click.Choice(["a", "b", "c"])
|
| 251 |
+
message = choice.get_invalid_choice_message("d")
|
| 252 |
+
assert message == "'d' is not one of 'a', 'b', 'c'."
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/test_utils.py
ADDED
|
@@ -0,0 +1,653 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import pathlib
|
| 3 |
+
import stat
|
| 4 |
+
import sys
|
| 5 |
+
from collections import namedtuple
|
| 6 |
+
from io import StringIO
|
| 7 |
+
from tempfile import tempdir
|
| 8 |
+
|
| 9 |
+
import pytest
|
| 10 |
+
|
| 11 |
+
import click._termui_impl
|
| 12 |
+
import click.utils
|
| 13 |
+
from click._compat import WIN
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def test_echo(runner):
|
| 17 |
+
with runner.isolation() as outstreams:
|
| 18 |
+
click.echo("\N{SNOWMAN}")
|
| 19 |
+
click.echo(b"\x44\x44")
|
| 20 |
+
click.echo(42, nl=False)
|
| 21 |
+
click.echo(b"a", nl=False)
|
| 22 |
+
click.echo("\x1b[31mx\x1b[39m", nl=False)
|
| 23 |
+
bytes = outstreams[0].getvalue().replace(b"\r\n", b"\n")
|
| 24 |
+
assert bytes == b"\xe2\x98\x83\nDD\n42ax"
|
| 25 |
+
|
| 26 |
+
# if wrapped, we expect bytes to survive.
|
| 27 |
+
@click.command()
|
| 28 |
+
def cli():
|
| 29 |
+
click.echo(b"\xf6")
|
| 30 |
+
|
| 31 |
+
result = runner.invoke(cli, [])
|
| 32 |
+
assert result.stdout_bytes == b"\xf6\n"
|
| 33 |
+
|
| 34 |
+
# Ensure we do not strip for bytes.
|
| 35 |
+
with runner.isolation() as outstreams:
|
| 36 |
+
click.echo(bytearray(b"\x1b[31mx\x1b[39m"), nl=False)
|
| 37 |
+
assert outstreams[0].getvalue() == b"\x1b[31mx\x1b[39m"
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def test_echo_custom_file():
|
| 41 |
+
f = StringIO()
|
| 42 |
+
click.echo("hello", file=f)
|
| 43 |
+
assert f.getvalue() == "hello\n"
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def test_echo_no_streams(monkeypatch, runner):
|
| 47 |
+
"""echo should not fail when stdout and stderr are None with pythonw on Windows."""
|
| 48 |
+
with runner.isolation():
|
| 49 |
+
sys.stdout = None
|
| 50 |
+
sys.stderr = None
|
| 51 |
+
click.echo("test")
|
| 52 |
+
click.echo("test", err=True)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
@pytest.mark.parametrize(
|
| 56 |
+
("styles", "ref"),
|
| 57 |
+
[
|
| 58 |
+
({"fg": "black"}, "\x1b[30mx y\x1b[0m"),
|
| 59 |
+
({"fg": "red"}, "\x1b[31mx y\x1b[0m"),
|
| 60 |
+
({"fg": "green"}, "\x1b[32mx y\x1b[0m"),
|
| 61 |
+
({"fg": "yellow"}, "\x1b[33mx y\x1b[0m"),
|
| 62 |
+
({"fg": "blue"}, "\x1b[34mx y\x1b[0m"),
|
| 63 |
+
({"fg": "magenta"}, "\x1b[35mx y\x1b[0m"),
|
| 64 |
+
({"fg": "cyan"}, "\x1b[36mx y\x1b[0m"),
|
| 65 |
+
({"fg": "white"}, "\x1b[37mx y\x1b[0m"),
|
| 66 |
+
({"bg": "black"}, "\x1b[40mx y\x1b[0m"),
|
| 67 |
+
({"bg": "red"}, "\x1b[41mx y\x1b[0m"),
|
| 68 |
+
({"bg": "green"}, "\x1b[42mx y\x1b[0m"),
|
| 69 |
+
({"bg": "yellow"}, "\x1b[43mx y\x1b[0m"),
|
| 70 |
+
({"bg": "blue"}, "\x1b[44mx y\x1b[0m"),
|
| 71 |
+
({"bg": "magenta"}, "\x1b[45mx y\x1b[0m"),
|
| 72 |
+
({"bg": "cyan"}, "\x1b[46mx y\x1b[0m"),
|
| 73 |
+
({"bg": "white"}, "\x1b[47mx y\x1b[0m"),
|
| 74 |
+
({"bg": 91}, "\x1b[48;5;91mx y\x1b[0m"),
|
| 75 |
+
({"bg": (135, 0, 175)}, "\x1b[48;2;135;0;175mx y\x1b[0m"),
|
| 76 |
+
({"bold": True}, "\x1b[1mx y\x1b[0m"),
|
| 77 |
+
({"dim": True}, "\x1b[2mx y\x1b[0m"),
|
| 78 |
+
({"underline": True}, "\x1b[4mx y\x1b[0m"),
|
| 79 |
+
({"overline": True}, "\x1b[53mx y\x1b[0m"),
|
| 80 |
+
({"italic": True}, "\x1b[3mx y\x1b[0m"),
|
| 81 |
+
({"blink": True}, "\x1b[5mx y\x1b[0m"),
|
| 82 |
+
({"reverse": True}, "\x1b[7mx y\x1b[0m"),
|
| 83 |
+
({"strikethrough": True}, "\x1b[9mx y\x1b[0m"),
|
| 84 |
+
({"bold": False}, "\x1b[22mx y\x1b[0m"),
|
| 85 |
+
({"dim": False}, "\x1b[22mx y\x1b[0m"),
|
| 86 |
+
({"underline": False}, "\x1b[24mx y\x1b[0m"),
|
| 87 |
+
({"overline": False}, "\x1b[55mx y\x1b[0m"),
|
| 88 |
+
({"italic": False}, "\x1b[23mx y\x1b[0m"),
|
| 89 |
+
({"blink": False}, "\x1b[25mx y\x1b[0m"),
|
| 90 |
+
({"reverse": False}, "\x1b[27mx y\x1b[0m"),
|
| 91 |
+
({"strikethrough": False}, "\x1b[29mx y\x1b[0m"),
|
| 92 |
+
({"fg": "black", "reset": False}, "\x1b[30mx y"),
|
| 93 |
+
],
|
| 94 |
+
)
|
| 95 |
+
def test_styling(styles, ref):
|
| 96 |
+
assert click.style("x y", **styles) == ref
|
| 97 |
+
assert click.unstyle(ref) == "x y"
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
@pytest.mark.parametrize(("text", "expect"), [("\x1b[?25lx y\x1b[?25h", "x y")])
|
| 101 |
+
def test_unstyle_other_ansi(text, expect):
|
| 102 |
+
assert click.unstyle(text) == expect
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def test_filename_formatting():
|
| 106 |
+
assert click.format_filename(b"foo.txt") == "foo.txt"
|
| 107 |
+
assert click.format_filename(b"/x/foo.txt") == "/x/foo.txt"
|
| 108 |
+
assert click.format_filename("/x/foo.txt") == "/x/foo.txt"
|
| 109 |
+
assert click.format_filename("/x/foo.txt", shorten=True) == "foo.txt"
|
| 110 |
+
assert click.format_filename(b"/x/\xff.txt", shorten=True) == "�.txt"
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def test_prompts(runner):
|
| 114 |
+
@click.command()
|
| 115 |
+
def test():
|
| 116 |
+
if click.confirm("Foo"):
|
| 117 |
+
click.echo("yes!")
|
| 118 |
+
else:
|
| 119 |
+
click.echo("no :(")
|
| 120 |
+
|
| 121 |
+
result = runner.invoke(test, input="y\n")
|
| 122 |
+
assert not result.exception
|
| 123 |
+
assert result.output == "Foo [y/N]: y\nyes!\n"
|
| 124 |
+
|
| 125 |
+
result = runner.invoke(test, input="\n")
|
| 126 |
+
assert not result.exception
|
| 127 |
+
assert result.output == "Foo [y/N]: \nno :(\n"
|
| 128 |
+
|
| 129 |
+
result = runner.invoke(test, input="n\n")
|
| 130 |
+
assert not result.exception
|
| 131 |
+
assert result.output == "Foo [y/N]: n\nno :(\n"
|
| 132 |
+
|
| 133 |
+
@click.command()
|
| 134 |
+
def test_no():
|
| 135 |
+
if click.confirm("Foo", default=True):
|
| 136 |
+
click.echo("yes!")
|
| 137 |
+
else:
|
| 138 |
+
click.echo("no :(")
|
| 139 |
+
|
| 140 |
+
result = runner.invoke(test_no, input="y\n")
|
| 141 |
+
assert not result.exception
|
| 142 |
+
assert result.output == "Foo [Y/n]: y\nyes!\n"
|
| 143 |
+
|
| 144 |
+
result = runner.invoke(test_no, input="\n")
|
| 145 |
+
assert not result.exception
|
| 146 |
+
assert result.output == "Foo [Y/n]: \nyes!\n"
|
| 147 |
+
|
| 148 |
+
result = runner.invoke(test_no, input="n\n")
|
| 149 |
+
assert not result.exception
|
| 150 |
+
assert result.output == "Foo [Y/n]: n\nno :(\n"
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def test_confirm_repeat(runner):
|
| 154 |
+
cli = click.Command(
|
| 155 |
+
"cli", params=[click.Option(["--a/--no-a"], default=None, prompt=True)]
|
| 156 |
+
)
|
| 157 |
+
result = runner.invoke(cli, input="\ny\n")
|
| 158 |
+
assert result.output == "A [y/n]: \nError: invalid input\nA [y/n]: y\n"
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
@pytest.mark.skipif(WIN, reason="Different behavior on windows.")
|
| 162 |
+
def test_prompts_abort(monkeypatch, capsys):
|
| 163 |
+
def f(_):
|
| 164 |
+
raise KeyboardInterrupt()
|
| 165 |
+
|
| 166 |
+
monkeypatch.setattr("click.termui.hidden_prompt_func", f)
|
| 167 |
+
|
| 168 |
+
try:
|
| 169 |
+
click.prompt("Password", hide_input=True)
|
| 170 |
+
except click.Abort:
|
| 171 |
+
click.echo("interrupted")
|
| 172 |
+
|
| 173 |
+
out, err = capsys.readouterr()
|
| 174 |
+
assert out == "Password:\ninterrupted\n"
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
def _test_gen_func():
|
| 178 |
+
yield "a"
|
| 179 |
+
yield "b"
|
| 180 |
+
yield "c"
|
| 181 |
+
yield "abc"
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
def _test_gen_func_fails():
|
| 185 |
+
yield "test"
|
| 186 |
+
raise RuntimeError("This is a test.")
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def _test_gen_func_echo(file=None):
|
| 190 |
+
yield "test"
|
| 191 |
+
click.echo("hello", file=file)
|
| 192 |
+
yield "test"
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
def _test_simulate_keyboard_interrupt(file=None):
|
| 196 |
+
yield "output_before_keyboard_interrupt"
|
| 197 |
+
raise KeyboardInterrupt()
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
EchoViaPagerTest = namedtuple(
|
| 201 |
+
"EchoViaPagerTest",
|
| 202 |
+
(
|
| 203 |
+
"description",
|
| 204 |
+
"test_input",
|
| 205 |
+
"expected_pager",
|
| 206 |
+
"expected_stdout",
|
| 207 |
+
"expected_stderr",
|
| 208 |
+
"expected_error",
|
| 209 |
+
),
|
| 210 |
+
)
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
@pytest.mark.skipif(WIN, reason="Different behavior on windows.")
|
| 214 |
+
@pytest.mark.parametrize(
|
| 215 |
+
"test",
|
| 216 |
+
[
|
| 217 |
+
# We need to pass a parameter function instead of a plain param
|
| 218 |
+
# as pytest.mark.parametrize will reuse the parameters causing the
|
| 219 |
+
# generators to be used up so they will not yield anymore
|
| 220 |
+
EchoViaPagerTest(
|
| 221 |
+
description="Plain string argument",
|
| 222 |
+
test_input=lambda: "just text",
|
| 223 |
+
expected_pager="just text\n",
|
| 224 |
+
expected_stdout="",
|
| 225 |
+
expected_stderr="",
|
| 226 |
+
expected_error=None,
|
| 227 |
+
),
|
| 228 |
+
EchoViaPagerTest(
|
| 229 |
+
description="Iterable argument",
|
| 230 |
+
test_input=lambda: ["itera", "ble"],
|
| 231 |
+
expected_pager="iterable\n",
|
| 232 |
+
expected_stdout="",
|
| 233 |
+
expected_stderr="",
|
| 234 |
+
expected_error=None,
|
| 235 |
+
),
|
| 236 |
+
EchoViaPagerTest(
|
| 237 |
+
description="Generator function argument",
|
| 238 |
+
test_input=lambda: _test_gen_func,
|
| 239 |
+
expected_pager="abcabc\n",
|
| 240 |
+
expected_stdout="",
|
| 241 |
+
expected_stderr="",
|
| 242 |
+
expected_error=None,
|
| 243 |
+
),
|
| 244 |
+
EchoViaPagerTest(
|
| 245 |
+
description="String generator argument",
|
| 246 |
+
test_input=lambda: _test_gen_func(),
|
| 247 |
+
expected_pager="abcabc\n",
|
| 248 |
+
expected_stdout="",
|
| 249 |
+
expected_stderr="",
|
| 250 |
+
expected_error=None,
|
| 251 |
+
),
|
| 252 |
+
EchoViaPagerTest(
|
| 253 |
+
description="Number generator expression argument",
|
| 254 |
+
test_input=lambda: (c for c in range(6)),
|
| 255 |
+
expected_pager="012345\n",
|
| 256 |
+
expected_stdout="",
|
| 257 |
+
expected_stderr="",
|
| 258 |
+
expected_error=None,
|
| 259 |
+
),
|
| 260 |
+
EchoViaPagerTest(
|
| 261 |
+
description="Exception in generator function argument",
|
| 262 |
+
test_input=lambda: _test_gen_func_fails,
|
| 263 |
+
# Because generator throws early on, the pager did not have
|
| 264 |
+
# a chance yet to write the file.
|
| 265 |
+
expected_pager=None,
|
| 266 |
+
expected_stdout="",
|
| 267 |
+
expected_stderr="",
|
| 268 |
+
expected_error=RuntimeError,
|
| 269 |
+
),
|
| 270 |
+
EchoViaPagerTest(
|
| 271 |
+
description="Exception in generator argument",
|
| 272 |
+
test_input=lambda: _test_gen_func_fails,
|
| 273 |
+
# Because generator throws early on, the pager did not have a
|
| 274 |
+
# chance yet to write the file.
|
| 275 |
+
expected_pager=None,
|
| 276 |
+
expected_stdout="",
|
| 277 |
+
expected_stderr="",
|
| 278 |
+
expected_error=RuntimeError,
|
| 279 |
+
),
|
| 280 |
+
EchoViaPagerTest(
|
| 281 |
+
description="Keyboard interrupt should not terminate the pager",
|
| 282 |
+
test_input=lambda: _test_simulate_keyboard_interrupt(),
|
| 283 |
+
# Due to the keyboard interrupt during pager execution, click program
|
| 284 |
+
# should abort, but the pager should stay open.
|
| 285 |
+
# This allows users to cancel the program and search in the pager
|
| 286 |
+
# output, before they decide to terminate the pager.
|
| 287 |
+
expected_pager="output_before_keyboard_interrupt",
|
| 288 |
+
expected_stdout="",
|
| 289 |
+
expected_stderr="",
|
| 290 |
+
expected_error=KeyboardInterrupt,
|
| 291 |
+
),
|
| 292 |
+
EchoViaPagerTest(
|
| 293 |
+
description="Writing to stdout during generator execution",
|
| 294 |
+
test_input=lambda: _test_gen_func_echo(),
|
| 295 |
+
expected_pager="testtest\n",
|
| 296 |
+
expected_stdout="hello\n",
|
| 297 |
+
expected_stderr="",
|
| 298 |
+
expected_error=None,
|
| 299 |
+
),
|
| 300 |
+
EchoViaPagerTest(
|
| 301 |
+
description="Writing to stderr during generator execution",
|
| 302 |
+
test_input=lambda: _test_gen_func_echo(file=sys.stderr),
|
| 303 |
+
expected_pager="testtest\n",
|
| 304 |
+
expected_stdout="",
|
| 305 |
+
expected_stderr="hello\n",
|
| 306 |
+
expected_error=None,
|
| 307 |
+
),
|
| 308 |
+
],
|
| 309 |
+
)
|
| 310 |
+
def test_echo_via_pager(monkeypatch, capfd, test):
|
| 311 |
+
pager_out_tmp = f"{tempdir}/pager_out.txt"
|
| 312 |
+
|
| 313 |
+
if os.path.exists(pager_out_tmp):
|
| 314 |
+
os.remove(pager_out_tmp)
|
| 315 |
+
|
| 316 |
+
monkeypatch.setitem(os.environ, "PAGER", f"cat > {pager_out_tmp}")
|
| 317 |
+
monkeypatch.setattr(click._termui_impl, "isatty", lambda x: True)
|
| 318 |
+
|
| 319 |
+
test_input = test.test_input()
|
| 320 |
+
expected_pager = test.expected_pager
|
| 321 |
+
expected_stdout = test.expected_stdout
|
| 322 |
+
expected_stderr = test.expected_stderr
|
| 323 |
+
expected_error = test.expected_error
|
| 324 |
+
|
| 325 |
+
if expected_error:
|
| 326 |
+
with pytest.raises(expected_error):
|
| 327 |
+
click.echo_via_pager(test_input)
|
| 328 |
+
else:
|
| 329 |
+
click.echo_via_pager(test_input)
|
| 330 |
+
|
| 331 |
+
out, err = capfd.readouterr()
|
| 332 |
+
|
| 333 |
+
if os.path.exists(pager_out_tmp):
|
| 334 |
+
with open(pager_out_tmp) as f:
|
| 335 |
+
pager = f.read()
|
| 336 |
+
else:
|
| 337 |
+
# The pager process was not started or has been
|
| 338 |
+
# terminated before it could finish writing
|
| 339 |
+
pager = None
|
| 340 |
+
|
| 341 |
+
assert (
|
| 342 |
+
pager == expected_pager
|
| 343 |
+
), f"Unexpected pager output in test case '{test.description}'"
|
| 344 |
+
assert (
|
| 345 |
+
out == expected_stdout
|
| 346 |
+
), f"Unexpected stdout in test case '{test.description}'"
|
| 347 |
+
assert (
|
| 348 |
+
err == expected_stderr
|
| 349 |
+
), f"Unexpected stderr in test case '{test.description}'"
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
def test_echo_color_flag(monkeypatch, capfd):
|
| 353 |
+
isatty = True
|
| 354 |
+
monkeypatch.setattr(click._compat, "isatty", lambda x: isatty)
|
| 355 |
+
|
| 356 |
+
text = "foo"
|
| 357 |
+
styled_text = click.style(text, fg="red")
|
| 358 |
+
assert styled_text == "\x1b[31mfoo\x1b[0m"
|
| 359 |
+
|
| 360 |
+
click.echo(styled_text, color=False)
|
| 361 |
+
out, err = capfd.readouterr()
|
| 362 |
+
assert out == f"{text}\n"
|
| 363 |
+
|
| 364 |
+
click.echo(styled_text, color=True)
|
| 365 |
+
out, err = capfd.readouterr()
|
| 366 |
+
assert out == f"{styled_text}\n"
|
| 367 |
+
|
| 368 |
+
isatty = True
|
| 369 |
+
click.echo(styled_text)
|
| 370 |
+
out, err = capfd.readouterr()
|
| 371 |
+
assert out == f"{styled_text}\n"
|
| 372 |
+
|
| 373 |
+
isatty = False
|
| 374 |
+
# Faking isatty() is not enough on Windows;
|
| 375 |
+
# the implementation caches the colorama wrapped stream
|
| 376 |
+
# so we have to use a new stream for each test
|
| 377 |
+
stream = StringIO()
|
| 378 |
+
click.echo(styled_text, file=stream)
|
| 379 |
+
assert stream.getvalue() == f"{text}\n"
|
| 380 |
+
|
| 381 |
+
stream = StringIO()
|
| 382 |
+
click.echo(styled_text, file=stream, color=True)
|
| 383 |
+
assert stream.getvalue() == f"{styled_text}\n"
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
def test_prompt_cast_default(capfd, monkeypatch):
|
| 387 |
+
monkeypatch.setattr(sys, "stdin", StringIO("\n"))
|
| 388 |
+
value = click.prompt("value", default="100", type=int)
|
| 389 |
+
capfd.readouterr()
|
| 390 |
+
assert isinstance(value, int)
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
@pytest.mark.skipif(WIN, reason="Test too complex to make work windows.")
|
| 394 |
+
def test_echo_writing_to_standard_error(capfd, monkeypatch):
|
| 395 |
+
def emulate_input(text):
|
| 396 |
+
"""Emulate keyboard input."""
|
| 397 |
+
monkeypatch.setattr(sys, "stdin", StringIO(text))
|
| 398 |
+
|
| 399 |
+
click.echo("Echo to standard output")
|
| 400 |
+
out, err = capfd.readouterr()
|
| 401 |
+
assert out == "Echo to standard output\n"
|
| 402 |
+
assert err == ""
|
| 403 |
+
|
| 404 |
+
click.echo("Echo to standard error", err=True)
|
| 405 |
+
out, err = capfd.readouterr()
|
| 406 |
+
assert out == ""
|
| 407 |
+
assert err == "Echo to standard error\n"
|
| 408 |
+
|
| 409 |
+
emulate_input("asdlkj\n")
|
| 410 |
+
click.prompt("Prompt to stdin")
|
| 411 |
+
out, err = capfd.readouterr()
|
| 412 |
+
assert out == "Prompt to stdin: "
|
| 413 |
+
assert err == ""
|
| 414 |
+
|
| 415 |
+
emulate_input("asdlkj\n")
|
| 416 |
+
click.prompt("Prompt to stderr", err=True)
|
| 417 |
+
out, err = capfd.readouterr()
|
| 418 |
+
assert out == " "
|
| 419 |
+
assert err == "Prompt to stderr:"
|
| 420 |
+
|
| 421 |
+
emulate_input("y\n")
|
| 422 |
+
click.confirm("Prompt to stdin")
|
| 423 |
+
out, err = capfd.readouterr()
|
| 424 |
+
assert out == "Prompt to stdin [y/N]: "
|
| 425 |
+
assert err == ""
|
| 426 |
+
|
| 427 |
+
emulate_input("y\n")
|
| 428 |
+
click.confirm("Prompt to stderr", err=True)
|
| 429 |
+
out, err = capfd.readouterr()
|
| 430 |
+
assert out == " "
|
| 431 |
+
assert err == "Prompt to stderr [y/N]:"
|
| 432 |
+
|
| 433 |
+
monkeypatch.setattr(click.termui, "isatty", lambda x: True)
|
| 434 |
+
monkeypatch.setattr(click.termui, "getchar", lambda: " ")
|
| 435 |
+
|
| 436 |
+
click.pause("Pause to stdout")
|
| 437 |
+
out, err = capfd.readouterr()
|
| 438 |
+
assert out == "Pause to stdout\n"
|
| 439 |
+
assert err == ""
|
| 440 |
+
|
| 441 |
+
click.pause("Pause to stderr", err=True)
|
| 442 |
+
out, err = capfd.readouterr()
|
| 443 |
+
assert out == ""
|
| 444 |
+
assert err == "Pause to stderr\n"
|
| 445 |
+
|
| 446 |
+
|
| 447 |
+
def test_echo_with_capsys(capsys):
|
| 448 |
+
click.echo("Capture me.")
|
| 449 |
+
out, err = capsys.readouterr()
|
| 450 |
+
assert out == "Capture me.\n"
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
def test_open_file(runner):
|
| 454 |
+
@click.command()
|
| 455 |
+
@click.argument("filename")
|
| 456 |
+
def cli(filename):
|
| 457 |
+
with click.open_file(filename) as f:
|
| 458 |
+
click.echo(f.read())
|
| 459 |
+
|
| 460 |
+
click.echo("meep")
|
| 461 |
+
|
| 462 |
+
with runner.isolated_filesystem():
|
| 463 |
+
with open("hello.txt", "w") as f:
|
| 464 |
+
f.write("Cool stuff")
|
| 465 |
+
|
| 466 |
+
result = runner.invoke(cli, ["hello.txt"])
|
| 467 |
+
assert result.exception is None
|
| 468 |
+
assert result.output == "Cool stuff\nmeep\n"
|
| 469 |
+
|
| 470 |
+
result = runner.invoke(cli, ["-"], input="foobar")
|
| 471 |
+
assert result.exception is None
|
| 472 |
+
assert result.output == "foobar\nmeep\n"
|
| 473 |
+
|
| 474 |
+
|
| 475 |
+
def test_open_file_pathlib_dash(runner):
|
| 476 |
+
@click.command()
|
| 477 |
+
@click.argument(
|
| 478 |
+
"filename", type=click.Path(allow_dash=True, path_type=pathlib.Path)
|
| 479 |
+
)
|
| 480 |
+
def cli(filename):
|
| 481 |
+
click.echo(str(type(filename)))
|
| 482 |
+
|
| 483 |
+
with click.open_file(filename) as f:
|
| 484 |
+
click.echo(f.read())
|
| 485 |
+
|
| 486 |
+
result = runner.invoke(cli, ["-"], input="value")
|
| 487 |
+
assert result.exception is None
|
| 488 |
+
assert result.output == "pathlib.Path\nvalue\n"
|
| 489 |
+
|
| 490 |
+
|
| 491 |
+
def test_open_file_ignore_errors_stdin(runner):
|
| 492 |
+
@click.command()
|
| 493 |
+
@click.argument("filename")
|
| 494 |
+
def cli(filename):
|
| 495 |
+
with click.open_file(filename, errors="ignore") as f:
|
| 496 |
+
click.echo(f.read())
|
| 497 |
+
|
| 498 |
+
result = runner.invoke(cli, ["-"], input=os.urandom(16))
|
| 499 |
+
assert result.exception is None
|
| 500 |
+
|
| 501 |
+
|
| 502 |
+
def test_open_file_respects_ignore(runner):
|
| 503 |
+
with runner.isolated_filesystem():
|
| 504 |
+
with open("test.txt", "w") as f:
|
| 505 |
+
f.write("Hello world!")
|
| 506 |
+
|
| 507 |
+
with click.open_file("test.txt", encoding="utf8", errors="ignore") as f:
|
| 508 |
+
assert f.errors == "ignore"
|
| 509 |
+
|
| 510 |
+
|
| 511 |
+
def test_open_file_ignore_invalid_utf8(runner):
|
| 512 |
+
with runner.isolated_filesystem():
|
| 513 |
+
with open("test.txt", "wb") as f:
|
| 514 |
+
f.write(b"\xe2\x28\xa1")
|
| 515 |
+
|
| 516 |
+
with click.open_file("test.txt", encoding="utf8", errors="ignore") as f:
|
| 517 |
+
f.read()
|
| 518 |
+
|
| 519 |
+
|
| 520 |
+
def test_open_file_ignore_no_encoding(runner):
|
| 521 |
+
with runner.isolated_filesystem():
|
| 522 |
+
with open("test.bin", "wb") as f:
|
| 523 |
+
f.write(os.urandom(16))
|
| 524 |
+
|
| 525 |
+
with click.open_file("test.bin", errors="ignore") as f:
|
| 526 |
+
f.read()
|
| 527 |
+
|
| 528 |
+
|
| 529 |
+
@pytest.mark.skipif(WIN, reason="os.chmod() is not fully supported on Windows.")
|
| 530 |
+
@pytest.mark.parametrize("permissions", [0o400, 0o444, 0o600, 0o644])
|
| 531 |
+
def test_open_file_atomic_permissions_existing_file(runner, permissions):
|
| 532 |
+
with runner.isolated_filesystem():
|
| 533 |
+
with open("existing.txt", "w") as f:
|
| 534 |
+
f.write("content")
|
| 535 |
+
os.chmod("existing.txt", permissions)
|
| 536 |
+
|
| 537 |
+
@click.command()
|
| 538 |
+
@click.argument("filename")
|
| 539 |
+
def cli(filename):
|
| 540 |
+
click.open_file(filename, "w", atomic=True).close()
|
| 541 |
+
|
| 542 |
+
result = runner.invoke(cli, ["existing.txt"])
|
| 543 |
+
assert result.exception is None
|
| 544 |
+
assert stat.S_IMODE(os.stat("existing.txt").st_mode) == permissions
|
| 545 |
+
|
| 546 |
+
|
| 547 |
+
@pytest.mark.skipif(WIN, reason="os.stat() is not fully supported on Windows.")
|
| 548 |
+
def test_open_file_atomic_permissions_new_file(runner):
|
| 549 |
+
with runner.isolated_filesystem():
|
| 550 |
+
|
| 551 |
+
@click.command()
|
| 552 |
+
@click.argument("filename")
|
| 553 |
+
def cli(filename):
|
| 554 |
+
click.open_file(filename, "w", atomic=True).close()
|
| 555 |
+
|
| 556 |
+
# Create a test file to get the expected permissions for new files
|
| 557 |
+
# according to the current umask.
|
| 558 |
+
with open("test.txt", "w"):
|
| 559 |
+
pass
|
| 560 |
+
permissions = stat.S_IMODE(os.stat("test.txt").st_mode)
|
| 561 |
+
|
| 562 |
+
result = runner.invoke(cli, ["new.txt"])
|
| 563 |
+
assert result.exception is None
|
| 564 |
+
assert stat.S_IMODE(os.stat("new.txt").st_mode) == permissions
|
| 565 |
+
|
| 566 |
+
|
| 567 |
+
def test_iter_keepopenfile(tmpdir):
|
| 568 |
+
expected = list(map(str, range(10)))
|
| 569 |
+
p = tmpdir.mkdir("testdir").join("testfile")
|
| 570 |
+
p.write("\n".join(expected))
|
| 571 |
+
with p.open() as f:
|
| 572 |
+
for e_line, a_line in zip(expected, click.utils.KeepOpenFile(f)):
|
| 573 |
+
assert e_line == a_line.strip()
|
| 574 |
+
|
| 575 |
+
|
| 576 |
+
def test_iter_lazyfile(tmpdir):
|
| 577 |
+
expected = list(map(str, range(10)))
|
| 578 |
+
p = tmpdir.mkdir("testdir").join("testfile")
|
| 579 |
+
p.write("\n".join(expected))
|
| 580 |
+
with p.open() as f:
|
| 581 |
+
with click.utils.LazyFile(f.name) as lf:
|
| 582 |
+
for e_line, a_line in zip(expected, lf):
|
| 583 |
+
assert e_line == a_line.strip()
|
| 584 |
+
|
| 585 |
+
|
| 586 |
+
class MockMain:
|
| 587 |
+
__slots__ = "__package__"
|
| 588 |
+
|
| 589 |
+
def __init__(self, package_name):
|
| 590 |
+
self.__package__ = package_name
|
| 591 |
+
|
| 592 |
+
|
| 593 |
+
@pytest.mark.parametrize(
|
| 594 |
+
("path", "main", "expected"),
|
| 595 |
+
[
|
| 596 |
+
("example.py", None, "example.py"),
|
| 597 |
+
(str(pathlib.Path("/foo/bar/example.py")), None, "example.py"),
|
| 598 |
+
("example", None, "example"),
|
| 599 |
+
(str(pathlib.Path("example/__main__.py")), "example", "python -m example"),
|
| 600 |
+
(str(pathlib.Path("example/cli.py")), "example", "python -m example.cli"),
|
| 601 |
+
(str(pathlib.Path("./example")), "", "example"),
|
| 602 |
+
],
|
| 603 |
+
)
|
| 604 |
+
def test_detect_program_name(path, main, expected):
|
| 605 |
+
assert click.utils._detect_program_name(path, _main=MockMain(main)) == expected
|
| 606 |
+
|
| 607 |
+
|
| 608 |
+
def test_expand_args(monkeypatch):
|
| 609 |
+
user = os.path.expanduser("~")
|
| 610 |
+
assert user in click.utils._expand_args(["~"])
|
| 611 |
+
monkeypatch.setenv("CLICK_TEST", "hello")
|
| 612 |
+
assert "hello" in click.utils._expand_args(["$CLICK_TEST"])
|
| 613 |
+
assert "pyproject.toml" in click.utils._expand_args(["*.toml"])
|
| 614 |
+
assert os.path.join("docs", "conf.py") in click.utils._expand_args(["**/conf.py"])
|
| 615 |
+
assert "*.not-found" in click.utils._expand_args(["*.not-found"])
|
| 616 |
+
# a bad glob pattern, such as a pytest identifier, should return itself
|
| 617 |
+
assert click.utils._expand_args(["test.py::test_bad"])[0] == "test.py::test_bad"
|
| 618 |
+
|
| 619 |
+
|
| 620 |
+
@pytest.mark.parametrize(
|
| 621 |
+
("value", "max_length", "expect"),
|
| 622 |
+
[
|
| 623 |
+
pytest.param("", 10, "", id="empty"),
|
| 624 |
+
pytest.param("123 567 90", 10, "123 567 90", id="equal length, no dot"),
|
| 625 |
+
pytest.param("123 567 9. aaaa bbb", 10, "123 567 9.", id="sentence < max"),
|
| 626 |
+
pytest.param("123 567\n\n 9. aaaa bbb", 10, "123 567", id="paragraph < max"),
|
| 627 |
+
pytest.param("123 567 90123.", 10, "123 567...", id="truncate"),
|
| 628 |
+
pytest.param("123 5678 xxxxxx", 10, "123...", id="length includes suffix"),
|
| 629 |
+
pytest.param(
|
| 630 |
+
"token in ~/.netrc ciao ciao",
|
| 631 |
+
20,
|
| 632 |
+
"token in ~/.netrc...",
|
| 633 |
+
id="ignore dot in word",
|
| 634 |
+
),
|
| 635 |
+
],
|
| 636 |
+
)
|
| 637 |
+
@pytest.mark.parametrize(
|
| 638 |
+
"alter",
|
| 639 |
+
[
|
| 640 |
+
pytest.param(None, id=""),
|
| 641 |
+
pytest.param(
|
| 642 |
+
lambda text: "\n\b\n" + " ".join(text.split(" ")) + "\n", id="no-wrap mark"
|
| 643 |
+
),
|
| 644 |
+
],
|
| 645 |
+
)
|
| 646 |
+
def test_make_default_short_help(value, max_length, alter, expect):
|
| 647 |
+
assert len(expect) <= max_length
|
| 648 |
+
|
| 649 |
+
if alter:
|
| 650 |
+
value = alter(value)
|
| 651 |
+
|
| 652 |
+
out = click.utils.make_default_short_help(value, max_length)
|
| 653 |
+
assert out == expect
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/typing/typing_aliased_group.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Example from https://click.palletsprojects.com/en/8.1.x/advanced/#command-aliases"""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing_extensions import assert_type
|
| 6 |
+
|
| 7 |
+
import click
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class AliasedGroup(click.Group):
|
| 11 |
+
def get_command(self, ctx: click.Context, cmd_name: str) -> click.Command | None:
|
| 12 |
+
rv = click.Group.get_command(self, ctx, cmd_name)
|
| 13 |
+
if rv is not None:
|
| 14 |
+
return rv
|
| 15 |
+
matches = [x for x in self.list_commands(ctx) if x.startswith(cmd_name)]
|
| 16 |
+
if not matches:
|
| 17 |
+
return None
|
| 18 |
+
elif len(matches) == 1:
|
| 19 |
+
return click.Group.get_command(self, ctx, matches[0])
|
| 20 |
+
ctx.fail(f"Too many matches: {', '.join(sorted(matches))}")
|
| 21 |
+
|
| 22 |
+
def resolve_command(
|
| 23 |
+
self, ctx: click.Context, args: list[str]
|
| 24 |
+
) -> tuple[str | None, click.Command, list[str]]:
|
| 25 |
+
# always return the full command name
|
| 26 |
+
_, cmd, args = super().resolve_command(ctx, args)
|
| 27 |
+
assert cmd is not None
|
| 28 |
+
return cmd.name, cmd, args
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
@click.command(cls=AliasedGroup)
|
| 32 |
+
def cli() -> None:
|
| 33 |
+
pass
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
assert_type(cli, AliasedGroup)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
@cli.command()
|
| 40 |
+
def push() -> None:
|
| 41 |
+
pass
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
@cli.command()
|
| 45 |
+
def pop() -> None:
|
| 46 |
+
pass
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/typing/typing_confirmation_option.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""From https://click.palletsprojects.com/en/8.1.x/options/#yes-parameters"""
|
| 2 |
+
|
| 3 |
+
from typing_extensions import assert_type
|
| 4 |
+
|
| 5 |
+
import click
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
@click.command()
|
| 9 |
+
@click.confirmation_option(prompt="Are you sure you want to drop the db?")
|
| 10 |
+
def dropdb() -> None:
|
| 11 |
+
click.echo("Dropped all tables!")
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
assert_type(dropdb, click.Command)
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/typing/typing_group_kw_options.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing_extensions import assert_type
|
| 2 |
+
|
| 3 |
+
import click
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
@click.group(context_settings={})
|
| 7 |
+
def hello() -> None:
|
| 8 |
+
pass
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
assert_type(hello, click.Group)
|
tasks/pallets__click.fde47b4b.combine_file__3hfoaaic/tests/trusted/tests/typing/typing_help_option.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing_extensions import assert_type
|
| 2 |
+
|
| 3 |
+
import click
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
@click.command()
|
| 7 |
+
@click.help_option("-h", "--help")
|
| 8 |
+
def hello() -> None:
|
| 9 |
+
"""Simple program that greets NAME for a total of COUNT times."""
|
| 10 |
+
click.echo("Hello!")
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
assert_type(hello, click.Command)
|