mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
bpo-23078: Add support for {class,static}method to mock.create_autospec() (GH-11613)
Co-authored-by: Felipe <felipe.nospam.ochoa@gmail.com>
This commit is contained in:
parent
9541bd321a
commit
9b21856b0f
5 changed files with 81 additions and 2 deletions
|
@ -5,7 +5,7 @@ import unittest
|
|||
|
||||
from unittest.mock import (
|
||||
call, _Call, create_autospec, MagicMock,
|
||||
Mock, ANY, _CallList, patch, PropertyMock
|
||||
Mock, ANY, _CallList, patch, PropertyMock, _callable
|
||||
)
|
||||
|
||||
from datetime import datetime
|
||||
|
@ -1011,5 +1011,43 @@ class TestCallList(unittest.TestCase):
|
|||
self.assertNotIsInstance(returned, PropertyMock)
|
||||
|
||||
|
||||
class TestCallablePredicate(unittest.TestCase):
|
||||
|
||||
def test_type(self):
|
||||
for obj in [str, bytes, int, list, tuple, SomeClass]:
|
||||
self.assertTrue(_callable(obj))
|
||||
|
||||
def test_call_magic_method(self):
|
||||
class Callable:
|
||||
def __call__(self):
|
||||
pass
|
||||
instance = Callable()
|
||||
self.assertTrue(_callable(instance))
|
||||
|
||||
def test_staticmethod(self):
|
||||
class WithStaticMethod:
|
||||
@staticmethod
|
||||
def staticfunc():
|
||||
pass
|
||||
self.assertTrue(_callable(WithStaticMethod.staticfunc))
|
||||
|
||||
def test_non_callable_staticmethod(self):
|
||||
class BadStaticMethod:
|
||||
not_callable = staticmethod(None)
|
||||
self.assertFalse(_callable(BadStaticMethod.not_callable))
|
||||
|
||||
def test_classmethod(self):
|
||||
class WithClassMethod:
|
||||
@classmethod
|
||||
def classfunc(cls):
|
||||
pass
|
||||
self.assertTrue(_callable(WithClassMethod.classfunc))
|
||||
|
||||
def test_non_callable_classmethod(self):
|
||||
class BadClassMethod:
|
||||
not_callable = classmethod(None)
|
||||
self.assertFalse(_callable(BadClassMethod.not_callable))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue