From 24474488274dadd72afd1086915f2b23c3a06e8a Mon Sep 17 00:00:00 2001 From: Marcel Wilson Date: Tue, 2 Apr 2024 16:52:06 -0400 Subject: [PATCH] fixing #137 --- screenpy/speech_tools.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/screenpy/speech_tools.py b/screenpy/speech_tools.py index b358b88..9a78cda 100644 --- a/screenpy/speech_tools.py +++ b/screenpy/speech_tools.py @@ -4,9 +4,9 @@ import re from typing import TypeVar, overload +from unittest import mock from hamcrest.core.helpers.hasmethod import hasmethod -from hamcrest.core.helpers.ismock import ismock from screenpy.protocols import Answerable, Describable, Performable, Resolvable @@ -52,22 +52,20 @@ class name: replace each capital letter with a space and a lower-case @overload -def represent_prop(item: str) -> str: ... +def represent_prop(item: mock.Mock) -> mock.Mock: ... @overload -def represent_prop(item: T) -> T: ... +def represent_prop(item: str | T) -> str: ... -def represent_prop(item: str | T) -> str | T: +def represent_prop(item: str | T | mock.Mock) -> str | mock.Mock: """Represent items in a manner suitable for the audience (logging).""" - if not ismock(item) and hasmethod(item, "describe_to"): + if isinstance(item, mock.Mock): + return item + if hasmethod(item, "describe_to"): return f"{item}" if isinstance(item, str): return repr(item) - description = str(item) - if description[:1] == "<" and description[-1:] == ">": - return item - return f"<{item}>"