diff options
author | Michael Foord <michael@voidspace.org.uk> | 2012-04-13 17:16:54 +0100 |
---|---|---|
committer | Michael Foord <michael@voidspace.org.uk> | 2012-04-13 17:16:54 +0100 |
commit | 7e44aecbd98ce6e4718c81a12418505c2172fcc7 (patch) | |
tree | 3d472c2747dcfdbd46b81418a6ae8ca13a666597 /tests | |
parent | 021c8f04ba6dd92955fe02b988f29049a3540212 (diff) | |
download | mock-7e44aecbd98ce6e4718c81a12418505c2172fcc7.tar.gz |
create_autospec now works with attributes that can't be fetched
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testhelpers.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/testhelpers.py b/tests/testhelpers.py index b92f511..6a7d68b 100644 --- a/tests/testhelpers.py +++ b/tests/testhelpers.py @@ -691,6 +691,29 @@ class SpecSignatureTest(unittest2.TestCase): mock.assert_called_with(4, 5) + def test_skip_attributeerrors(self): + class Raiser(object): + def __get__(self, obj, type=None): + if obj is None: + raise AttributeError('Can only be accessed via an instance') + + class RaiserClass(object): + raiser = Raiser() + + @staticmethod + def existing(a, b): + return a + b + + s = create_autospec(RaiserClass) + self.assertRaises(TypeError, lambda x: s.existing(1, 2, 3)) + s.existing(1, 2) + self.assertRaises(AttributeError, lambda: s.nonexisting) + + # check we can fetch the raiser attribute and it has no spec + obj = s.raiser + obj.foo, obj.bar + + @unittest2.skipIf(inPy3k, 'no old style classes in Python 3') def test_signature_old_style_class(self): class Foo: |