-
-
Notifications
You must be signed in to change notification settings - Fork 308
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
Refactor core tests, round 2 #1462
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1462 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 37 37
Lines 15026 14723 -303
==========================================
- Hits 15026 14723 -303
|
@rabernat this is ready for eyes |
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.
This is fantastic work @d-v-b! 🙌
Overall, what I love is that you have eliminated a ton of boilerplate code. I have a few comments mostly in the vein of "could we go even farther"?
Another open question I have is whether to bring in pytest conveniences like parametrization and temporary directories.
Happy to leave both thoseitems for future work if you prefer. Or we could keep pushing forward here.
version = 2 | ||
root = '' | ||
KVStoreClass = KVStore | ||
path = '' | ||
compressor = Zlib(level=1) |
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.
Curious about why we are setting a default compressor here, and / or why it is different from the built-in default.
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.
I did that to make the test pass :) My observation is that historically, different test classes used different compressors (I have no idea why), and because of the hexdigest tests, these compressors get immured with the rest of the tests in that test class. I think this alone argues for rethinking the hexdigest tests.
zarr/tests/test_core.py
Outdated
# keyword arguments for array initialization | ||
init_array_kwargs = { | ||
"path": kwargs.pop("path", self.path), | ||
"compressor": self.compressor, |
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.
Why not
"compressor": self.compressor, | |
"compressor": kwargs.pop("compressor", self.compressor), |
?
Just trying to understand how this class is intended to be used by developers...
store.close() | ||
|
||
# initialize at path | ||
store = self.KVStoreClass(dict()) | ||
store = self.create_store() |
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.
Kind of feels like we should be in a separate test here. Is anything reused below from above?
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.
no, nothing is reused, so it's a great opportunity for just making a separate test
path = mktemp(suffix=".anydbm") | ||
atexit.register(atexit_rmglob, path + "*") |
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.
It would really be best to replace all of this stuff with pytest tempdir fixtures.
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.
yeah, I had the same feeling. I wanted to keep the initial PR close to the original tests, but I'm experimenting with a fixture-style locally.
init_array(store, **kwargs) | ||
return Array(store, read_only=read_only, cache_metadata=cache_metadata, | ||
cache_attrs=cache_attrs, write_empty_chunks=write_empty_chunks) | ||
compressor = Blosc(cname="zstd", clevel=1, shuffle=1) |
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.
Feels like we should be using parametrized fixtures here rather than making a class for each compressor.
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.
Absolutely. Locally, I'm experimenting with ripping out al the OOP stuff and just having parameterized functions. We'll see how that compares.
zarr/tests/test_core.py
Outdated
dtype = kwargs.get('dtype') | ||
compressor = Zlib(1) | ||
|
||
def create_array(self, shape: Union[int, Tuple[int, ...]], **kwargs): |
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.
Rather than re-implementing this whole method in the subclass, could you add filters
to the base TestArray
class attributes?
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.
done in 9d5b41f
… kwarg in create_array.
I'm making progress even more refactoring of the tests, but it's getting a bit more involved -- I'm entering territory where I'm merging / splitting / parametrizing individual tests, and I'm less sure that coverage will be preserved. This messier refactoring could take a while, so I think I recommend we settle for the current state of this PR for now. I can follow up with deeper refactors later on. How does this sound @rabernat ? |
It's the same thing as #1305, but without ruff + black linting applied to the whole codebase, and thus a much cleaner diff.
Some type hints were improved outside the core tests to ensure that mypy was happy.
TODO: