(runner)
| 396 | |
| 397 | |
| 398 | def test_path_option(runner): |
| 399 | @click.command() |
| 400 | @click.option("-O", type=click.Path(file_okay=False, exists=True, writable=True)) |
| 401 | def write_to_dir(o): |
| 402 | with open(os.path.join(o, "foo.txt"), "wb") as f: |
| 403 | f.write(b"meh\n") |
| 404 | |
| 405 | with runner.isolated_filesystem(): |
| 406 | os.mkdir("test") |
| 407 | |
| 408 | result = runner.invoke(write_to_dir, ["-O", "test"]) |
| 409 | assert not result.exception |
| 410 | |
| 411 | with open("test/foo.txt", "rb") as f: |
| 412 | assert f.read() == b"meh\n" |
| 413 | |
| 414 | result = runner.invoke(write_to_dir, ["-O", "test/foo.txt"]) |
| 415 | assert "is a file" in result.output |
| 416 | |
| 417 | @click.command() |
| 418 | @click.option("-f", type=click.Path(exists=True)) |
| 419 | def showtype(f): |
| 420 | click.echo(f"is_file={os.path.isfile(f)}") |
| 421 | click.echo(f"is_dir={os.path.isdir(f)}") |
| 422 | |
| 423 | with runner.isolated_filesystem(): |
| 424 | result = runner.invoke(showtype, ["-f", "xxx"]) |
| 425 | assert "does not exist" in result.output |
| 426 | |
| 427 | result = runner.invoke(showtype, ["-f", "."]) |
| 428 | assert "is_file=False" in result.output |
| 429 | assert "is_dir=True" in result.output |
| 430 | |
| 431 | @click.command() |
| 432 | @click.option("-f", type=click.Path()) |
| 433 | def exists(f): |
| 434 | click.echo(f"exists={os.path.exists(f)}") |
| 435 | |
| 436 | with runner.isolated_filesystem(): |
| 437 | result = runner.invoke(exists, ["-f", "xxx"]) |
| 438 | assert "exists=False" in result.output |
| 439 | |
| 440 | result = runner.invoke(exists, ["-f", "."]) |
| 441 | assert "exists=True" in result.output |
| 442 | |
| 443 | |
| 444 | def test_choice_option(runner): |
nothing calls this directly
no test coverage detected
searching dependent graphs…