def test_write_file_yaml(tmpdir): """Test write_file YAML file output.""" 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_json(tmpdir): """Test write_file JSON file output.""" path = tmpdir.mkdir('sub').join('outfile.json') pathname = abspath(path) file_io.write_file(pathname, VALUE) assert len(tmpdir.listdir()) == 1 assert path.read() == EXAMPLE_JSON tmpdir.remove()
def test_write_file_yaml_gz(tmpdir): """Test write_file gzipped YAML output.""" 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): """Test write_file text file output.""" 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(): """Test write_file to bad 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