mirror of
https://github.com/langgenius/dify.git
synced 2026-11-14 07:11:06 +08:00
19 lines
579 B
Python
19 lines
579 B
Python
"""Inspect actual spies installed on real objects, including autospec wrappers."""
|
|
|
|
from typing import Protocol, runtime_checkable
|
|
from unittest.mock import Mock
|
|
|
|
|
|
@runtime_checkable
|
|
class _AutospeccedMethod(Protocol):
|
|
# unittest.mock.create_autospec exposes the underlying spy on its function wrapper.
|
|
mock: Mock
|
|
|
|
|
|
def installed_mock(method: object) -> Mock:
|
|
"""Return the installed spy without treating a real bound method as a mock."""
|
|
if isinstance(method, Mock):
|
|
return method
|
|
assert isinstance(method, _AutospeccedMethod)
|
|
return method.mock
|