diff options
author | Xtreak <tir.karthi@gmail.com> | 2019-04-22 02:30:23 (GMT) |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2019-04-22 02:30:23 (GMT) |
commit | 9b21856b0fcda949de239edc7aa6cf3f2f4f77a3 (patch) | |
tree | 67b8f216a06b29748f5e573d5ab855b3462752e7 /Lib/unittest/test/testmock/testhelpers.py | |
parent | 9541bd321a94f13dc41163a5d7a1a847816fac84 (diff) | |
download | cpython-9b21856b0fcda949de239edc7aa6cf3f2f4f77a3.zip cpython-9b21856b0fcda949de239edc7aa6cf3f2f4f77a3.tar.gz cpython-9b21856b0fcda949de239edc7aa6cf3f2f4f77a3.tar.bz2 |
bpo-23078: Add support for {class,static}method to mock.create_autospec() (GH-11613)
Co-authored-by: Felipe <felipe.nospam.ochoa@gmail.com>
Diffstat (limited to 'Lib/unittest/test/testmock/testhelpers.py')
-rw-r--r-- | Lib/unittest/test/testmock/testhelpers.py | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/Lib/unittest/test/testmock/testhelpers.py b/Lib/unittest/test/testmock/testhelpers.py index 9f1bf26..0d03108 100644 --- a/Lib/unittest/test/testmock/testhelpers.py +++ b/Lib/unittest/test/testmock/testhelpers.py @@ -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() |