# Path: datafs/_compat.py
# def open_filelike(filelike, mode='r'):


import os
from datafs._compat import u
    # No good way to guard against this since the file has
    # already been opened for reading. A lock on new writes
    # would not solve the problem, since that would have an
    # identical result.

    with opener(archive1, 'r') as f1:
        with opener(archive2, 'w+') as f2:
            f2.write(u('test2'))

        assert u(f1.read()) == u('test1')

    with opener(archive1, 'r') as f1:
        assert u(f1.read()) == u('test2')

    # Turn off caching in archive 2, and do the same test.
    # We expect the same result because the cached file is
    # already open in archive 1

    archive2.remove_from_cache()

    assert archive1.api.cache.fs.isfile('myArchive')
    assert not archive2.api.cache.fs.isfile('myArchive')

    with opener(archive1, 'r') as f1:
        with opener(archive2, 'w+') as f2:
            f2.write(u('test3'))

        assert u(f1.read()) == u('test2')

    with opener(archive1, 'r') as f1:

# Path: datafs/_compat.py
# def open_filelike(filelike, mode='r'):


# Path: tests/test_caching.py
import os
from datafs._compat import u

    # No good way to guard against this since the file has
    # already been opened for reading. A lock on new writes
    # would not solve the problem, since that would have an
    # identical result.

    with opener(archive1, 'r') as f1:
        with opener(archive2, 'w+') as f2:
            f2.write(u('test2'))

        assert u(f1.read()) == u('test1')

    with opener(archive1, 'r') as f1:
        assert u(f1.read()) == u('test2')

    # Turn off caching in archive 2, and do the same test.
    # We expect the same result because the cached file is
    # already open in archive 1

    archive2.remove_from_cache()

    assert archive1.api.cache.fs.isfile('myArchive')
    assert not archive2.api.cache.fs.isfile('myArchive')

    with opener(archive1, 'r') as f1:
        with opener(archive2, 'w+') as f2:
            f2.write(u('test3'))

        assert u(f1.read()) == u('test2')

    with opener(archive1, 'r') as f1:

        assert u(f1.read()) == u('test3')