summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichael Foord <michael@voidspace.org.uk>2012-02-12 17:23:28 +0000
committerMichael Foord <michael@voidspace.org.uk>2012-02-12 17:23:28 +0000
commit241f9dc023efa4e402c550c237baaa9350b5a9db (patch)
tree525fe76761037010ee5fdde8682357a0c5916385 /tests
parent69d76954d5a401666b15d4942b18e1b9d9c495fb (diff)
downloadmock-241f9dc023efa4e402c550c237baaa9350b5a9db.tar.gz
Improvement to handing of MagicMock.__iter__ return value.
Diffstat (limited to 'tests')
-rw-r--r--tests/testmagicmethods.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/testmagicmethods.py b/tests/testmagicmethods.py
index 745377e..6dac3cc 100644
--- a/tests/testmagicmethods.py
+++ b/tests/testmagicmethods.py
@@ -455,6 +455,16 @@ class TestMockingMagicMethods(unittest2.TestCase):
self.assertEqual(str(m), 'foo')
+ def test_iterable_as_iter_return_value(self):
+ m = MagicMock()
+ m.__iter__.return_value = [1, 2, 3]
+ self.assertEqual(list(m), [1, 2, 3])
+ self.assertEqual(list(m), [1, 2, 3])
+
+ m.__iter__.return_value = iter([4, 5, 6])
+ self.assertEqual(list(m), [4, 5, 6])
+ self.assertEqual(list(m), [])
+
if __name__ == '__main__':
unittest2.main()