Path: blob/main/py-polars/tests/unit/io/cloud/test_cloud.py
6939 views
from __future__ import annotations12import contextlib3from functools import partial45import pytest67import polars as pl8910@pytest.mark.slow11@pytest.mark.parametrize("format", ["parquet", "csv", "ndjson", "ipc"])12def test_scan_nonexistent_cloud_path_17444(format: str) -> None:13# https://github.com/pola-rs/polars/issues/174441415path_str = f"s3://my-nonexistent-bucket/data.{format}"16scan_function = getattr(pl, f"scan_{format}")17# Prevent automatic credential provideder instantiation, otherwise CI may fail with18# * pytest.PytestUnraisableExceptionWarning:19# * Exception ignored:20# * ResourceWarning: unclosed socket21scan_function = partial(scan_function, credential_provider=None)2223# Just calling the scan function should not raise any errors24if format == "ndjson":25# NDJSON does not have a `retries` parameter yet - so use the default26result = scan_function(path_str)27else:28result = scan_function(path_str, retries=0)29assert isinstance(result, pl.LazyFrame)3031# Upon collection, it should fail32with pytest.raises(IOError):33result.collect()343536def test_scan_err_rebuild_store_19933() -> None:37call_count = 03839def f() -> None:40nonlocal call_count41call_count += 142raise AssertionError4344q = pl.scan_parquet(45"s3://.../...",46storage_options={"aws_region": "eu-west-1"},47credential_provider=f, # type: ignore[arg-type]48)4950with contextlib.suppress(Exception):51q.collect()5253# Note: We get called 2 times per attempt54if call_count != 4:55raise AssertionError(call_count)565758