Skip to content Skip to sidebar Skip to footer

Mocking Numpy Structured Arrays

I'm trying to figure out how to mock a numpy structured array and am not having much luck. Ideally, I'd like to do something like this: from mock import MagicMock mock_obj = Magic

Solution 1:

I believe that I found the solution. It seems a bit lame, but it's the closet I've been able to get:

from mock importMagicMockmock_obj= MagicMock()
mock_obj.__getitem__().__getitem__().__getitem__.return_value = 3assert3 ==  mock_obj['some']['test']['structure']

The only problem I really see with is that it doesn't work for multiple levels. i.e. mock_obj['some']['test'] returns a mock object and not 3.

Post a Comment for "Mocking Numpy Structured Arrays"