샘플
click 8.4.2: Test a click command without spawning a subprocess
검증된 샘플 — pypi click 8.4.2: Test a click command without spawning a subprocess. python 3.12 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다.
sha256:02f8c2f7fe825dcfb2135cbd593f008e36f7550ce68c3fcfa7c6de1bcfcbb02f
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 2
- 빌드한 서명 키
- 2
선언된 환경
python 3.12 linux x64 python 3.12 python pip
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| python 3.12 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1 |
2026-08-13 |
| python 3.12 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1 |
2026-08-17 |
케이스
HOW- 목표
- Test a click command without spawning a subprocess
- 패키지
- 심벌
-
- click.command
- click.option
- CliRunner
- 환경
- python 3.12
- 생성일
- 2026-08-13T18:43:59Z
컨트랙트
- define a command with an option and an argument
- assert CliRunner invokes it in-process and captures stdout
- assert a bad value exits with code 2 and an error message
- assert the exit code is available without a subprocess
파일
- csx.json
- requirements.txt
- src/__init__.py
- src/cli.py
- test/contract.py
소스
{"case":{"caseId":"case:sha256:d87471a05acabf2b3b96c01132c1c2c680e31e30a713feeb381357de113bb7ba","constraints":{"runtime":"python"},"contract":["define a command with an option and an argument","assert CliRunner invokes it in-process and captures stdout","assert a bad value exits with code 2 and an error message","assert the exit code is available without a subprocess"],"goal":"Test a click command without spawning a subprocess","kind":"HOW","packages":["pkg:pypi/click@8.4.2"],"schemaVersion":1,"symbols":["click.command","click.option","CliRunner"]},"contractCommand":["python","test/contract.py"],"environment":{"arch":"x64","ecosystem":"pypi","executionContext":"python","language":"python","os":"linux","packageManager":"pip","runtime":"python","runtimeVersion":"3.12","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/click@8.4.2"],"schemaVersion":1,"symbols":["click.command","click.option","CliRunner"],"verifierAdapter":"python@1"}
click==8.4.2
"""A click command and the runner that tests it in-process."""
import click
@click.command()
@click.argument("name")
@click.option("--count", default=1, type=int, help="how many times to greet")
@click.option("--shout/--no-shout", default=False)
def greet(name, count, shout):
"""Greet NAME COUNT times."""
line = "hello %s" % name
if shout:
line = line.upper()
for _ in range(count):
click.echo(line)
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from click.testing import CliRunner
from src.cli import greet
runner = CliRunner()
# CliRunner calls the command in this process: no subprocess, no PATH, and
# the exit code and output are both returned rather than having to be
# scraped from a pipe.
result = runner.invoke(greet, ["codesamplex", "--count", "2"])
assert result.exit_code == 0, result.output
assert result.output == "hello codesamplex\nhello codesamplex\n", repr(result.output)
result = runner.invoke(greet, ["csx", "--shout"])
assert result.exit_code == 0
assert result.output.strip() == "HELLO CSX"
# Usage errors exit 2 — click's convention, distinct from an app error.
result = runner.invoke(greet, ["csx", "--count", "not-a-number"])
assert result.exit_code == 2, result.output
assert "not a valid integer" in result.output.lower(), result.output
# A missing required argument is also a usage error, not a crash.
result = runner.invoke(greet, [])
assert result.exit_code == 2
assert "missing argument" in result.output.lower(), result.output
print("CONTRACT PASS: click ran in-process and reported usage errors as exit 2")