I have a list of filters and each filter changes the input list. How do I create a mock for each filter that will change the input list?
class TwoFilter(object):
def filter(self, arr):
arr[:] = [i for i in arr if i % 2 != 0]
class ThreeFilter(object):
def filter(self, arr):
arr[:] = [i for i in arr if i % 3 != 0]
class FourFilter(object):
def filter(self, arr):
arr[:] = [i for i in arr if i % 3 != 0]
class MyFilters(object):
def __init__(self):
self.filters = [TwoFilter(), ThreeFilter(), FourFilter()]
def apply_filters(self, arr):
for f in self.filters:
f.filter(arr)
I want to unit test apply_filters
by mocking the filters in self.filters
for input [1,2,3,4]. Is there a way to have each mock change the input arr
and verify if each subsequent filter was called with this modified arr
?
P.S: I am able to get around this problem by having the filters return the arr
and use mock.return_value
to change the mock's output.