async def test_normalize_local_path_uri__tilde_in_host(client: Client, pwd: Path) -> None: url = URL("file://~/path/to/file.txt") with pytest.raises( ValueError, match=f"Host part is not allowed in file URI, found '~'"): url = normalize_local_path_uri(url)
async def test_normalize_local_path_uri__tilde_in_relative_path_2(pwd: Path,) -> None: url = URL("file:./~/path/to/file.txt") url = normalize_local_path_uri(url) assert url.scheme == "file" assert url.host is None assert _extract_path(url) == pwd / "~/path/to/file.txt" assert str(url) == (pwd / "~/path/to/file.txt").as_uri().replace("%7E", "~")
async def test_normalize_local_path_uri__4_slashes_relative() -> None: url = URL("file:////path/to/file.txt") url = normalize_local_path_uri(url) assert url.scheme == "file" assert url.host is None assert url.path == "/path/to/file.txt" assert str(url) == f"file:///path/to/file.txt"
async def test_normalize_local_path_uri__tilde_in_absolute_path( fake_homedir: Path, pwd: Path ) -> None: url = URL("file:/~/path/to/file.txt") url = normalize_local_path_uri(url) assert url.scheme == "file" assert url.host is None assert _extract_path(url) == pwd / "/~/path/to/file.txt" assert str(url) == (pwd / "/~/path/to/file.txt").as_uri().replace("%7E", "~")
async def test_normalize_local_path_uri__tilde_slash__double( fake_homedir: Path ) -> None: url = URL("file:~/path/to/file.txt") url = normalize_local_path_uri(url) assert url.scheme == "file" assert url.host is None assert _extract_path(url) == fake_homedir / "path/to/file.txt" assert str(url) == (fake_homedir / "path/to/file.txt").as_uri()
async def test_normalize_local_path_uri__no_slash__double(pwd: Path) -> None: url = URL("file:path/to/file.txt") url = normalize_local_path_uri(url) assert url.scheme == "file" assert url.host is None assert _extract_path(url) == pwd / "path/to/file.txt"
async def test_normalize_local_path_uri__bad_scheme() -> None: with pytest.raises(ValueError, match="Invalid local file scheme 'other:'"): url = URL("other:path/to/file.txt") normalize_local_path_uri(url)
async def test_normalize_local_path_uri__tilde_in_relative_path( fake_homedir: Path, ) -> None: url = URL("file:~/path/to/file.txt") with pytest.raises(ValueError, match=r"Cannot expand user for "): normalize_local_path_uri(url)
async def test_normalize_local_path_uri__3_slashes_relative(pwd: Path) -> None: url = URL("file:///path/to/file.txt") url = normalize_local_path_uri(url) assert url.scheme == "file" assert url.host is None assert _extract_path(url) == Path(pwd.drive + "/path/to/file.txt")
async def test_normalize_local_path_uri__2_slashes(pwd: Path) -> None: url = URL("file://path/to/file.txt") with pytest.raises(ValueError, match="Host part is not allowed, found 'path'"): url = normalize_local_path_uri(url)
async def test_normalize_local_path_uri_no_path(pwd: Path) -> None: url = URL("file:") url = normalize_local_path_uri(url) assert url.scheme == "file" assert url.host is None assert _extract_path(url) == pwd
async def test_normalize_local_path_uri__fail(uri_str: str) -> None: uri = URL(uri_str) with pytest.raises(ValueError): normalize_local_path_uri(uri)