I want to write a test case for a feature within complex data structures. The feature doesn't rely on all the data and getting real instances with the desired properties is hard. Hence, I am using Mocks.
def test_Case:
t1 = Timeseries(...) # Data
t2 = Timeseries(...) # Data
fancy_t1 = Mock(data=d1, additional_property= ...)
fancy_t2 = Mock(data=d2, additional_property= ...)
container = Mock(data_sets=[fancy_t1, fancy_t2])
ret = function_to_test(container)
assert ret ... # Some condition
Within function_to_test
there is a call of the form
container.aggregation.aggregate(fancy_t, more_arguments1, more_arguments2, ... )
What I want that the aggregation.aggregate
call to do is quite simple. It is supposed to evaluate to d1+d2
and ignore the fancy_t
and the other arguments.
How would I do that?
If I do something like this
agg = Mock()
agg.return_value = d1 + d2
container.aggregation.get_aggregated_positions = agg
It evalutes to something like <Mock name='mock.aggregation.get_aggregated_positions()' id='296569680'>
instead of a Timeseries
Aucun commentaire:
Enregistrer un commentaire