def test_exists(filesystem: FileSystemImpl,
                lpaths: Dict[str, AbstractPath]) -> None:
    assert filesystem._exists(lpaths['root'])
    assert filesystem._exists(lpaths['dir'])
    assert filesystem._exists(lpaths['file'])
    assert filesystem._exists(lpaths['link'])
    assert not filesystem._exists(lpaths['broken_link'])
    assert not filesystem._exists(lpaths['link_loop'])
def test_rename(filesystem: FileSystemImpl,
                lpaths: Dict[str, AbstractPath]) -> None:
    assert not filesystem._exists(lpaths['new_file'])
    assert filesystem._exists(lpaths['file'])
    filesystem._rename(lpaths['file'], lpaths['new_file'])
    assert filesystem._exists(lpaths['new_file'])
    assert not filesystem._exists(lpaths['file'])
    filesystem._rename(lpaths['new_file'], lpaths['file'])
def test_symlink_to(filesystem: FileSystemImpl,
                    lpaths: Dict[str, AbstractPath]) -> None:
    if filesystem._supports('symlinks'):
        filesystem._symlink_to(lpaths['new_file'], lpaths['file'])
        assert filesystem._is_symlink(lpaths['new_file'])
        assert filesystem._is_file(lpaths['new_file'])
        filesystem._unlink(lpaths['new_file'])
        assert not filesystem._exists(lpaths['new_file'])
        assert filesystem._exists(lpaths['file'])
def test_touch(filesystem: FileSystemImpl, lpaths: Dict[str,
                                                        AbstractPath]) -> None:
    path = lpaths['new_file']
    filesystem._touch(path)
    assert filesystem._exists(path)
    # clean up, since we're reusing the file system
    filesystem._unlink(path)
def test_rmdir(filesystem: FileSystemImpl, lpaths: Dict[str,
                                                        AbstractPath]) -> None:
    filesystem._mkdir(lpaths['new_dir'])
    filesystem._rmdir(lpaths['new_dir'])
    assert not filesystem._exists(lpaths['new_dir'])

    with pytest.raises(OSError):
        filesystem._rmdir(lpaths['root'])

    filesystem._mkdir(lpaths['new_dir'])
    filesystem._touch(lpaths['new_dir'] / 'file.txt')
    filesystem._rmdir(lpaths['new_dir'], recursive=True)
    assert not filesystem._exists(lpaths['new_dir'])

    with pytest.raises(RuntimeError):
        filesystem._rmdir(lpaths['file'])
def test_unlink(filesystem: FileSystemImpl,
                lpaths: Dict[str, AbstractPath]) -> None:
    filesystem._touch(lpaths['new_file'])
    assert filesystem._exists(lpaths['new_file'])
    filesystem._unlink(lpaths['new_file'])
    assert not filesystem._exists(lpaths['new_file'])