Example #1
0
def test_open_file_ignore_no_encoding(runner):
    with runner.isolated_filesystem():
        with open("test.bin", "wb") as f:
            f.write(os.urandom(16))

        with click.open_file("test.bin", errors="ignore") as f:
            f.read()
Example #2
0
def test_open_file_ignore_invalid_utf8(runner):
    with runner.isolated_filesystem():
        with open("test.txt", "wb") as f:
            f.write(b"\xe2\x28\xa1")

        with click.open_file("test.txt", encoding="utf8", errors="ignore") as f:
            f.read()
Example #3
0
def test_open_file_respects_ignore(runner):
    with runner.isolated_filesystem():
        with open("test.txt", "w") as f:
            f.write("Hello world!")

        with click.open_file("test.txt", encoding="utf8", errors="ignore") as f:
            assert f.errors == "ignore"
Example #4
0
 def cli(filename):
     with click.open_file(filename) as f:
         click.echo(f.read())
     click.echo('meep')
Example #5
0
 def cli(filename):
     click.open_file(filename, "w", atomic=True).close()
Example #6
0
 def cli(filename):
     with click.open_file(filename, errors="ignore") as f:
         click.echo(f.read())