Skip to content
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

Mock s3fs testing framework #26

Merged
merged 13 commits into from
Jan 15, 2025
Merged

Mock s3fs testing framework #26

merged 13 commits into from
Jan 15, 2025

Conversation

valeriupredoi
Copy link
Collaborator

Sister PR to NCAS-CMS/PyActiveStorage#232

We mock an entire S3 fsspec/s3fs-like File System, pop a working HTTP client on top of it, and add a real POSIX file to it, then access it as if it was a real file but in an S3 s3fs-like FS. Wild Weasel YGBSM stuff 😁

@valeriupredoi valeriupredoi added the enhancement New feature or request label Jan 9, 2025
os.environ["AWS_SECRET_ACCESS_KEY"] = "foo"
if "AWS_ACCESS_KEY_ID" not in os.environ:
os.environ["AWS_ACCESS_KEY_ID"] = "foo"
os.environ.pop("AWS_PROFILE", None)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's going on with the credentials here? Is the objective to create credentials which only have scope within the tests? If so, I think it would be worth being explicit in comments, both here where the credentials are created, and where the (test scoped) credentials are being used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hang on, good call, let me add some inline comments here

client.create_bucket(Bucket=versioned_bucket_name, ACL="public-read")
client.put_bucket_versioning(
Bucket=versioned_bucket_name, VersioningConfiguration={"Status": "Enabled"}
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Public Read mean the credentials created earlier are ignored?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public is NOT anon, this is like your bucket on CEDA/ACES

@bnlawrence
Copy link
Collaborator

bnlawrence commented Jan 11, 2025

Could you please add another test (in another file) which actually uses this fixture, that we can then clone/copy/extract bits of, for the real tests?

endpoint_uri = "http://127.0.0.1:%s/" % port


def test_s3fs_s3(s3fs_s3):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bnlawrence here is a very little test that sets up the mock S3 FS via its fixture in conftest - the object mock_s3_filesystem is a true S3 FS with all its attributes and methods, and you can use it to do puts and gets and what nots. It's just virtual, not a real thing 😁

s3 = s3fs.S3FileSystem(anon=False, client_kwargs={"endpoint_url": endpoint_uri})
s3.invalidate_cache()

yield s3
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conftest now added, gents @bnlawrence and @davidhassell - these fixtures are now available out the box for testing right away

Copy link
Collaborator

@bnlawrence bnlawrence left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@bnlawrence bnlawrence merged commit 03183b7 into h5netcdf Jan 15, 2025
3 checks passed
@bnlawrence bnlawrence deleted the mock_s3fs branch January 15, 2025 08:37
@bnlawrence
Copy link
Collaborator

I have had the following when I used the merge branch:

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
aiobotocore 2.16.1 requires botocore<1.35.89,>=1.35.74, but you have botocore 1.35.99 which is incompatible.ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
aiobotocore 2.16.1 requires botocore<1.35.89,>=1.35.74, but you have botocore 1.35.99 which is incompatible.

which is likely to bite us on the bum in pyactivestorage?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants