daily pastebin goal
17%
SHARE
TWEET

Untitled

a guest Jul 17th, 2012 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     @patch('__builtin__.open')
  2.     @patch.object(os.path, 'join')
  3.     @patch.object(os, 'getcwd')
  4.     def test_002_readfile_exist_with_local_provided\
  5.         (self, mk_getcwd, mk_join, mk_open):
  6.         """
  7.        Tests reading a file and verify its content with local
  8.        provided.
  9.        """
  10.         # setup mocks
  11.         mk_getcwd.return_value = None
  12.         mk_join.return_value = '/tmp/test/dummy.py'
  13.         mk_open.return_value = MagicMock(spec=file)
  14.         m_file = mk_open.return_value.__enter__.return_value
  15.         m_file.read.return_value = 'hello world'
  16.  
  17.         # assert function output is 'hello world'
  18.         self.assertEqual(
  19.                         readfile(self.source_f, **self.kwargs),
  20.                         'hello world')
  21.  
  22.         # assert mk_getcwd
  23.         self.assertEqual(mk_getcwd.called, True)
  24.         self.assertEqual(mk_getcwd.call_args_list, [call()])
  25.  
  26.         # assert mk_join
  27.         self.assertEqual(mk_join.call_count, 1)
  28.         join_call_list = [call(self.kwargs['local'], 'dummy.py')]
  29.         self.assertEqual(mk_join.call_args_list, join_call_list)
  30.  
  31.         # assert mk_open
  32.         self.assertEqual(mk_open.call_count, 1)
  33.         open_call_list = [call('/tmp/test/dummy.py', 'r')]
  34.         self.assertEqual(mk_open.call_args_list, open_call_list)
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