summaryrefslogtreecommitdiff
path: root/mock/tests
diff options
context:
space:
mode:
authorXtreak <tirkarthi@users.noreply.github.com>2018-12-03 13:28:15 +0530
committerChris Withers <chris@withers.org>2019-04-30 08:39:55 +0100
commit98f4fc477ea89472ac9fb75ed0b005a681c79304 (patch)
tree577aa19f71dfbb9e51a4cd61444f900612934e27 /mock/tests
parent5a593292f8e7e27da990e9c548b1e9fcd5c81bf1 (diff)
downloadmock-98f4fc477ea89472ac9fb75ed0b005a681c79304.tar.gz
bpo-32153: Add unit test for create_autospec with partial function returned in getattr (#10398)
* Add create_autospec with partial function returned in getattr * Use self.assertFalse instead of assert * Use different names and remove object Backports: c667b094ae37799a7e42ba5cd2ad501cc7920888 Signed-off-by: Chris Withers <chris@simplistix.co.uk>
Diffstat (limited to 'mock/tests')
-rw-r--r--mock/tests/testhelpers.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/mock/tests/testhelpers.py b/mock/tests/testhelpers.py
index e7c42f6..cc3e4f8 100644
--- a/mock/tests/testhelpers.py
+++ b/mock/tests/testhelpers.py
@@ -15,6 +15,7 @@ from mock import (
from mock.mock import _Call, _CallList
from datetime import datetime
+from functools import partial
class SomeClass(object):
def one(self, a, b):
@@ -962,6 +963,17 @@ class SpecSignatureTest(unittest.TestCase):
self.assertRaises(TypeError, sock_class, foo=1)
+ def test_autospec_getattr_partial_function(self):
+ # bpo-32153 : getattr returning partial functions without
+ # __name__ should not create AttributeError in create_autospec
+ class Foo:
+ def __getattr__(self, attribute):
+ return partial(lambda name: name, attribute)
+ proxy = Foo()
+ autospec = create_autospec(proxy)
+ self.assertFalse(hasattr(autospec, '__name__'))
+
+
class TestCallList(unittest.TestCase):
def test_args_list_contains_call_list(self):