MCPcopy
hub / github.com/pallets/click / test_open_file

Function test_open_file

tests/test_utils.py:659–678  ·  view source on GitHub ↗
(runner)

Source from the content-addressed store, hash-verified

657
658
659def test_open_file(runner):
660 @click.command()
661 @click.argument("filename")
662 def cli(filename):
663 with click.open_file(filename) as f:
664 click.echo(f.read())
665
666 click.echo("meep")
667
668 with runner.isolated_filesystem():
669 with open("hello.txt", "w") as f:
670 f.write("Cool stuff")
671
672 result = runner.invoke(cli, ["hello.txt"])
673 assert result.exception is None
674 assert result.output == "Cool stuff\nmeep\n"
675
676 result = runner.invoke(cli, ["-"], input="foobar")
677 assert result.exception is None
678 assert result.output == "foobar\nmeep\n"
679
680
681def test_open_file_pathlib_dash(runner):

Callers

nothing calls this directly

Calls 4

openFunction · 0.85
isolated_filesystemMethod · 0.80
writeMethod · 0.45
invokeMethod · 0.45

Tested by

no test coverage detected