Example #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)
Example #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)
Example #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
Example #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)
Example #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
Example #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)
Example #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(),
    }
Example #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
Example #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
Example #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
Example #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)
Example #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"}
Example #13
0
def test_default_filesystem_dir(tmp_path):
    fs = DefaultFilesystem()

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