has207/flexmock — Issue #63: Incompatibility with numpy arrays
Author: jgosmann
Created: 2011-12-07 20:41:12+00:00
State: open

Hi,

I've started recently using flexmock and I really like it until now. However, I came across one issue when using numpy arrays. If a function is called with a numpy array as argument the check whether it matches the expected argument always fails. The reason is that the equality operator for arrays does not return a single truth value, but a new array of truth values which cannot be used directly in an if-condition (one has to use the numpy.all or numpy.any function to do so).

Now, I don't think that it is flexmock's task to deal with this inconvenient numpy behavior. Nevertheless, I have a feature proposal which would make it possible to deal with this problem:

Instead of always matching the function arguments exactly it would be nice to be able to pass a (PyHamcrest) matcher to the `with_args` function. That would allow to match arguments depending on different criteria and not just equality. Also, it would be possible to write a matcher handling numpy arrays correctly.

As far as I know, jMock for Java is an example of a mock library where it is already possible to use Hamcrest matcher to match the function arguments (maybe this can be used as reference as needed).

What do you think about this proposal?

I think, I would be able to implement it myself. But it would be nice to know if you would include it in the main branch and it may take some months until I finally have time to do so.

- Jan