You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Every __operator__ method has a corresponding function which should have the same behavior, meaning the tests for those operators should be able to just reuse the test for the function. We should figure out a clean way to do this. Maybe it's just a question of parameterizing over the function so that something like test_add will parameterize over add(), x1.__add__ and x1.__radd__. There's also the complication of the in-place operators (x1.__iadd__), which work just like the operators except the input shape and dtypes are more restricted (the result shape and dtype must be the same as the lhs). This might just be a case of only testing op= when the inputs would be legal.
These are already split out in the type promotion tests (which are currently the only tests that test the operator methods). I don't know if those tests also need to be merged. If they can be merged simply they can be, but otherwise it is fine to keep them separate as they are now.
It's not necessary to test both the dunder method and the operator. Python will call the dunder method when the operator is used. The only slight hitch to that is the __r*__ methods are only called when the left operand returns NotImplemented, so we generally have to test them directly. As far as the actual pytest parameter ids, I think either way looks fine.
As-is this doesn't work out for inplace operators nicely. I'll experiment more and hopefully come up with something better. Maybe a custom pytest fixture or decorator which passes an out parameter (that could be x1 in inplace operations), so the test method body doesn't need to worry how it was evaluated. Inplace operations with scalars are something I'd also leave last heh.
Activity
honno commentedon Oct 13, 2021
asmeurer commentedon Oct 13, 2021
It's not necessary to test both the dunder method and the operator. Python will call the dunder method when the operator is used. The only slight hitch to that is the
__r*__methods are only called when the left operand returns NotImplemented, so we generally have to test them directly. As far as the actual pytest parameter ids, I think either way looks fine.honno commentedon Oct 14, 2021
Ah I misunderstood this issue, I see now.
honno commentedon Oct 28, 2021
Tackling this next. My first idea is to eval expression parameters e.g.
As-is this doesn't work out for inplace operators nicely. I'll experiment more and hopefully come up with something better. Maybe a custom pytest fixture or decorator which passes an
outparameter (that could bex1in inplace operations), so the test method body doesn't need to worry how it was evaluated. Inplace operations with scalars are something I'd also leave last heh.