Created
February 28, 2011 21:46
-
-
Save awestendorf/848107 to your computer and use it in GitHub Desktop.
An example of Chai
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
from chai import Chai | |
class CustomObject (object): | |
def get(self, arg): | |
pass | |
class TestCase(Chai): | |
def test_mock_get(self): | |
obj = CustomObject() | |
expect(obj.get).args('name').returns('My Name') | |
assert_equals(obj.get('name'), 'My Name') | |
expect(obj.get).args('name').returns('Your Name') | |
assert_equals(obj.get('name'), 'Your Name') | |
def test_mock_get_with_at_most(self): | |
obj = CustomObject() | |
expect(obj.get).args('name').returns('My Name').at_most(2) | |
assert_equals(obj.get('name'), 'My Name') | |
assert_equals(obj.get('name'), 'My Name') | |
assert_equals(obj.get('name'), 'My Name') # this one will fail | |
def test_mock_object(self): | |
mock = mock() | |
expect(mock).args('name').returns('My Name') | |
assert_equals('My Name', mock('name')) | |
expect(mock.foo).args('name').returns('Your Name') | |
assert_equals('Your Name', mock.foo('name')) | |
def test_stub(self): | |
obj = CustomObject() | |
stub(obj.get) | |
assert_equals(obj.get('name'), 'My Name') # this will fail | |
if __name__ == '__main__': | |
import unittest2 | |
unittest2.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment