Created
August 16, 2011 19:09
-
-
Save alecmunro/1149878 to your computer and use it in GitHub Desktop.
Getting mock objects from different libraries
This file contains 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
"""Mocker: | |
Mocks are obtained from a mocker instance, which is created | |
automatically if you create a test case that inherits from | |
MockerTestCase. | |
""" | |
from mocker import Mocker, MockerTestCase | |
class TestCaseForMocker(MockerTestCase): | |
def test_something(self): | |
a_mock = self.mocker.mock() | |
def mocker_test(): | |
mocker = Mocker() | |
a_mock = mocker.mock() | |
"""Flexmock: | |
Mocks are obtained by calling flexmock(), which can take a | |
variety of arguments to further detail their behaviour.""" | |
from flexmock import flexmock | |
def flexmock_test(): | |
a_mock = flexmock() | |
"""Fudge: | |
There are two ways mocks are obtained in Fudge. The neater | |
way, which I'll call the "implicit" way, is with the | |
fudge.patch decorator, which performs both creation of the mock, | |
and substituting it into the namespace of the test.""" | |
from unittest import TestCase | |
import fudge | |
class TestCaseForFudge(TestCase): | |
@fudge.patch("time.sleep") | |
def test_something(self, a_mock): | |
pass | |
#Then there's the explicit way: | |
def fudge_test(): | |
a_mock = fudge.fake() | |
"""Mock: | |
mock.Mock() gives you a mock. | |
""" | |
import mock | |
def mock_test(): | |
a_mock = mock.Mock() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment