summaryrefslogtreecommitdiff
path: root/test.py
diff options
context:
space:
mode:
authorGustavo Niemeyer <gustavo@niemeyer.net>2010-06-19 22:55:31 -0300
committerGustavo Niemeyer <gustavo@niemeyer.net>2010-06-19 22:55:31 -0300
commit9fd75500a2d7097c539ea4be23fa9763b02c3d29 (patch)
tree9cbfc09accaa90f55069f33b65a5d4ff37933cc0 /test.py
parent88f2b4b1ac94b26bafe2357fbc3129030109780b (diff)
downloadmocker-9fd75500a2d7097c539ea4be23fa9763b02c3d29.tar.gz
Fixed support for Python 2.6. Mocking of iterators was broken in
certain cases because, even though that's *not* documented, Python tries to use __length_hint__ in some cases.
Diffstat (limited to 'test.py')
-rwxr-xr-xtest.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/test.py b/test.py
index 6816513..68f3125 100755
--- a/test.py
+++ b/test.py
@@ -2524,6 +2524,25 @@ class MockTest(TestCase):
else:
self.fail("AttributeError not raised.")
+ def test_mock_raises_attribute_error_on_length_hint(self):
+ """
+ In Python 2.6+ list() uses __length_hint__() as a hint. When
+ we mock iter(), it shouldn't explode due to the lack of
+ __length_hint__.
+ """
+ def raise_error(path):
+ raise MatchError("Kaboom!")
+
+ self.mocker.act = raise_error
+ try:
+ self.mock.__length_hint__
+ except AttributeError, e:
+ self.assertEquals(str(e), "No __length_hint__ here!")
+ except MatchError:
+ self.fail("Expected AttributeError, not MatchError.")
+ else:
+ self.fail("AttributeError not raised.")
+
def test_nonzero(self):
self.assertEquals(bool(self.mock), True) # True due to 42.
(path,) = self.paths
@@ -4000,7 +4019,7 @@ class PatcherTest(TestCase):
obj.use_non_existing_attribute()
except AttributeError, error:
message = "'C' object has no attribute 'bad_attribute'"
- self.assertEquals(message, error.message)
+ self.assertEquals(message, str(error))
def main():