Skip to content

Commit b014542

Browse files
committed
Add class with mocks to unit test example package
1 parent 92ad3ae commit b014542

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

pdoc/test/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
from tempfile import TemporaryDirectory
2323
from time import sleep
2424
from types import ModuleType
25-
from unittest.mock import patch
25+
from unittest import expectedFailure
26+
from unittest.mock import Mock, patch
2627
from urllib.error import HTTPError
2728
from urllib.request import Request, urlopen
2829

@@ -350,6 +351,8 @@ def test_text(self):
350351
'B.p docstring',
351352
'C',
352353
'B.overridden docstring',
354+
'function_mock',
355+
'coroutine_mock',
353356
]
354357
exclude_patterns = [
355358
'_private',
@@ -1157,6 +1160,11 @@ def __init__(self):
11571160
self.assertEqual(mod.doc['C'].doc['class_var'].docstring, 'class var')
11581161
self.assertEqual(mod.doc['C'].doc['instance_var'].docstring, 'instance var')
11591162

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+
11601168

11611169
class HtmlHelpersTest(unittest.TestCase):
11621170
"""

pdoc/test/example_pkg/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from collections import namedtuple
33
import subprocess
44
import os
5+
from unittest.mock import AsyncMock, Mock
56

67
CONST = 'const'
78
"""CONST docstring"""
@@ -363,3 +364,19 @@ def latex_math():
363364

364365
class Location(namedtuple('Location', 'lat lon')):
365366
"""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)

0 commit comments

Comments
 (0)