Created
March 25, 2012 04:12
-
-
Save msmhrt/2191333 to your computer and use it in GitHub Desktop.
side_effect = lambda *args: call(*args)
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
#!/usr/bin/env python3.2 | |
import unittest | |
from mock import call, patch | |
class Spam: | |
def __init__(self, *args): | |
pass | |
class Ham: | |
def get_spams(self, args_list): | |
spams = [Spam(*args) for args in args_list] | |
return spams | |
class TestHam(unittest.TestCase): | |
@patch('__main__.Spam') | |
def test_get_spams(self, mock_spam): | |
mock_spam.side_effect = lambda *args: call(*args) | |
args_list = [(1,), ('2',), (3, '4')] | |
spams = Ham().get_spams(args_list) | |
expected_calls = [call(*args) for args in args_list] | |
self.assertEqual(mock_spam.mock_calls, expected_calls) | |
expected_spams = expected_calls | |
self.assertEqual(spams, expected_spams) | |
if __name__ == '__main__': # pragma: no cover | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment