test_s3.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from io import BytesIO
  2. import pytest
  3. from pandas import read_csv
  4. def test_streaming_s3_objects():
  5. # GH17135
  6. # botocore gained iteration support in 1.10.47, can now be used in read_*
  7. pytest.importorskip("botocore", minversion="1.10.47")
  8. from botocore.response import StreamingBody
  9. data = [b"foo,bar,baz\n1,2,3\n4,5,6\n", b"just,the,header\n"]
  10. for el in data:
  11. body = StreamingBody(BytesIO(el), content_length=len(el))
  12. read_csv(body)
  13. @pytest.mark.single_cpu
  14. def test_read_without_creds_from_pub_bucket(s3_public_bucket_with_data, s3so):
  15. # GH 34626
  16. pytest.importorskip("s3fs")
  17. result = read_csv(
  18. f"s3://{s3_public_bucket_with_data.name}/tips.csv",
  19. nrows=3,
  20. storage_options=s3so,
  21. )
  22. assert len(result) == 3
  23. @pytest.mark.single_cpu
  24. def test_read_with_creds_from_pub_bucket(s3_public_bucket_with_data, s3so):
  25. # Ensure we can read from a public bucket with credentials
  26. # GH 34626
  27. pytest.importorskip("s3fs")
  28. df = read_csv(
  29. f"s3://{s3_public_bucket_with_data.name}/tips.csv",
  30. nrows=5,
  31. header=None,
  32. storage_options=s3so,
  33. )
  34. assert len(df) == 5