diff options
author | Michael Foord <michael@voidspace.org.uk> | 2012-03-13 17:00:04 -0700 |
---|---|---|
committer | Michael Foord <michael@voidspace.org.uk> | 2012-03-13 17:00:04 -0700 |
commit | ee683230e2a28bcdf96fcd17c58c64ca55f2369c (patch) | |
tree | ff2184c0b21182eb1136d4368d52eb46b11e50cb /tests/testhelpers.py | |
parent | f5237198bb48a21e1bec104f6575ad1d605d9844 (diff) | |
download | mock-ee683230e2a28bcdf96fcd17c58c64ca55f2369c.tar.gz |
Removing mocksignature documentation
Diffstat (limited to 'tests/testhelpers.py')
-rw-r--r-- | tests/testhelpers.py | 56 |
1 files changed, 12 insertions, 44 deletions
diff --git a/tests/testhelpers.py b/tests/testhelpers.py index 1b04c88..a2d7bce 100644 --- a/tests/testhelpers.py +++ b/tests/testhelpers.py @@ -6,7 +6,7 @@ from tests.support import unittest2, inPy3k from mock import ( call, _Call, create_autospec, MagicMock, - Mock, ANY, _CallList, mock_open, patch + Mock, ANY, _CallList, patch ) from datetime import datetime @@ -359,6 +359,17 @@ class SpecSignatureTest(unittest2.TestCase): self.assertEqual(mock(), 'foo') + def test_mocking_unbound_methods(self): + class Foo(object): + def foo(self, foo): + pass + p = patch.object(Foo, 'foo') + mock_foo = p.start() + Foo().foo(1) + + mock_foo.assert_called_with(1) + + @unittest2.expectedFailure def test_create_autospec_unbound_methods(self): # see issue 128 @@ -853,48 +864,5 @@ class TestCallList(unittest2.TestCase): -class TestMockOpen(unittest2.TestCase): - - def test_mock_open(self): - mock = mock_open() - with patch('%s.open' % __name__, mock, create=True) as patched: - self.assertIs(patched, mock) - open('foo') - - mock.assert_called_once_with('foo') - - - def test_mock_open_context_manager(self): - mock = mock_open() - handle = mock.return_value - with patch('%s.open' % __name__, mock, create=True): - with open('foo') as f: - f.read() - - expected_calls = [call('foo'), call().__enter__(), call().read(), - call().__exit__(None, None, None)] - self.assertEqual(mock.mock_calls, expected_calls) - self.assertIs(f, handle) - - - def test_explicit_mock(self): - mock = MagicMock() - mock_open(mock) - - with patch('%s.open' % __name__, mock, create=True) as patched: - self.assertIs(patched, mock) - open('foo') - - mock.assert_called_once_with('foo') - - - def test_read_data(self): - mock = mock_open(read_data='foo') - with patch('%s.open' % __name__, mock, create=True): - h = open('bar') - result = h.read() - - self.assertEqual(result, 'foo') - if __name__ == '__main__': unittest2.main() |