Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* fixing ScreenPyHQ#137
* keeping logic where a non-mock object may have `< >` surrounding the str output whereby we dont need to add another.
  • Loading branch information
bandophahita authored Apr 3, 2024
1 parent 22adbc5 commit e5736dc
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions screenpy/speech_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -52,22 +52,24 @@ 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
if description.startswith("<") and description.endswith(">"):
return description

return f"<{item}>"

0 comments on commit e5736dc

Please sign in to comment.