Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 30th, 2012  |  syntax: None  |  size: 1.08 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/env python2.7
  2.  
  3. from hyper import Hyper
  4. from mock import patch
  5. from pprint import pprint
  6. import mock
  7. import time
  8. import urllib
  9.  
  10. @patch('urllib.urlopen')
  11. def more_testclass(mock):
  12.     """docstring for more_test"""
  13.     get_res = mock.return_value
  14.     get_res.read.return_value = 'the result'
  15.  
  16.     hy = Hyper()
  17.     result = hy.some_func()
  18.     assert result == 'the result'
  19.     mock.reset_mock()
  20.  
  21. more_testclass()
  22.  
  23. def some_func():
  24.     get_res = urllib.urlopen()
  25.     return get_res.read()
  26.  
  27. @patch('urllib.urlopen')
  28. def more_test(mock):
  29.     """docstring for more_test"""
  30.     get_res = mock.return_value
  31.     get_res.read.return_value = 'the result'
  32.  
  33.     result = some_func()
  34.     assert result == 'the result'
  35.  
  36. more_test()
  37.  
  38. with patch('urllib.urlopen') as mock:
  39.     get_res = mock.return_value
  40.     get_res.read.return_value = 'the result'
  41.  
  42.     result = some_func()
  43.     print result
  44.     assert result == 'the result'
  45.     mock.reset_mock()
  46.  
  47. @patch.object(Hyper, 's_func')
  48. def test_sfunc(mk):
  49.     mk.return_value = True
  50.     hy = Hyper()
  51.     assert hy.s_func() == True
  52.     mk.reset_mock()
  53.  
  54. test_sfunc()