Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Method that does some work
- # The interesting data is a part of "param", but it's not directly accessible
- def do_work(param):
- # Navigating object graph to get to the array
- data_array = param.related_object.some_dict['data_array']
- # This array contains more data, we remove it
- relevant_array = [x for x in data_array if not useless(x)]
- # Only now we can start processing business logic
- result = [process(x) for x in relevant_array]
- return result
- # In tests
- def test():
- # Since the "param" is some complex structure,
- # that is probably used for something else,
- # we need to do a lot of effort to mock it
- # Produces more data, which is mostly "useless()", hence it's slower
- data_array = Factory.get_generic_data_array()
- fake_param = MagicMock()
- fake_param.related_object.some_dict['data_array'] = data_array
- # Only now we can finally execute it
- assert do_work(fake_param) == Factory.get_do_work_result()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement