Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support enums in represent_prop #144

Open
bandophahita opened this issue Jul 17, 2024 · 1 comment
Open

support enums in represent_prop #144

bandophahita opened this issue Jul 17, 2024 · 1 comment

Comments

@bandophahita
Copy link
Contributor

bandophahita commented Jul 17, 2024

Consider the following code

class ScheduleStatus(StrEnum):
    DRAFT = "DRAFT"
    POSTED = "POSTED"
    ARCHIVED = "ARCHIVED"

actor.shall(See(Text(SCHEDULE_STATUS), ReadsExactly(ScheduleStatus.POSTED)))

Which works fine but logs as follows:

Marcel sees if the text from the schedule status is <ScheduleStatus.POSTED: 'POSTED'>, verbatim.

What we really want is:

Marcel sees if the text from the schedule status is 'POSTED', verbatim.

To avoid this we can wrap the enum in a string, but could perhaps represent_prop do this for us?

@bandophahita
Copy link
Contributor Author

The problem is isinstance(ScheduleStatus.POSTED, str) returns true even though type(ScheduleStatus.POSTED) returns <enum 'ScheduleStatus'>.

I'm curious if we can get away with something like this:

def represent_prop(item: str | T | mock.Mock) -> str | mock.Mock:
    """Represent items in a manner suitable for the audience (logging)."""
    if isinstance(item, mock.Mock):
        return item
    if hasmethod(item, "describe_to"):
        return f"{item}"
    if isisntance(item, Enum):
        return repr(f"{item}")
    if isinstance(item, str):
        return repr(item)
    ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant