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 CAVEclient for testing #259

Merged
merged 17 commits into from
Oct 31, 2024
Merged

Mock CAVEclient for testing #259

merged 17 commits into from
Oct 31, 2024

Conversation

ceesem
Copy link
Collaborator

@ceesem ceesem commented Oct 25, 2024

Adding a small submodule caveclient.tools.testing that makes it much easier to mock CAVEclients for testing.

  1. CAVEclientMock lets you specify which services you anticipate loading, can take a datastack or use a only global-only version, can select what versions of each service you want to test against, specify api version availability, set materialization versions, etc. In general, CAVEclient initialization options are mocked out.

  2. CAVEclient conftest.py was altered to use this tooling and several small tests were added to use these features.

  3. This caught one or two bugs/issues thanks to these new tests.

@ceesem
Copy link
Collaborator Author

ceesem commented Oct 25, 2024

Note on the bugs and issues:

  • Global-only CAVEClient initialization was ignoring server_version because it was trying to use the datastack-to-server map when a datastack was not provided. This check was moved to happen only if the condition that a datastack is specified.
  • l2cache.has_cache() was always checking the pcg tables anew, rather than doing it once on initialization. Not a huge deal, but it adds latency and also made mocking a pain since it would send a new request through the pcg client with every l2 cache request. Now the pcg-to-l2cache table mapping is saved once retrieved the first time.
  • There was no way to tell caveclient to not try to save a synchronized save file for the local server. I realized that this is actually a hazard, because it will save your token to a file automatically and silently without user permission. I changed this to require an explicit call to a new function client.auth.write_local_server_token().

@ceesem
Copy link
Collaborator Author

ceesem commented Oct 25, 2024

On reflection, I dont' like the implementation in the third bullet point. Will move that feature to part of the existing save_token function

@ceesem
Copy link
Collaborator Author

ceesem commented Oct 25, 2024

Added a parameter local_server to the save_token function which will also save the token to a datastack local server specific file, if a local server is set. Defaults to true, which will effectively save two files with a token for the price of one, making it much more convenient to e.g. use cloudvolume by default to get access to segmentation.

@ceesem ceesem mentioned this pull request Oct 30, 2024
@fcollman fcollman merged commit 56b3215 into master Oct 31, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants