Created
October 9, 2014 18:56
-
-
Save omaciel/5f51c851db278a72ed5d to your computer and use it in GitHub Desktop.
Playing with Mock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mock | |
class Car(object): | |
def shift_down(self): | |
print "Down" | |
def shift_up(self): | |
print "Up" | |
with mock.patch('__main__.Car') as mocked_car: | |
my_car = mocked_car() | |
my_car.shift_up() | |
my_car.shift_down() | |
my_car.foo() | |
print my_car.method_calls | |
def hello(): | |
return "Hello" | |
with mock.patch.object(Car, 'shift_down') as mocked_shift_down: | |
mocked_shift_down.return_value = hello() | |
my_car = Car() | |
my_car.shift_up() | |
print my_car.shift_down() | |
my_car.foo() | |
print my_car.method_calls |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment