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
DM-33394: Refactor the tests #5
Conversation
Codecov Report
@@ Coverage Diff @@
## main #5 +/- ##
==========================================
+ Coverage 85.46% 89.70% +4.23%
==========================================
Files 15 21 +6
Lines 2071 2302 +231
Branches 297 329 +32
==========================================
+ Hits 1770 2065 +295
+ Misses 210 162 -48
+ Partials 91 75 -16
Continue to review full report at Codecov.
|
25b235c
to
888e42f
Compare
43bd258
to
1da25aa
Compare
Otherwise an internal error happens if the remote resource is missing.
Previously as_local would delete a local temporary file even if it did not itself create the temporary file.
1da25aa
to
4284562
Compare
Turns out that os.makedirs would already raise if a file was there so catch that and make it consistent.
Now that we correctly return temporary status in as_local for local files that were temporary, we need to have a more nuanced check for whether linking is allowed.
Now that the package is standalone it makes sense to have generic tests that can then be run for each URI scheme. We also want each scheme to be tested in a separate test file. The big test file has been removed. There are some complications from mypy.
4ee1fb9
to
86980b8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand this correctly, a lot of the changes are because the previous code assumed that if a ResourcePath
was temporary, it was therefore safe to delete, but did not anticipate the case where a local temporary ResourcePath
was itself passed to as_local
and thus generated another layer of indirection that should not be allowed to delete itself because it's not the owner of the temporary. Assuming I have that right, this all looks good. That might be worth a general docstring somewhere because it's fairly inobvious.
Also, if I'm reading this correctly, the generic test cases are currently used only by files and S3, but the goal is to also use them for the WebDAV test cases eventually? (BTW, I would rename http to webdav in at least the name of the tests, since http makes me think it's some sort of generic http-backed resource, but the operations you're doing are very specific to WebDAV, which is a much more obscure protocol that most http stores won't support.)
All the changes I did here were driven by test coverage uncovering problems. The fact that as_local could be given a temporary was one of those cases (previously as_local always returned that a local file was not temporary even if it was). Yes, the hope was that schemes that support read/write would all just inherit from the standard base class TestCase. That works for file and s3 because moto acts like a mocked S3 backend that can remember state. All the code switching is based entirely on URI scheme so calling it $ python -c 'from lsst.resources import ResourcePath; print(ResourcePath("https://raw.githubusercontent.com/lsst/daf_butler/main/python/lsst/daf/butler/configs/datastore.yaml").read().decode())'
/Users/timj/work/lsstsw3/miniconda/envs/lsst-scipipe-1.0.0/lib/python3.8/site-packages/urllib3/connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'raw.githubusercontent.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
warnings.warn(
datastore:
# Use file datastore as a default for a default butler
cls: lsst.daf.butler.datastores.fileDatastore.FileDatastore What other http-based URI standard would we use for uploading and moving files on a remote server? |
Co-authored-by: Russ Allbery <eagle@eyrie.org>
I agree with your analysis of the difficulty with testing WebDAV. For whatever it's worth, I don't have any one association with an HTTP-based file manipulation protocol but I'm not sure I would think of WebDAV. S3 would probably be my first thought for something that manipulated files via HTTP, and beyond that I'd probably assume some custom REST thing. I think they all support download via simple HTTP. That said, it's certainly not a blocking comment or anything, just something that made me pause a moment because I wasn't expecting HTTP to actually mean WebDAV. It's a good point that WebDAV is probably the only protocol that uses the |
It looks like webdav uses |
Checklist
doc/changes