(runner)
| 356 | |
| 357 | |
| 358 | def test_file_lazy_mode(runner): |
| 359 | do_io = False |
| 360 | |
| 361 | @click.command() |
| 362 | @click.option("--file", type=click.File("w")) |
| 363 | def input(file): |
| 364 | if do_io: |
| 365 | file.write("Hello World!\n") |
| 366 | |
| 367 | @click.command() |
| 368 | @click.option("--file", type=click.File("r")) |
| 369 | def output(file): |
| 370 | pass |
| 371 | |
| 372 | with runner.isolated_filesystem(): |
| 373 | os.mkdir("example.txt") |
| 374 | |
| 375 | do_io = True |
| 376 | result_in = runner.invoke(input, ["--file=example.txt"]) |
| 377 | assert result_in.exit_code == 1 |
| 378 | |
| 379 | do_io = False |
| 380 | result_in = runner.invoke(input, ["--file=example.txt"]) |
| 381 | assert result_in.exit_code == 0 |
| 382 | |
| 383 | result_out = runner.invoke(output, ["--file=example.txt"]) |
| 384 | assert result_out.exception |
| 385 | |
| 386 | @click.command() |
| 387 | @click.option("--file", type=click.File("w", lazy=False)) |
| 388 | def input_non_lazy(file): |
| 389 | file.write("Hello World!\n") |
| 390 | |
| 391 | with runner.isolated_filesystem(): |
| 392 | os.mkdir("example.txt") |
| 393 | result_in = runner.invoke(input_non_lazy, ["--file=example.txt"]) |
| 394 | assert result_in.exit_code == 2 |
| 395 | assert "Invalid value for '--file': 'example.txt'" in result_in.output |
| 396 | |
| 397 | |
| 398 | def test_path_option(runner): |
nothing calls this directly
no test coverage detected