
Untitled
By: a guest on
Jun 30th, 2012 | syntax:
None | size: 1.08 KB | hits: 14 | expires: Never
#!/usr/bin/env python2.7
from hyper import Hyper
from mock import patch
from pprint import pprint
import mock
import time
import urllib
@patch('urllib.urlopen')
def more_testclass(mock):
"""docstring for more_test"""
get_res = mock.return_value
get_res.read.return_value = 'the result'
hy = Hyper()
result = hy.some_func()
assert result == 'the result'
mock.reset_mock()
more_testclass()
def some_func():
get_res = urllib.urlopen()
return get_res.read()
@patch('urllib.urlopen')
def more_test(mock):
"""docstring for more_test"""
get_res = mock.return_value
get_res.read.return_value = 'the result'
result = some_func()
assert result == 'the result'
more_test()
with patch('urllib.urlopen') as mock:
get_res = mock.return_value
get_res.read.return_value = 'the result'
result = some_func()
print result
assert result == 'the result'
mock.reset_mock()
@patch.object(Hyper, 's_func')
def test_sfunc(mk):
mk.return_value = True
hy = Hyper()
assert hy.s_func() == True
mk.reset_mock()
test_sfunc()