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)
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)
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
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)
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
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)
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(), }
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
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
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
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)
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"}
def test_default_filesystem_dir(tmp_path): fs = DefaultFilesystem() assert fs.exists(tmp_path) assert fs.is_directory(tmp_path)