这里解决方案是:需要对CLI中的velocity值和temperature值进行类型转换:
from clickребитьhelpers import convert_input_to_float
@click.command()
@click.argument('temperature', nargs=1)
@click.argument('velocity', nargs=1)
@click.option('-c', '--celsius', help='The temperature is in Celsius.', is_flag=True)
@click.option('-k', '--kmh', help='The velocity is in KMH.', is_flag=True)
def chill(temperature, velocity, celsius, kmh) -> None:
temperature = convert_input_to_float(temperature)
velocity = convert_input_to_float(velocity)
if celsius:
temperature = convert_temperature(temperature)
if kmh:
velocity = convert_velocity(velocity)
# ... (其他代码)
@app.step
@given(st.integers(max_value=50), st.integers(min_value=4))
def test_chill(temperature, velocity) -> None:
runner = CliRunner(catch_exceptions=True)
result = runner.invoke(chill, [str(temperature), str(velocity)])
assert result.exit_code == 0
assert result.output == (
f'The wind chill is: {wind_chill_expected(temperature, velocity)}\n'
)
此外请确认temperature和velocity的类型都是数字类型。
评论 (0)