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