I am writing a unit test case for one of my python 2.7 methods.
In my test method, there is a method call that takes a dictionary with string key and panadas dataframe as the value for that key.
I want to write an interaction test for this method to check if it calls the method internally with correct dictionary
def MethodUnderTest(self):
#some code here
externalMethod(dictionary_of_string_dataframe)
#some code here
In the unit test, I do write my assert to test this interaction like this
mock_externalClass.externalMethod.assert_called_once_with(dictionary_of_string_dataframe)
I create dictionary_of_string_dataframe exactly the same way it is created in the actual method. In fact, I copied the helper method that does that in the test code just to make sure that both the dictionaries are the same. I even print both the dictionaries while debugging the test method on python console and both look exactly the same.
And I patch the external class using @patch decorator and all that works fine.
The problem is that in the above mentioned assert statement, i get the following error:
mock_externalClass.externalMethod.assert_called_once_with(dictionary_of_string_dataframe)
File "C:\Python27\lib\site-packages\mock\mock.py", line 948, in assert_called_once_with
return self.assert_called_with(*args, **kwargs)
File "C:\Python27\lib\site-packages\mock\mock.py", line 935, in assert_called_with
if expected != actual:
File "C:\Python27\lib\site-packages\mock\mock.py", line 2200, in __ne__
return not self.__eq__(other)
File "C:\Python27\lib\site-packages\mock\mock.py", line 2196, in __eq__
return (other_args, other_kwargs) == (self_args, self_kwargs)
File "C:\Python27\lib\site-packages\pandas\core\generic.py", line 953, in __nonzero__
.format(self.__class__.__name__))
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I did search on the valueError but not much of help. Can someone tell me what's going on here ?
I did check the following question but that didn't help