Skip to content

Commit

Permalink
fixing ScreenPyHQ#40 - beat logging text should use single quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
bandophahita committed Feb 21, 2024
1 parent 19a9862 commit 2884ea6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
6 changes: 3 additions & 3 deletions screenpy_selenium/actions/enter.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ def then_press(self, *keys: str) -> Self:

def describe(self) -> str:
"""Describe the Action in present tense."""
return f'Enter "{self.text_to_log}" into the {self.target}.'
return f"Enter {self.text_to_log!r} into the {self.target}."

@beat('{} enters "{text_to_log}" into the {target}.')
@beat("{} enters '{text_to_log}' into the {target}.")
def perform_as(self, the_actor: Actor) -> None:
"""Direct the Actor to enter the text into the element."""
if self.target is None:
Expand All @@ -137,7 +137,7 @@ def perform_as(self, the_actor: Actor) -> None:
)
raise DeliveryError(msg) from e

@beat(' Enter "{text_to_log}" into the {target}!')
@beat(" Enter '{text_to_log}' into the {target}!")
def add_to_chain(self, the_actor: Actor, the_chain: ActionChains) -> None:
"""Add the Enter Action to a Chain of Actions."""
if self.target is None:
Expand Down
31 changes: 29 additions & 2 deletions tests/test_actions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import logging
import warnings
from contextlib import contextmanager
from typing import TYPE_CHECKING, Generator, cast
Expand Down Expand Up @@ -431,11 +432,11 @@ def test_exception(self, Tester: Actor) -> None:

def test_describe(self) -> None:
assert (
Enter("blah").into(TARGET).describe() == f'Enter "blah" into the {TARGET}.'
Enter("blah").into(TARGET).describe() == f"Enter 'blah' into the {TARGET}."
)
assert (
Enter.the_secret("blah").into(TARGET).describe()
== f'Enter "[CENSORED]" into the {TARGET}.'
== f"Enter '[CENSORED]' into the {TARGET}."
)

def test_subclass(self) -> None:
Expand All @@ -447,6 +448,32 @@ def new_method(self) -> bool:

assert SubEnter.the_text("blah").new_method() is True

def test_beat_logging(
self, Tester: Actor, caplog: pytest.LogCaptureFixture
) -> None:
target, element = get_mocked_target_and_element()
text = 'Speak "Friend" and Enter'
caplog.set_level(logging.INFO)
Enter.the_text(text).into_the(target).perform_as(Tester)

assert [r.msg for r in caplog.records] == [
f"Tester enters 'Speak \"Friend\" and Enter' into the {target}."
]

def test_beat_logging_chain(
self, Tester: Actor, caplog: pytest.LogCaptureFixture
) -> None:
chain = get_mocked_chain()
target, element = get_mocked_target_and_element()
text = "Hello, Champion City."

caplog.set_level(logging.INFO)
Enter.the_text(text).into_the(target).add_to_chain(Tester, chain)

assert [r.msg for r in caplog.records] == [
f" Enter 'Hello, Champion City.' into the {target}!"
]

def test_positional_arg_warns(self) -> None:
with pytest.warns(DeprecationWarning):
Enter("", True)
Expand Down

0 comments on commit 2884ea6

Please sign in to comment.