File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 22
22
from tempfile import TemporaryDirectory
23
23
from time import sleep
24
24
from types import ModuleType
25
- from unittest .mock import patch
25
+ from unittest import expectedFailure
26
+ from unittest .mock import Mock , patch
26
27
from urllib .error import HTTPError
27
28
from urllib .request import Request , urlopen
28
29
@@ -350,6 +351,8 @@ def test_text(self):
350
351
'B.p docstring' ,
351
352
'C' ,
352
353
'B.overridden docstring' ,
354
+ 'function_mock' ,
355
+ 'coroutine_mock' ,
353
356
]
354
357
exclude_patterns = [
355
358
'_private' ,
@@ -1157,6 +1160,11 @@ def __init__(self):
1157
1160
self .assertEqual (mod .doc ['C' ].doc ['class_var' ].docstring , 'class var' )
1158
1161
self .assertEqual (mod .doc ['C' ].doc ['instance_var' ].docstring , 'instance var' )
1159
1162
1163
+ @expectedFailure
1164
+ def test_mock_signature_error (self ):
1165
+ # GH-350 -- throws `TypeError: 'Mock' object is not subscriptable`:
1166
+ self .assertIsInstance (inspect .signature (Mock (spec = lambda x : x )), inspect .Signature )
1167
+
1160
1168
1161
1169
class HtmlHelpersTest (unittest .TestCase ):
1162
1170
"""
Original file line number Diff line number Diff line change 2
2
from collections import namedtuple
3
3
import subprocess
4
4
import os
5
+ from unittest .mock import AsyncMock , Mock
5
6
6
7
CONST = 'const'
7
8
"""CONST docstring"""
@@ -363,3 +364,19 @@ def latex_math():
363
364
364
365
class Location (namedtuple ('Location' , 'lat lon' )):
365
366
"""Geo-location, GPS position."""
367
+
368
+
369
+ def _func_spec (value : int ) -> bool :
370
+ ...
371
+
372
+ async def _coro_spec (value : int ) -> bool :
373
+ ...
374
+
375
+
376
+ class HasMockAttributes :
377
+ """
378
+ Test class containing instances of `unittest.mock.Mock`.
379
+ """
380
+
381
+ function_mock = Mock (spec = _func_spec )
382
+ coroutine_mock = AsyncMock (spec = _coro_spec )
You can’t perform that action at this time.
0 commit comments