aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/unittest/test/testmock/testwith.py
diff options
context:
space:
mode:
authorRobert Collins <rbtcollins@hp.com>2015-07-17 20:08:45 +1200
committerRobert Collins <rbtcollins@hp.com>2015-07-17 20:08:45 +1200
commit5329aaa74bfe48a3be4fcd15d070bacfde682267 (patch)
treedf4df4e19122af73c1a262d2719843b8ef990c87 /Lib/unittest/test/testmock/testwith.py
parent579db160b392404b6dd9608ce5f5bef29a9885a4 (diff)
downloadcpython-5329aaa74bfe48a3be4fcd15d070bacfde682267.tar.gz
cpython-5329aaa74bfe48a3be4fcd15d070bacfde682267.zip
Issue #21750: mock_open.read_data can now be read from each instance, as it
could in Python 3.3.
Diffstat (limited to 'Lib/unittest/test/testmock/testwith.py')
-rw-r--r--Lib/unittest/test/testmock/testwith.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/Lib/unittest/test/testmock/testwith.py b/Lib/unittest/test/testmock/testwith.py
index f54e051e945..ddcfe77e4d9 100644
--- a/Lib/unittest/test/testmock/testwith.py
+++ b/Lib/unittest/test/testmock/testwith.py
@@ -141,7 +141,6 @@ 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()
@@ -149,8 +148,23 @@ class TestMockOpen(unittest.TestCase):
expected_calls = [call('foo'), call().__enter__(), call().read(),
call().__exit__(None, None, None)]
self.assertEqual(mock.mock_calls, expected_calls)
- self.assertIs(f, handle)
+ # mock_open.return_value is no longer static, because
+ # readline support requires that it mutate state
+ 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()