async def test_normalize_storage_path_uri__4_slashes_relative(client: Client) -> None: url = URL("storage:////path/to/file.txt") url = normalize_storage_path_uri(url, client.username) assert url.scheme == "storage" assert url.host == "path" assert url.path == "/to/file.txt" assert str(url) == "storage://path/to/file.txt"
async def test_normalize_storage_path_uri__3_slashes__double(client: Client) -> None: url = URL("storage:///path/to/file.txt") url = normalize_storage_path_uri(url, client.username, "test-cluster") assert url.scheme == "storage" assert url.host == "test-cluster" assert url.path == "/path/to/file.txt" assert str(url) == "storage://test-cluster/path/to/file.txt"
async def test_normalize_storage_path_uri_no_path(client: Client) -> None: url = URL("storage:") url = normalize_storage_path_uri(url, client.username, "test-cluster") assert url.scheme == "storage" assert url.host == "test-cluster" assert url.path == "/user" assert str(url) == "storage://test-cluster/user"
async def test_normalize_storage_path_uri_no_slashes(client: Client) -> None: url = URL("storage:file.txt") url = normalize_storage_path_uri(url, client.username) assert url.scheme == "storage" assert url.host == "user" assert url.path == "/file.txt" assert str(url) == "storage://user/file.txt"
async def test_normalize_storage_path_uri__tilde_in_relative_path_3( client: Client, ) -> None: url = URL("storage:path/to~file.txt") url = normalize_storage_path_uri(url, client.username, "test-cluster") assert url.scheme == "storage" assert url.host == "test-cluster" assert url.path == "/user/path/to~file.txt" assert str(url) == "storage://test-cluster/user/path/to~file.txt"
async def test_normalize_storage_path_uri__tilde_in_absolute_path( client: Client ) -> None: url = URL("storage:/~/path/to/file.txt") url = normalize_storage_path_uri(url, client.username) assert url.scheme == "storage" assert url.host == "user" assert url.path == "/path/to/file.txt" assert str(url) == "storage://user/path/to/file.txt"
async def test_normalize_storage_path_uri__tilde_slash__double(client: Client) -> None: url = URL("storage:~/path/to/file.txt") with pytest.raises(ValueError, match=".*Cannot expand user.*"): normalize_storage_path_uri(url, client.username, "test-cluster")
async def test_normalize_storage_path_uri__bad_scheme(client: Client) -> None: with pytest.raises(ValueError, match="Invalid storage scheme 'other:'"): url = URL("other:path/to/file.txt") normalize_storage_path_uri(url, client.username, "test-cluster")
async def test_normalize_storage_path_uri__tilde_in_host(client: Client) -> None: url = URL("storage://~/path/to/file.txt") with pytest.raises(ValueError, match=r"Cannot expand user for "): normalize_storage_path_uri(url, client.username, "test-cluster")
async def test_normalize_storage_path_uri__tilde_in_relative_path( client: Client ) -> None: url = URL("storage:~/path/to/file.txt") with pytest.raises(ValueError, match=".*Cannot expand user.*"): normalize_storage_path_uri(url, client.username)
async def test_normalize_storage_path_uri__fail(uri_str: str) -> None: uri = URL(uri_str) with pytest.raises(ValueError): normalize_storage_path_uri(uri, "test-user", "test-cluster")