summaryrefslogtreecommitdiff
path: root/Lib/unittest/test/testmock/testpatch.py
diff options
context:
space:
mode:
authorChris Withers <chris@withers.org>2020-01-29 16:24:54 +0000
committerGitHub <noreply@github.com>2020-01-29 16:24:54 +0000
commitdb5e86adbce12350c26e7ffc2c6673369971a2dc (patch)
tree4d0ea04ac823485a1366958f36136fdd0a809726 /Lib/unittest/test/testmock/testpatch.py
parenta327677905956ae0b239ff430a1346dfe265709e (diff)
downloadcpython-git-db5e86adbce12350c26e7ffc2c6673369971a2dc.tar.gz
Get mock coverage back to 100% (GH-18228)
* use the `: pass` and `: yield` patterns for code that isn't expected to ever be executed. * The _Call items passed to _AnyComparer are only ever of length two, so assert instead of if/else * fix typo * Fix bug, where stop-without-start patching dict blows up with `TypeError: 'NoneType' object is not iterable`, highlighted by lack of coverage of an except branch. * The fix for bpo-37972 means _Call.count and _Call.index are no longer needed. * add coverage for calling next() on a mock_open with readline.return_value set. * __aiter__ is defined on the Mock so the one on _AsyncIterator is never called.
Diffstat (limited to 'Lib/unittest/test/testmock/testpatch.py')
-rw-r--r--Lib/unittest/test/testmock/testpatch.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/unittest/test/testmock/testpatch.py b/Lib/unittest/test/testmock/testpatch.py
index 438dfd8cfb..f1bc0e1cd4 100644
--- a/Lib/unittest/test/testmock/testpatch.py
+++ b/Lib/unittest/test/testmock/testpatch.py
@@ -770,6 +770,14 @@ class PatchTest(unittest.TestCase):
self.assertEqual(d, original)
+ def test_patch_dict_stop_without_start(self):
+ d = {'foo': 'bar'}
+ original = d.copy()
+ patcher = patch.dict(d, [('spam', 'eggs')], clear=True)
+ self.assertEqual(patcher.stop(), False)
+ self.assertEqual(d, original)
+
+
def test_patch_dict_class_decorator(self):
this = self
d = {'spam': 'eggs'}