Skip to content

Instantly share code, notes, and snippets.

@jgosmann
Created December 8, 2011 13:36
Show Gist options
  • Save jgosmann/1447004 to your computer and use it in GitHub Desktop.
Save jgosmann/1447004 to your computer and use it in GitHub Desktop.
Example of incompatibility between flexmock and numpy arrays
from flexmock import *
import numpy as np
import unittest
class FlexmockNumpyTest(unittest.TestCase):
def testFlexmockNumpy(self):
someArray = np.array([[0, 1], [2, 3]])
equalToSomeArray = someArray.copy()
mock = flexmock()
mock.should_receive("funcWithArrayArg").with_args(someArray)
mock.funcWithArrayArg(equalToSomeArray)
if __name__ == "__main__":
unittest.main()
E.
======================================================================
ERROR: testFlexmockNumpy (__main__.FlexmockNumpyTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "flexmock_numpy.py", line 13, in testFlexmockNumpy
mock.funcWithArrayArg(equalToSomeArray)
File "/Volumes/Home/blubb/bin/python/lib/python/flexmock.py", line 670, in mock_method
self, method, arguments)
File "/Volumes/Home/blubb/bin/python/lib/python/flexmock.py", line 104, in get_flexmock_expectation
if e.method == name and _match_args(args, e.args):
File "/Volumes/Home/blubb/bin/python/lib/python/flexmock.py", line 792, in _match_args
if (given_args == expected_args or expected_args is None):
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
----------------------------------------------------------------------
Ran 1 test in 0.046s
FAILED (errors=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment