-
Notifications
You must be signed in to change notification settings - Fork 45
Implement test_*_like
tests
#18
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
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
e0548af
Pin Hypothesis to >=6.21.0
honno 6066c5a
Rudimentary test_full_like()
honno db3370e
Paired nd arrays for test_equal()
honno f8d784d
Rudimentary empty/ones/zeros-like tests
honno a6e72cf
Make numeric_arrays multi-dimensional
honno 6be73aa
Make new tests more in-line with established style
honno 6622a81
Remove redundant st.shared import
honno a3470e1
promotable_dtypes() strategy
honno 955cabf
Cleaned up hypothesis helper tests
honno e14c09d
Internally flatmap promotable_dtypes
honno eba6e61
Redefine custom shapes strategy using xps.array_shapes
honno ae4171f
Defined shared_optional_promotable_dtype
honno 78817ef
Remove redundant imports
honno b7089e4
Test promotable dtype and broadcastable shape in test_equal
honno e25c257
Fixed test_full_like generation to match spec
honno f7f8bde
Fixed test_*_like methods to match spec
honno 68fadcd
Refactored strategy used in test_equal
honno f2435c9
Remove promotable_dtypes and use the original mutual method
honno ab6b684
Correct fill_value values for test_full_like() + relevant assertions
honno 2a65bfa
For NumPy, xfail test_full_like
honno 4c2e32c
Rename "mutually_promotable_dtype_pairs" back to its original name
honno 8c26f50
Update Hypothesis pin
honno 312db69
Prematurely update test_full_like for proposed spec change
honno 70099e5
Assert `x_like.dtype == x.dtype` when dtype kwarg is `None`
honno 8b11476
Implement `kwargs` strategy, and use it in some creation tests
honno 3f6e330
Fixed `test_full_like`
honno 0fb851f
Removed redundant optional_dtypes strategy
honno 4aa49d4
Assert inferred dtype correctly in `test_full`
honno afc7822
Use `math.isnan` for checking `fill_value`
honno 10cb57a
Fix assertion statements
honno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from math import prod | ||
|
||
import pytest | ||
from hypothesis import given, strategies as st | ||
|
||
from .. import _array_module as xp | ||
from .._array_module import _UndefinedStub | ||
from .. import array_helpers as ah | ||
from .. import hypothesis_helpers as hh | ||
|
||
UNDEFINED_DTYPES = any(isinstance(d, _UndefinedStub) for d in ah.dtype_objects) | ||
pytestmark = [pytest.mark.skipif(UNDEFINED_DTYPES, reason="undefined dtypes")] | ||
|
||
|
||
@given(hh.mutually_promotable_dtypes([xp.float32, xp.float64])) | ||
def test_mutually_promotable_dtypes(pairs): | ||
assert pairs in ( | ||
(xp.float32, xp.float32), | ||
(xp.float32, xp.float64), | ||
(xp.float64, xp.float32), | ||
(xp.float64, xp.float64), | ||
) | ||
|
||
|
||
def valid_shape(shape) -> bool: | ||
return ( | ||
all(isinstance(side, int) for side in shape) | ||
and all(side >= 0 for side in shape) | ||
and prod(shape) < hh.MAX_ARRAY_SIZE | ||
) | ||
|
||
|
||
@given(hh.shapes) | ||
def test_shapes(shape): | ||
assert valid_shape(shape) | ||
|
||
|
||
@given(hh.two_mutually_broadcastable_shapes) | ||
def test_two_mutually_broadcastable_shapes(pair): | ||
for shape in pair: | ||
assert valid_shape(shape) | ||
|
||
|
||
@given(hh.two_broadcastable_shapes()) | ||
def test_two_broadcastable_shapes(pair): | ||
for shape in pair: | ||
assert valid_shape(shape) | ||
|
||
from ..test_broadcasting import broadcast_shapes | ||
|
||
assert broadcast_shapes(pair[0], pair[1]) == pair[0] | ||
|
||
|
||
def test_kwargs(): | ||
results = [] | ||
|
||
@given(hh.kwargs(n=st.integers(0, 10), c=st.from_regex("[a-f]"))) | ||
def run(kw): | ||
results.append(kw) | ||
|
||
run() | ||
assert all(isinstance(kw, dict) for kw in results) | ||
for size in [0, 1, 2]: | ||
assert any(len(kw) == size for kw in results) | ||
|
||
n_results = [kw for kw in results if "n" in kw] | ||
assert len(n_results) > 0 | ||
assert all(isinstance(kw["n"], int) for kw in n_results) | ||
|
||
c_results = [kw for kw in results if "c" in kw] | ||
assert len(c_results) > 0 | ||
assert all(isinstance(kw["c"], str) for kw in c_results) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just a note here: we're going to want to split this across the different dtype categories. I guess this strategy is currently used in the special cases tests which are generated automatically, so we would have to also update the generate_stubs script to parse said categories from the spec. I think at present every function that has special cases accepts floating-point inputs which is why this works. This might end up being complicated, so it's something I'll take a look at myself at some point. We are also going to need to consider how things will work with complex dtypes once those start being added later this year.