Exemplo n.º 1
0
def test_entry_types(filesystem: FileSystemImpl,
                     lpaths: Dict[str, AbstractPath]) -> None:
    assert filesystem._is_dir(lpaths['root'])
    assert not filesystem._is_dir(lpaths['file'])
    assert not filesystem._is_dir(lpaths['new_dir'])

    assert filesystem._is_file(lpaths['file'])
    assert not filesystem._is_file(lpaths['root'])
    assert not filesystem._is_file(lpaths['new_file'])

    assert (filesystem._is_symlink(lpaths['link'])
            or not filesystem._supports('symlinks'))
    assert filesystem._is_file(lpaths['link'])
    assert not filesystem._is_dir(lpaths['link'])
    assert not filesystem._is_symlink(lpaths['new_file'])

    assert (filesystem._is_symlink(lpaths['broken_link'])
            or not filesystem._supports('symlinks'))
    assert not filesystem._is_file(lpaths['broken_link'])

    assert filesystem._entry_type(lpaths['root']) == EntryType.DIRECTORY
    assert filesystem._entry_type(lpaths['file']) == EntryType.FILE
    if filesystem._supports('symlinks'):
        assert filesystem._entry_type(
            lpaths['link']) == EntryType.SYMBOLIC_LINK
        # disable for now, doesn't work in a docker
        #assert filesystem._entry_type(lpaths['chardev']) == EntryType.CHARACTER_DEVICE
        assert filesystem._entry_type(
            lpaths['blockdev']) == EntryType.BLOCK_DEVICE
        assert filesystem._entry_type(lpaths['fifo']) == EntryType.FIFO
        # TODO: socket?

    with pytest.raises(FileNotFoundError):
        filesystem._entry_type(lpaths['new_file'])
Exemplo n.º 2
0
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'])