[lang-ref] ( file_io_with_gzip ) ( python )

def test_file_io_with_gzip(tmp_path):
    # f.read(), f.write()
    lines = ['test message %03d\n' % x for x in range(5)]
    text  = ''.join(lines)
    p = tmp_path / 'a.txt.gz'

    import gzip

    with gzip.open(p, 'wt', encoding='utf-8') as f:
        f.write(text)

    with gzip.open(p, 'rt') as f:
        r = f.read()

    assert r == text