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

match describe text with the alias #93

Open
MarcelWilson opened this issue Aug 18, 2023 · 2 comments
Open

match describe text with the alias #93

MarcelWilson opened this issue Aug 18, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@MarcelWilson
Copy link
Contributor

I love aliases. I like being able to customize the way tests read.

actor.will(See(question, resolution))
actor.will(Confirm(question, resolution))
actor.will(Observe(question, resolution))

However, when it comes to logging, it just recently dawned on me that the use of aliases doesn't change the output text.
All of the above lines will log exactly the same:

Marcel sees if question is resolution

Wouldn't it be great if aliases logged the way they were written?

Marcel will see if question is resolution
Marcel will confirm if question is resolution
Marcel will observe if question is resolution

The gotcha here would be getting the logging to know which method was used in the actor as well.

actor(Sees(question, resolution))

ought to log
Marcel sees question is resolution
I'm not sure how feasible this is, but it sure would be cool if it could.

@perrygoy
Copy link
Member

perrygoy commented Aug 18, 2023

I think this is possible, and it's something i've outlined here: #90 (comment)

All we'd need to do is have aliases through inheritance rather than simple equality. Or we could make a make_see that takes in a the word to use in the description and sets that as the class property in the version of See it returns (multiply that across all our Actions):

def make_see(action_word: str):
    class _See:
        @beat("{} {action_word} if ...")
        def perform_as(...)
        ...  # same as See currently is
       

    _See.action_word = action_word
    return _See


See = make_see("sees")
Saw = make_see("saw")
...

What do you think? The second might look a bit weirder, but it makes it easier to add aliases than the inheritance way. This is actually pretty close to what i've done in ScreenPy Requests to make all the HTTP method Actions: https://github.com/ScreenPyHQ/screenpy_requests/blob/trunk/screenpy_requests/actions/__init__.py#L20

@bandophahita bandophahita added the enhancement New feature or request label Aug 18, 2023
@MarcelWilson
Copy link
Contributor Author

MarcelWilson commented Aug 18, 2023

I haven't really considered this fully yet, but my initial thought was subclassing actions.

class See:
    @beat("{} {action_word} if ...")
    def perform_as(....):
        ...

class Confirm(See):
    def describe(self) -> str:
        return f"Confirm {self.question_to_log} is {self.resolution_to_log}."
    action_word = "confirm"

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

No branches or pull requests

3 participants