Skip to content

Commit

Permalink
is_present.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bandophahita committed Feb 21, 2024
1 parent 7ba2f9d commit b7e77bd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
16 changes: 9 additions & 7 deletions screenpy_selenium/resolutions/is_present.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

from typing import TYPE_CHECKING

from screenpy.resolutions.base_resolution import BaseResolution
from screenpy import beat

from .custom_matchers import is_present_element

if TYPE_CHECKING:
from .custom_matchers.is_present_element import IsPresentElement


class IsPresent(BaseResolution):
class IsPresent:
"""Match on a present element.
Examples::
Expand All @@ -22,9 +22,11 @@ class IsPresent(BaseResolution):
the_actor.should(See.the(Element(BUTTON), DoesNot(Exist())))
"""

matcher: IsPresentElement
line = "present"
matcher_function = is_present_element
def describe(self) -> str:
"""Describe the Resolution's expectation."""
return "present"

def __init__(self) -> None: # pylint: disable=useless-super-delegation
super().__init__()
@beat("... hoping it's present")
def resolve(self) -> IsPresentElement:
"""Produce the Matcher to make the assertion."""
return is_present_element()
16 changes: 9 additions & 7 deletions tests/test_resolutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_can_be_instantiated(self) -> None:
def test_matches_a_visible_element(self) -> None:
element = get_mocked_element()
element.is_displayed.return_value = True
iv: IsVisibleElement = IsVisible().resolve()
iv = IsVisible().resolve()

assert iv._matches(element)

Expand Down Expand Up @@ -231,14 +231,14 @@ def test_can_be_instantiated(self) -> None:
)
def test_matches_a_present_element(self, enabled: bool, displayed: bool) -> None:
element = get_mocked_element()
ic = IsPresent()

element.is_enabled.return_value = enabled
element.is_displayed.return_value = displayed
ic = IsPresent().resolve()

assert ic._matches(element)

def test_does_not_match_missing_element(self) -> None:
ic = IsPresent()
ic = IsPresent().resolve()

assert not ic._matches(None)

Expand All @@ -250,11 +250,13 @@ def test_descriptions(self) -> None:
describe_mismatch="was not present",
describe_none="was not present",
)
ip = IsPresent()

_assert_descriptions(IsPresent(), element, expected)
assert ip.describe() == "present"
_assert_descriptions(ip.resolve(), element, expected)

def test_type_hint(self) -> None:
ip = IsPresent()
annotation = ip.__annotations__["matcher"]
annotation = ip.resolve.__annotations__["return"]
assert annotation == "IsPresentElement"
assert type(ip.matcher) == IsPresentElement
assert type(ip.resolve()) == IsPresentElement

0 comments on commit b7e77bd

Please sign in to comment.