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

Refactor core tests, round 2 #1462

Merged
merged 7 commits into from
Jul 14, 2023

Conversation

d-v-b
Copy link
Contributor

@d-v-b d-v-b commented Jul 14, 2023

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:

  • [] Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • [] New/modified features documented in docs/tutorial.rst
  • Changes documented in docs/release.rst
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

@github-actions github-actions bot added the needs release notes Automatically applied to PRs which haven't added release notes label Jul 14, 2023
@d-v-b d-v-b mentioned this pull request Jul 14, 2023
6 tasks
@codecov
Copy link

codecov bot commented Jul 14, 2023

Codecov Report

Merging #1462 (9d5b41f) into main (aa5db9f) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##              main     #1462    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           37        37            
  Lines        15026     14723   -303     
==========================================
- Hits         15026     14723   -303     
Impacted Files Coverage Δ
zarr/storage.py 100.00% <ø> (ø)
zarr/tests/test_core.py 100.00% <100.00%> (ø)
zarr/util.py 100.00% <100.00%> (ø)

@github-actions github-actions bot removed the needs release notes Automatically applied to PRs which haven't added release notes label Jul 14, 2023
@d-v-b
Copy link
Contributor Author

d-v-b commented Jul 14, 2023

@rabernat this is ready for eyes

Copy link
Contributor

@rabernat rabernat left a 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)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

# keyword arguments for array initialization
init_array_kwargs = {
"path": kwargs.pop("path", self.path),
"compressor": self.compressor,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not

Suggested change
"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()
Copy link
Contributor

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?

Copy link
Contributor Author

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

Comment on lines +2038 to +2039
path = mktemp(suffix=".anydbm")
atexit.register(atexit_rmglob, path + "*")
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

dtype = kwargs.get('dtype')
compressor = Zlib(1)

def create_array(self, shape: Union[int, Tuple[int, ...]], **kwargs):
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 9d5b41f

@d-v-b
Copy link
Contributor Author

d-v-b commented Jul 14, 2023

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 ?

@rabernat rabernat merged commit 1558041 into zarr-developers:main Jul 14, 2023
19 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