summaryrefslogtreecommitdiff
path: root/mock/tests/testwith.py
diff options
context:
space:
mode:
authorRobert Collins <rbtcollins@hp.com>2015-07-18 07:41:49 +1200
committerRobert Collins <rbtcollins@hp.com>2015-07-18 07:41:49 +1200
commit31d3922237ae51bba54c891970c3a638feb36768 (patch)
tree41932fd9b9758c2a1faecbc2b8c02c300d0de192 /mock/tests/testwith.py
parenta6367a9a2b6166d7d032ec91288294ec47177649 (diff)
downloadmock-31d3922237ae51bba54c891970c3a638feb36768.tar.gz
Revert "Issue #21750: mock_open.read_data can now be read from each instance, as it"
This reverts commit e9db0161fc11eceba189a0cc161deefce57529a8. Issue #288 - mock_open.return_value.<stuff here> was a widely used pattern.
Diffstat (limited to 'mock/tests/testwith.py')
-rw-r--r--mock/tests/testwith.py18
1 files changed, 2 insertions, 16 deletions
diff --git a/mock/tests/testwith.py b/mock/tests/testwith.py
index 11e97bb..25d706f 100644
--- a/mock/tests/testwith.py
+++ b/mock/tests/testwith.py
@@ -146,6 +146,7 @@ class TestMockOpen(unittest.TestCase):
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()
@@ -153,23 +154,8 @@ class TestMockOpen(unittest.TestCase):
expected_calls = [call('foo'), call().__enter__(), call().read(),
call().__exit__(None, None, None)]
self.assertEqual(mock.mock_calls, expected_calls)
- # mock_open.return_value is no longer static, because
- # readline support requires that it mutate state
+ self.assertIs(f, handle)
- def test_mock_open_context_manager_multiple_times(self):
- mock = mock_open()
- with patch('%s.open' % __name__, mock, create=True):
- with open('foo') as f:
- f.read()
- with open('bar') as f:
- f.read()
-
- expected_calls = [
- call('foo'), call().__enter__(), call().read(),
- call().__exit__(None, None, None),
- call('bar'), call().__enter__(), call().read(),
- call().__exit__(None, None, None)]
- self.assertEqual(mock.mock_calls, expected_calls)
def test_explicit_mock(self):
mock = MagicMock()