-
Notifications
You must be signed in to change notification settings - Fork 290
For exists(), more precise error handling. #757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 8 commits
a93de68
ebb6535
8090d41
36dd838
bac41a1
908931e
1f957ad
c6a1860
2ac545b
54c3bee
49a9ac5
584c74f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
from s3fs.core import S3FileSystem | ||
from s3fs.utils import ignoring, SSEParams | ||
from botocore.exceptions import NoCredentialsError | ||
from botocore.exceptions import EndpointConnectionError | ||
from fsspec.asyn import sync | ||
from fsspec.callbacks import Callback | ||
from packaging import version | ||
|
@@ -2464,6 +2465,40 @@ def test_exists_isdir(s3): | |
assert not s3.isdir(bad_path) | ||
|
||
|
||
def test_exists_raises_on_connection_error(monkeypatch): | ||
# Ensure that we raise a ConnectionError instead of returning False if we | ||
# are not actually able to connect to storage, by setting a fake proxy and | ||
# then re-creating the S3FileSystem instance. | ||
monkeypatch.setenv("https_proxy", "https://fakeproxy.127.0.0.1:8080") | ||
S3FileSystem.clear_instance_cache() | ||
s3 = S3FileSystem( | ||
anon=False, | ||
client_kwargs={"endpoint_url": endpoint_uri}, | ||
skip_instance_cache=True, | ||
) | ||
s3.invalidate_cache() | ||
with pytest.raises(EndpointConnectionError): | ||
s3.exists("this-bucket-does-not-exist/") | ||
|
||
|
||
def test_exists_bucket_nonexistent_or_no_access(caplog): | ||
# Ensure that a warning is raised and False is returned if querying a | ||
# bucket that might either not exist or be private. | ||
# This tests against real AWS, might fail due to network issues. | ||
caplog.clear() | ||
fs = s3fs.S3FileSystem(key="wrongkey", secret="wrongsecret") | ||
assert not fs.exists("s3://this-bucket-might-not-exist/") | ||
assert caplog.records[0].levelname == "WARNING" | ||
assert "doesn't exist or you don't have access" in caplog.text | ||
|
||
|
||
def test_exists_bucket_nonexistent(s3, caplog): | ||
# Ensure that NO warning is raised and False is returned if checking bucket | ||
# existance when we have full access. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, the bucket might still exist, but it's not one we can see. We happen to know for the sake of the test that it doesn't exist. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure whether this is true for all S3 systems, but at least for our internal systems, I get a "PermissionError" when trying to access a bucket I cannot see (because I don't have permission to see it) but a |
||
assert not s3.exists("non_existent_bucket/") | ||
assert len(caplog.records) == 0 | ||
|
||
|
||
def test_list_del_multipart(s3): | ||
path = test_bucket_name + "/afile" | ||
f = s3.open(path, "wb") | ||
|
Uh oh!
There was an error while loading. Please reload this page.