daily pastebin goal
59%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Method that does some work
  2. # The interesting data is a part of "param", but it's not directly accessible
  3. def do_work(param):
  4.     # Navigating object graph to get to the array
  5.     data_array = param.related_object.some_dict['data_array']
  6.  
  7.     # This array contains more data, we remove it
  8.     relevant_array = [x for x in data_array if not useless(x)]
  9.  
  10.     # Only now we can start processing business logic
  11.     result = [process(x) for x in relevant_array]
  12.  
  13.     return result
  14.  
  15. # In tests
  16. def test():
  17.     # Since the "param" is some complex structure,
  18.     # that is probably used for something else,
  19.     # we need to do a lot of effort to mock it
  20.    
  21.     # Produces more data, which is mostly "useless()", hence it's slower
  22.     data_array = Factory.get_generic_data_array()  
  23.     fake_param = MagicMock()
  24.     fake_param.related_object.some_dict['data_array'] = data_array
  25.  
  26.     # Only now we can finally execute it
  27.     assert do_work(fake_param) == Factory.get_do_work_result()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top