Пример #1
0
def test_default_filesystem_file(tmp_path):
    file: Path = tmp_path / "testfile"
    file.touch()

    fs = DefaultFilesystem()

    assert fs.exists(file)
    assert fs.is_file(file)
Пример #2
0
def test_get_valid_directories(tmp_path):
    fs = DefaultFilesystem()
    fs.touch(tmp_path / "test_file")

    values = {str(tmp_path / "test_file" / "..")}

    result = get_valid_directories(fs, values)

    assert str(result.pop()) == str(tmp_path)
Пример #3
0
def test_parse_path(tmp_path):
    fs = DefaultFilesystem()
    fs.touch(tmp_path / "test_file")

    value = str(tmp_path / "test_file" / "..")

    result = parse_path(fs, value)

    assert result == tmp_path
Пример #4
0
def test_validate_files(tmp_path):
    fs = DefaultFilesystem()

    path = tmp_path / "test_directory"
    fs.create_dir(path)
    paths = {path}

    with pytest.raises(Exception) as e:
        validate_files(fs, paths)

    assert "is not a file" in str(e.value)
Пример #5
0
def test_default_filesystem_children(tmp_path):
    expected_children = set()
    for name in range(10):
        file = tmp_path / str(name)
        file.touch()
        expected_children.add(file)
    fs = DefaultFilesystem()

    children = fs.children(tmp_path)

    assert set(children) == expected_children
Пример #6
0
def test_validate_exists(tmp_path):
    fs = DefaultFilesystem()

    path = tmp_path / "test_file"

    with pytest.raises(Exception) as e:
        validate_exists(fs, path)

    assert "path does not exist" in str(e.value)
Пример #7
0
def get_dependencies(args: Mapping) -> Mapping[str, Any]:
    clutch_client = clutch_factory(args)
    fs = DefaultFilesystem()
    return {
        "client": ClutchApi(clutch_client),
        "fs": fs,
        "locator": SingleDirectoryFileLocator(fs),
        "metainfo_reader": DefaultMetainfoIO(),
    }
Пример #8
0
async def test_default_filesystem_find_directory(tmp_path):
    file = tmp_path / "test_dir"
    file.mkdir(parents=True)
    fs = DefaultFilesystem()
    locator: FileLocator = SingleDirectoryFileLocator(fs, tmp_path)

    result = await locator.locate_directory("test_dir")

    assert result == tmp_path
Пример #9
0
async def test_default_locator_find_file(tmp_path):
    file = tmp_path / "test_file"
    file.touch()
    fs = DefaultFilesystem()
    locator: FileLocator = SingleDirectoryFileLocator(fs, tmp_path)

    result = await locator.locate_file("test_file")

    assert result == tmp_path
Пример #10
0
def test_metainfo_multifile_load(datadir):
    metainfo_reader: MetainfoIO = DefaultMetainfoIO()
    metainfo_path = datadir / "being_earnest.torrent"
    metainfo_file = metainfo_reader.from_path(metainfo_path)

    fs = DefaultFilesystem()
    data_reader = DefaultTorrentDataReader(fs)
    result = data_reader.verify(datadir, metainfo_file)

    assert result
Пример #11
0
async def test_async_data_locator_multi_file(datadir):
    reader: MetainfoIO = DefaultMetainfoIO()
    path = datadir / "being_earnest.torrent"
    file = reader.from_path(path)

    fs = DefaultFilesystem()
    locator = DefaultTorrentDataLocator(fs, datadir)
    result = await locator.find(file)

    assert result == TorrentData(file, datadir)
Пример #12
0
def test_get_valid_paths(tmp_path):
    fs = DefaultFilesystem()
    fs.create_dir(tmp_path / "test_dir")
    fs.touch(tmp_path / "test_file")

    values = {
        str(tmp_path / "test_dir" / ".." / "test_file"),
        str(tmp_path / "test_dir" / ".." / "test_dir"),
    }

    result = get_valid_paths(fs, values)

    assert result == {tmp_path / "test_dir", tmp_path / "test_file"}
Пример #13
0
def test_default_filesystem_dir(tmp_path):
    fs = DefaultFilesystem()

    assert fs.exists(tmp_path)
    assert fs.is_directory(tmp_path)