def test_write_file_yaml(tmpdir): path = tmpdir.mkdir('sub').join('outfile.yaml') pathname = abspath(path) file_io.write_file(pathname, VALUE) assert len(tmpdir.listdir()) == 1 assert path.read() == EXAMPLE_YAML tmpdir.remove()
def test_write_file_yaml_gz(tmpdir): path = tmpdir.mkdir('sub').join('outfile.yaml.gz') pathname = abspath(path) file_io.write_file(pathname, VALUE) assert len(tmpdir.listdir()) == 1 with open(pathname, 'rb') as fh: assert binascii.hexlify(fh.read(2)) == b'1f8b' tmpdir.remove()
def test_write_file_plain(tmpdir): path = tmpdir.mkdir('sub').join('outfile.txt') pathname = abspath(path) example_string = 'file content\n' file_io.write_file(pathname, example_string) assert len(tmpdir.listdir()) == 1 assert path.read() == example_string tmpdir.remove()
def test_write_file_invalid_path(): example_string = 'file content\n' assert file_io.write_file('path/does/not/exist', example_string) is False assert file_io.write_file('path/does/not/exist.gz', example_string) is False