From b7e77bd54889364dad8a52b6cd6414f12587e360 Mon Sep 17 00:00:00 2001 From: Marcel Wilson Date: Wed, 21 Feb 2024 17:42:01 -0600 Subject: [PATCH] is_present.py --- screenpy_selenium/resolutions/is_present.py | 16 +++++++++------- tests/test_resolutions.py | 16 +++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/screenpy_selenium/resolutions/is_present.py b/screenpy_selenium/resolutions/is_present.py index 4055794..6ed23bb 100644 --- a/screenpy_selenium/resolutions/is_present.py +++ b/screenpy_selenium/resolutions/is_present.py @@ -4,7 +4,7 @@ from typing import TYPE_CHECKING -from screenpy.resolutions.base_resolution import BaseResolution +from screenpy import beat from .custom_matchers import is_present_element @@ -12,7 +12,7 @@ from .custom_matchers.is_present_element import IsPresentElement -class IsPresent(BaseResolution): +class IsPresent: """Match on a present element. Examples:: @@ -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() diff --git a/tests/test_resolutions.py b/tests/test_resolutions.py index 3694c6e..d3ebe1d 100644 --- a/tests/test_resolutions.py +++ b/tests/test_resolutions.py @@ -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) @@ -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) @@ -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