# Path: fastavro/_write_common.py
# def _is_appendable(file_like):
#     if file_like.seekable() and file_like.tell() != 0:
#         if "<stdout>" == getattr(file_like, "name", ""):
#             # In OSX, sys.stdout is seekable and has a non-zero tell() but
#             # we wouldn't want to append to a stdout. In the python REPL,
#             # sys.stdout is named `<stdout>`
#             return False
#         if file_like.readable():
#             return True
#         else:
#             raise ValueError(
#                 "When appending to an avro file you must use the "
#                 + "'a+' mode, not just 'a'"
#             )
#     else:
#         return False


import sys
import pytest
from fastavro._write_common import _is_appendable


def test_appendable_raises_valuerror(tmpdir):
    """_is_appendable() raises ValueError when file is only 'a' mode."""
    test_file = str(tmpdir.join("test.avro"))

    with open(test_file, "a") as new_file:
        new_file.write("this phrase forwards cursor position beyond zero")
        with pytest.raises(ValueError, match=r"you must use the 'a\+' mode"):

# Path: fastavro/_write_common.py
# def _is_appendable(file_like):
#     if file_like.seekable() and file_like.tell() != 0:
#         if "<stdout>" == getattr(file_like, "name", ""):
#             # In OSX, sys.stdout is seekable and has a non-zero tell() but
#             # we wouldn't want to append to a stdout. In the python REPL,
#             # sys.stdout is named `<stdout>`
#             return False
#         if file_like.readable():
#             return True
#         else:
#             raise ValueError(
#                 "When appending to an avro file you must use the "
#                 + "'a+' mode, not just 'a'"
#             )
#     else:
#         return False


# Path: tests/test_appendable.py
import sys
import pytest
from fastavro._write_common import _is_appendable



def test_appendable_raises_valuerror(tmpdir):
    """_is_appendable() raises ValueError when file is only 'a' mode."""
    test_file = str(tmpdir.join("test.avro"))

    with open(test_file, "a") as new_file:
        new_file.write("this phrase forwards cursor position beyond zero")
        with pytest.raises(ValueError, match=r"you must use the 'a\+' mode"):

            _is_appendable(new_file)