From 7b4dd7528397f075f133ceb6bc5cc34474736786 Mon Sep 17 00:00:00 2001 From: Marcel Wilson Date: Thu, 11 Jan 2024 10:22:24 -0600 Subject: [PATCH] * TCH --- pyproject.toml | 14 +++++++------- screenpy_selenium/abilities/browse_the_web.py | 6 ++++-- screenpy_selenium/actions/accept_alert.py | 6 +++++- screenpy_selenium/actions/chain.py | 6 +++++- screenpy_selenium/actions/clear.py | 8 +++++--- screenpy_selenium/actions/click.py | 10 ++++++---- screenpy_selenium/actions/dismiss_alert.py | 6 +++++- screenpy_selenium/actions/double_click.py | 9 ++++++--- screenpy_selenium/actions/enter.py | 11 +++++++---- screenpy_selenium/actions/enter_2fa_token.py | 11 +++++++---- screenpy_selenium/actions/go_back.py | 6 +++++- screenpy_selenium/actions/go_forward.py | 6 +++++- screenpy_selenium/actions/hold_down.py | 11 +++++++---- screenpy_selenium/actions/move_mouse.py | 9 ++++++--- screenpy_selenium/actions/open.py | 6 ++++-- screenpy_selenium/actions/pause.py | 8 ++++++-- screenpy_selenium/actions/refresh_page.py | 6 +++++- screenpy_selenium/actions/release.py | 8 +++++--- screenpy_selenium/actions/respond_to_the_prompt.py | 6 ++++-- screenpy_selenium/actions/right_click.py | 9 ++++++--- screenpy_selenium/actions/save_console_log.py | 6 ++++-- screenpy_selenium/actions/save_screenshot.py | 6 ++++-- screenpy_selenium/actions/select.py | 8 +++++--- screenpy_selenium/actions/switch_to.py | 9 ++++++--- screenpy_selenium/actions/switch_to_tab.py | 6 +++++- screenpy_selenium/actions/wait.py | 6 ++++-- screenpy_selenium/protocols.py | 7 ++++--- screenpy_selenium/questions/attribute.py | 8 +++++--- screenpy_selenium/questions/browser_title.py | 6 +++++- screenpy_selenium/questions/browser_url.py | 6 +++++- screenpy_selenium/questions/cookies.py | 6 +++++- screenpy_selenium/questions/element.py | 11 +++++++---- screenpy_selenium/questions/list.py | 10 ++++++---- screenpy_selenium/questions/number.py | 8 +++++--- screenpy_selenium/questions/selected.py | 8 +++++--- screenpy_selenium/questions/text.py | 8 +++++--- screenpy_selenium/questions/text_of_the_alert.py | 6 +++++- .../custom_matchers/is_clickable_element.py | 6 ++++-- .../custom_matchers/is_invisible_element.py | 6 ++++-- .../custom_matchers/is_present_element.py | 6 ++++-- .../custom_matchers/is_visible_element.py | 6 ++++-- screenpy_selenium/resolutions/is_clickable.py | 6 +++++- screenpy_selenium/resolutions/is_invisible.py | 6 +++++- screenpy_selenium/resolutions/is_present.py | 6 +++++- screenpy_selenium/resolutions/is_visible.py | 6 +++++- screenpy_selenium/target.py | 8 +++++--- tests/test_resolutions.py | 7 +++++-- tests/test_target.py | 6 +++++- tests/useful_mocks.py | 6 ++++-- 49 files changed, 250 insertions(+), 112 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 29905ba..a0bde90 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -132,12 +132,12 @@ select = [ "PT", # flake8-pytest-style "Q", # flake8-quotes "RET", # flake8-return -# "RSE", # flake8-raise -# "RUF", # ruff specific -# "SIM", # flake8-simplify -# "T10", # flake8-debugger -# "T20", # flake8-print -# "TCH", # flake8-type-checking + "RSE", # flake8-raise + "RUF", # ruff specific + "SIM", # flake8-simplify + "T10", # flake8-debugger + "T20", # flake8-print + "TCH", # flake8-type-checking # "TRY", # tryceratops # "UP", # python upgrade "W", # pycodestyle warning @@ -164,7 +164,7 @@ exclude = [ extend-safe-fixes = [ "EM101", "EM102", -# "TCH001", "TCH002", "TCH003", "TCH004", + "TCH001", "TCH002", "TCH003", "TCH004", # "SIM108" # maybe? # "F841", diff --git a/screenpy_selenium/abilities/browse_the_web.py b/screenpy_selenium/abilities/browse_the_web.py index 711207c..ca87fa5 100644 --- a/screenpy_selenium/abilities/browse_the_web.py +++ b/screenpy_selenium/abilities/browse_the_web.py @@ -2,13 +2,15 @@ from __future__ import annotations import os -from typing import Type, TypeVar +from typing import TYPE_CHECKING, Type, TypeVar from selenium.webdriver import Chrome, Firefox, Remote, Safari -from selenium.webdriver.remote.webdriver import WebDriver from ..exceptions import BrowsingError +if TYPE_CHECKING: + from selenium.webdriver.remote.webdriver import WebDriver + DEFAULT_APPIUM_HUB_URL = "http://localhost:4723/wd/hub" diff --git a/screenpy_selenium/actions/accept_alert.py b/screenpy_selenium/actions/accept_alert.py index d9bd4ef..e0f60ac 100644 --- a/screenpy_selenium/actions/accept_alert.py +++ b/screenpy_selenium/actions/accept_alert.py @@ -1,11 +1,15 @@ """Accept a javascript alert.""" from __future__ import annotations -from screenpy.actor import Actor +from typing import TYPE_CHECKING + from screenpy.pacing import aside, beat from ..abilities import BrowseTheWeb +if TYPE_CHECKING: + from screenpy.actor import Actor + class AcceptAlert: """Accept an alert! diff --git a/screenpy_selenium/actions/chain.py b/screenpy_selenium/actions/chain.py index 0dc37d7..649aee2 100644 --- a/screenpy_selenium/actions/chain.py +++ b/screenpy_selenium/actions/chain.py @@ -1,7 +1,8 @@ """A meta-Action to group a series of chainable Actions together.""" from __future__ import annotations -from screenpy.actor import Actor +from typing import TYPE_CHECKING + from screenpy.exceptions import UnableToAct from screenpy.pacing import beat from selenium.webdriver.common.action_chains import ActionChains @@ -9,6 +10,9 @@ from ..abilities import BrowseTheWeb from ..protocols import Chainable +if TYPE_CHECKING: + from screenpy.actor import Actor + class Chain: """Group a series of chainable Actions together. diff --git a/screenpy_selenium/actions/clear.py b/screenpy_selenium/actions/clear.py index 8ab5da5..f3e0caf 100644 --- a/screenpy_selenium/actions/clear.py +++ b/screenpy_selenium/actions/clear.py @@ -1,14 +1,16 @@ """Clear text from an input.""" from __future__ import annotations -from typing import Type, TypeVar +from typing import TYPE_CHECKING, Type, TypeVar -from screenpy.actor import Actor from screenpy.exceptions import DeliveryError from screenpy.pacing import beat from selenium.common.exceptions import WebDriverException -from ..target import Target +if TYPE_CHECKING: + from screenpy.actor import Actor + + from ..target import Target SelfClear = TypeVar("SelfClear", bound="Clear") diff --git a/screenpy_selenium/actions/click.py b/screenpy_selenium/actions/click.py index 57a7e1c..e2ef959 100644 --- a/screenpy_selenium/actions/click.py +++ b/screenpy_selenium/actions/click.py @@ -1,15 +1,17 @@ """Click on an element.""" from __future__ import annotations -from typing import Optional, Type, TypeVar +from typing import TYPE_CHECKING, Optional, Type, TypeVar -from screenpy.actor import Actor from screenpy.exceptions import DeliveryError, UnableToAct from screenpy.pacing import beat from selenium.common.exceptions import WebDriverException -from selenium.webdriver.common.action_chains import ActionChains -from ..target import Target +if TYPE_CHECKING: + from screenpy.actor import Actor + from selenium.webdriver.common.action_chains import ActionChains + + from ..target import Target SelfClick = TypeVar("SelfClick", bound="Click") diff --git a/screenpy_selenium/actions/dismiss_alert.py b/screenpy_selenium/actions/dismiss_alert.py index 2140cb0..066ec1a 100644 --- a/screenpy_selenium/actions/dismiss_alert.py +++ b/screenpy_selenium/actions/dismiss_alert.py @@ -1,11 +1,15 @@ """Dismiss a javascript alert.""" from __future__ import annotations -from screenpy.actor import Actor +from typing import TYPE_CHECKING + from screenpy.pacing import aside, beat from ..abilities import BrowseTheWeb +if TYPE_CHECKING: + from screenpy.actor import Actor + class DismissAlert: """Dismiss an alert. diff --git a/screenpy_selenium/actions/double_click.py b/screenpy_selenium/actions/double_click.py index 378d9dc..56f9a6f 100644 --- a/screenpy_selenium/actions/double_click.py +++ b/screenpy_selenium/actions/double_click.py @@ -1,14 +1,17 @@ """Double-click on an element, or wherever the cursor currently is.""" from __future__ import annotations -from typing import Optional, Type, TypeVar +from typing import TYPE_CHECKING, Optional, Type, TypeVar -from screenpy.actor import Actor from screenpy.pacing import beat from selenium.webdriver.common.action_chains import ActionChains from ..abilities import BrowseTheWeb -from ..target import Target + +if TYPE_CHECKING: + from screenpy.actor import Actor + + from ..target import Target SelfDoubleClick = TypeVar("SelfDoubleClick", bound="DoubleClick") diff --git a/screenpy_selenium/actions/enter.py b/screenpy_selenium/actions/enter.py index ac8523c..3f5666b 100644 --- a/screenpy_selenium/actions/enter.py +++ b/screenpy_selenium/actions/enter.py @@ -2,16 +2,19 @@ from __future__ import annotations from functools import partial -from typing import List, Optional, Type, TypeVar +from typing import TYPE_CHECKING, List, Optional, Type, TypeVar -from screenpy import Actor from screenpy.exceptions import DeliveryError, UnableToAct from screenpy.pacing import aside, beat from selenium.common.exceptions import WebDriverException -from selenium.webdriver.common.action_chains import ActionChains from ..speech_tools import KEY_NAMES -from ..target import Target + +if TYPE_CHECKING: + from screenpy import Actor + from selenium.webdriver.common.action_chains import ActionChains + + from ..target import Target SelfEnter = TypeVar("SelfEnter", bound="Enter") diff --git a/screenpy_selenium/actions/enter_2fa_token.py b/screenpy_selenium/actions/enter_2fa_token.py index 61732be..0bca8bb 100644 --- a/screenpy_selenium/actions/enter_2fa_token.py +++ b/screenpy_selenium/actions/enter_2fa_token.py @@ -1,16 +1,19 @@ """Enter a 2-factor authentication code into a text field.""" from __future__ import annotations -from typing import Type, TypeVar +from typing import TYPE_CHECKING, Type, TypeVar -from screenpy.actor import Actor from screenpy.pacing import beat from screenpy_pyotp.abilities import AuthenticateWith2FA -from selenium.webdriver.common.action_chains import ActionChains -from ..target import Target from .enter import Enter +if TYPE_CHECKING: + from screenpy.actor import Actor + from selenium.webdriver.common.action_chains import ActionChains + + from ..target import Target + SelfEnter2FAToken = TypeVar("SelfEnter2FAToken", bound="Enter2FAToken") diff --git a/screenpy_selenium/actions/go_back.py b/screenpy_selenium/actions/go_back.py index 550798d..2d78649 100644 --- a/screenpy_selenium/actions/go_back.py +++ b/screenpy_selenium/actions/go_back.py @@ -1,11 +1,15 @@ """Press the browser back button.""" from __future__ import annotations -from screenpy.actor import Actor +from typing import TYPE_CHECKING + from screenpy.pacing import beat from ..abilities import BrowseTheWeb +if TYPE_CHECKING: + from screenpy.actor import Actor + class GoBack: """Press the browser back button. diff --git a/screenpy_selenium/actions/go_forward.py b/screenpy_selenium/actions/go_forward.py index fd25bb8..a7317ac 100644 --- a/screenpy_selenium/actions/go_forward.py +++ b/screenpy_selenium/actions/go_forward.py @@ -1,11 +1,15 @@ """Press the browser forward button.""" from __future__ import annotations -from screenpy.actor import Actor +from typing import TYPE_CHECKING + from screenpy.pacing import beat from ..abilities import BrowseTheWeb +if TYPE_CHECKING: + from screenpy.actor import Actor + class GoForward: """Press the browser forward button. diff --git a/screenpy_selenium/actions/hold_down.py b/screenpy_selenium/actions/hold_down.py index e393ea3..0b8610a 100644 --- a/screenpy_selenium/actions/hold_down.py +++ b/screenpy_selenium/actions/hold_down.py @@ -2,16 +2,19 @@ from __future__ import annotations import platform -from typing import Optional, Type, TypeVar +from typing import TYPE_CHECKING, Optional, Type, TypeVar -from screenpy import Actor from screenpy.exceptions import UnableToAct from screenpy.pacing import beat -from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.keys import Keys from ..speech_tools import KEY_NAMES -from ..target import Target + +if TYPE_CHECKING: + from screenpy import Actor + from selenium.webdriver.common.action_chains import ActionChains + + from ..target import Target SelfHoldDown = TypeVar("SelfHoldDown", bound="HoldDown") diff --git a/screenpy_selenium/actions/move_mouse.py b/screenpy_selenium/actions/move_mouse.py index 9f68cb5..b87575f 100644 --- a/screenpy_selenium/actions/move_mouse.py +++ b/screenpy_selenium/actions/move_mouse.py @@ -1,15 +1,18 @@ """Move the mouse to a specific element, or by an offset.""" from __future__ import annotations -from typing import Optional, Tuple, Type, TypeVar +from typing import TYPE_CHECKING, Optional, Tuple, Type, TypeVar -from screenpy.actor import Actor from screenpy.exceptions import UnableToAct from screenpy.pacing import beat from selenium.webdriver.common.action_chains import ActionChains from ..abilities import BrowseTheWeb -from ..target import Target + +if TYPE_CHECKING: + from screenpy.actor import Actor + + from ..target import Target SelfMoveMouse = TypeVar("SelfMoveMouse", bound="MoveMouse") diff --git a/screenpy_selenium/actions/open.py b/screenpy_selenium/actions/open.py index 0c55437..35fc47e 100644 --- a/screenpy_selenium/actions/open.py +++ b/screenpy_selenium/actions/open.py @@ -2,13 +2,15 @@ from __future__ import annotations import os -from typing import Type, TypeVar, Union +from typing import TYPE_CHECKING, Type, TypeVar, Union -from screenpy import Actor from screenpy.pacing import beat from ..abilities import BrowseTheWeb +if TYPE_CHECKING: + from screenpy import Actor + SelfOpen = TypeVar("SelfOpen", bound="Open") diff --git a/screenpy_selenium/actions/pause.py b/screenpy_selenium/actions/pause.py index 817a4ae..52d0c99 100644 --- a/screenpy_selenium/actions/pause.py +++ b/screenpy_selenium/actions/pause.py @@ -1,10 +1,14 @@ """Pause just like in ScreenPy, but also be able to do it in a Chain!""" from __future__ import annotations -from screenpy import Actor +from typing import TYPE_CHECKING + from screenpy.actions import Pause as BasePause from screenpy.pacing import beat -from selenium.webdriver.common.action_chains import ActionChains + +if TYPE_CHECKING: + from screenpy import Actor + from selenium.webdriver.common.action_chains import ActionChains class Pause(BasePause): diff --git a/screenpy_selenium/actions/refresh_page.py b/screenpy_selenium/actions/refresh_page.py index 962d1ba..f3a3ddb 100644 --- a/screenpy_selenium/actions/refresh_page.py +++ b/screenpy_selenium/actions/refresh_page.py @@ -1,11 +1,15 @@ """Refresh the browser page.""" from __future__ import annotations -from screenpy import Actor +from typing import TYPE_CHECKING + from screenpy.pacing import beat from ..abilities import BrowseTheWeb +if TYPE_CHECKING: + from screenpy import Actor + class RefreshPage: """Refresh the browser page! diff --git a/screenpy_selenium/actions/release.py b/screenpy_selenium/actions/release.py index 7e0c3bc..20eba6c 100644 --- a/screenpy_selenium/actions/release.py +++ b/screenpy_selenium/actions/release.py @@ -2,16 +2,18 @@ from __future__ import annotations import platform -from typing import Optional, Type, TypeVar +from typing import TYPE_CHECKING, Optional, Type, TypeVar -from screenpy import Actor from screenpy.exceptions import UnableToAct from screenpy.pacing import beat -from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.keys import Keys from ..speech_tools import KEY_NAMES +if TYPE_CHECKING: + from screenpy import Actor + from selenium.webdriver.common.action_chains import ActionChains + SelfRelease = TypeVar("SelfRelease", bound="Release") diff --git a/screenpy_selenium/actions/respond_to_the_prompt.py b/screenpy_selenium/actions/respond_to_the_prompt.py index 502b197..70e6058 100644 --- a/screenpy_selenium/actions/respond_to_the_prompt.py +++ b/screenpy_selenium/actions/respond_to_the_prompt.py @@ -1,13 +1,15 @@ """Respond to a prompt.""" from __future__ import annotations -from typing import Type, TypeVar +from typing import TYPE_CHECKING, Type, TypeVar -from screenpy.actor import Actor from screenpy.pacing import aside, beat from ..abilities import BrowseTheWeb +if TYPE_CHECKING: + from screenpy.actor import Actor + SelfRespondToThePrompt = TypeVar("SelfRespondToThePrompt", bound="RespondToThePrompt") diff --git a/screenpy_selenium/actions/right_click.py b/screenpy_selenium/actions/right_click.py index b9dfb74..68d32e9 100644 --- a/screenpy_selenium/actions/right_click.py +++ b/screenpy_selenium/actions/right_click.py @@ -1,14 +1,17 @@ """Right-click on an element, or wherever the cursor currently is.""" from __future__ import annotations -from typing import Optional, Type, TypeVar +from typing import TYPE_CHECKING, Optional, Type, TypeVar -from screenpy import Actor from screenpy.pacing import beat from selenium.webdriver.common.action_chains import ActionChains from ..abilities import BrowseTheWeb -from ..target import Target + +if TYPE_CHECKING: + from screenpy import Actor + + from ..target import Target SelfRightClick = TypeVar("SelfRightClick", bound="RightClick") diff --git a/screenpy_selenium/actions/save_console_log.py b/screenpy_selenium/actions/save_console_log.py index 8707fb3..f479cee 100644 --- a/screenpy_selenium/actions/save_console_log.py +++ b/screenpy_selenium/actions/save_console_log.py @@ -2,14 +2,16 @@ from __future__ import annotations import os -from typing import Any, Optional, Type, TypeVar +from typing import TYPE_CHECKING, Any, Optional, Type, TypeVar -from screenpy import Actor from screenpy.actions import AttachTheFile from screenpy.pacing import beat from ..abilities import BrowseTheWeb +if TYPE_CHECKING: + from screenpy import Actor + SelfSaveConsoleLog = TypeVar("SelfSaveConsoleLog", bound="SaveConsoleLog") diff --git a/screenpy_selenium/actions/save_screenshot.py b/screenpy_selenium/actions/save_screenshot.py index e0add78..93623d3 100644 --- a/screenpy_selenium/actions/save_screenshot.py +++ b/screenpy_selenium/actions/save_screenshot.py @@ -2,14 +2,16 @@ from __future__ import annotations import os -from typing import Any, Optional, Type, TypeVar +from typing import TYPE_CHECKING, Any, Optional, Type, TypeVar -from screenpy import Actor from screenpy.actions import AttachTheFile from screenpy.pacing import beat from ..abilities import BrowseTheWeb +if TYPE_CHECKING: + from screenpy import Actor + SelfSaveScreenshot = TypeVar("SelfSaveScreenshot", bound="SaveScreenshot") diff --git a/screenpy_selenium/actions/select.py b/screenpy_selenium/actions/select.py index 378339d..e108476 100644 --- a/screenpy_selenium/actions/select.py +++ b/screenpy_selenium/actions/select.py @@ -1,15 +1,17 @@ """Select an item from a multi-selection field or dropdown.""" from __future__ import annotations -from typing import Optional, TypeVar, Union +from typing import TYPE_CHECKING, Optional, TypeVar, Union -from screenpy import Actor from screenpy.exceptions import DeliveryError, UnableToAct from screenpy.pacing import beat from selenium.common.exceptions import WebDriverException from selenium.webdriver.support.ui import Select as SeleniumSelect -from ..target import Target +if TYPE_CHECKING: + from screenpy import Actor + + from ..target import Target SelfSelectByText = TypeVar("SelfSelectByText", bound="SelectByText") SelfSelectByIndex = TypeVar("SelfSelectByIndex", bound="SelectByIndex") diff --git a/screenpy_selenium/actions/switch_to.py b/screenpy_selenium/actions/switch_to.py index cbe07db..bf1ec07 100644 --- a/screenpy_selenium/actions/switch_to.py +++ b/screenpy_selenium/actions/switch_to.py @@ -1,13 +1,16 @@ """Switch the driver's frame of reference.""" from __future__ import annotations -from typing import Optional, Type, TypeVar +from typing import TYPE_CHECKING, Optional, Type, TypeVar -from screenpy.actor import Actor from screenpy.pacing import beat from ..abilities import BrowseTheWeb -from ..target import Target + +if TYPE_CHECKING: + from screenpy.actor import Actor + + from ..target import Target SelfSwitchTo = TypeVar("SelfSwitchTo", bound="SwitchTo") diff --git a/screenpy_selenium/actions/switch_to_tab.py b/screenpy_selenium/actions/switch_to_tab.py index 77bd19b..2ab3547 100644 --- a/screenpy_selenium/actions/switch_to_tab.py +++ b/screenpy_selenium/actions/switch_to_tab.py @@ -1,11 +1,15 @@ """Switch to a specific tab or window.""" from __future__ import annotations -from screenpy import Actor +from typing import TYPE_CHECKING + from screenpy.pacing import beat from ..abilities import BrowseTheWeb +if TYPE_CHECKING: + from screenpy import Actor + class SwitchToTab: """Switch to a specified tab or window. diff --git a/screenpy_selenium/actions/wait.py b/screenpy_selenium/actions/wait.py index a772d6e..f175bc6 100644 --- a/screenpy_selenium/actions/wait.py +++ b/screenpy_selenium/actions/wait.py @@ -1,7 +1,7 @@ """Wait for the application to fulfill a given condition.""" from __future__ import annotations -from typing import Any, Callable, Iterable, Optional, Type, TypeVar +from typing import TYPE_CHECKING, Any, Callable, Iterable, Optional, Type, TypeVar from screenpy import Actor, settings from screenpy.exceptions import DeliveryError @@ -11,7 +11,9 @@ from selenium.webdriver.support.ui import WebDriverWait from ..abilities import BrowseTheWeb -from ..target import Target + +if TYPE_CHECKING: + from ..target import Target SelfWait = TypeVar("SelfWait", bound="Wait") diff --git a/screenpy_selenium/protocols.py b/screenpy_selenium/protocols.py index 089380b..3d7b3f2 100644 --- a/screenpy_selenium/protocols.py +++ b/screenpy_selenium/protocols.py @@ -1,10 +1,11 @@ """Additional protocols for ScreenPy Selenium.""" from __future__ import annotations -from typing import Protocol, runtime_checkable +from typing import TYPE_CHECKING, Protocol, runtime_checkable -from screenpy import Actor -from selenium.webdriver.common.action_chains import ActionChains +if TYPE_CHECKING: + from screenpy import Actor + from selenium.webdriver.common.action_chains import ActionChains @runtime_checkable diff --git a/screenpy_selenium/questions/attribute.py b/screenpy_selenium/questions/attribute.py index 5a17acb..809b4f5 100644 --- a/screenpy_selenium/questions/attribute.py +++ b/screenpy_selenium/questions/attribute.py @@ -1,13 +1,15 @@ """Investigate an attribute of a Target.""" from __future__ import annotations -from typing import List, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union -from screenpy import Actor from screenpy.exceptions import UnableToAnswer from screenpy.pacing import beat -from ..target import Target +if TYPE_CHECKING: + from screenpy import Actor + + from ..target import Target class Attribute: diff --git a/screenpy_selenium/questions/browser_title.py b/screenpy_selenium/questions/browser_title.py index 5a6ac38..6b2d18c 100644 --- a/screenpy_selenium/questions/browser_title.py +++ b/screenpy_selenium/questions/browser_title.py @@ -1,11 +1,15 @@ """Investigate the title of an Actor's active browser window.""" from __future__ import annotations -from screenpy import Actor +from typing import TYPE_CHECKING + from screenpy.pacing import beat from ..abilities import BrowseTheWeb +if TYPE_CHECKING: + from screenpy import Actor + class BrowserTitle: """Ask what the title of the browser's active window is. diff --git a/screenpy_selenium/questions/browser_url.py b/screenpy_selenium/questions/browser_url.py index e884370..a07a18d 100644 --- a/screenpy_selenium/questions/browser_url.py +++ b/screenpy_selenium/questions/browser_url.py @@ -1,11 +1,15 @@ """Investigate the current url of an Actor's browser.""" from __future__ import annotations -from screenpy import Actor +from typing import TYPE_CHECKING + from screenpy.pacing import beat from ..abilities import BrowseTheWeb +if TYPE_CHECKING: + from screenpy import Actor + class BrowserURL: """Ask what the url of the browser's active window is. diff --git a/screenpy_selenium/questions/cookies.py b/screenpy_selenium/questions/cookies.py index eb19234..382c357 100644 --- a/screenpy_selenium/questions/cookies.py +++ b/screenpy_selenium/questions/cookies.py @@ -1,11 +1,15 @@ """Investigate the cookies on the Actor's web or API session.""" from __future__ import annotations -from screenpy import Actor +from typing import TYPE_CHECKING + from screenpy.pacing import beat from ..abilities import BrowseTheWeb +if TYPE_CHECKING: + from screenpy import Actor + class Cookies: """Ask about the cookies on the Actor's web browsing session. diff --git a/screenpy_selenium/questions/element.py b/screenpy_selenium/questions/element.py index 14b49e4..1ee4bd6 100644 --- a/screenpy_selenium/questions/element.py +++ b/screenpy_selenium/questions/element.py @@ -1,14 +1,17 @@ """Investigate an element on the browser page.""" from __future__ import annotations -from typing import Optional +from typing import TYPE_CHECKING, Optional -from screenpy import Actor from screenpy.pacing import beat -from selenium.webdriver.remote.webelement import WebElement from ..exceptions import TargetingError -from ..target import Target + +if TYPE_CHECKING: + from screenpy import Actor + from selenium.webdriver.remote.webelement import WebElement + + from ..target import Target class Element: diff --git a/screenpy_selenium/questions/list.py b/screenpy_selenium/questions/list.py index 0c54312..ac0d423 100644 --- a/screenpy_selenium/questions/list.py +++ b/screenpy_selenium/questions/list.py @@ -1,13 +1,15 @@ """Investigate one or more elements.""" from __future__ import annotations -from typing import List as ListType, Type, TypeVar +from typing import TYPE_CHECKING, List as ListType, Type, TypeVar -from screenpy import Actor from screenpy.pacing import beat -from selenium.webdriver.remote.webdriver import WebElement -from ..target import Target +if TYPE_CHECKING: + from screenpy import Actor + from selenium.webdriver.remote.webdriver import WebElement + + from ..target import Target SelfList = TypeVar("SelfList", bound="List") diff --git a/screenpy_selenium/questions/number.py b/screenpy_selenium/questions/number.py index b11dfcf..022d4e0 100644 --- a/screenpy_selenium/questions/number.py +++ b/screenpy_selenium/questions/number.py @@ -1,12 +1,14 @@ """Investigate how many of an element are present on the page.""" from __future__ import annotations -from typing import Type, TypeVar +from typing import TYPE_CHECKING, Type, TypeVar -from screenpy import Actor from screenpy.pacing import beat -from ..target import Target +if TYPE_CHECKING: + from screenpy import Actor + + from ..target import Target SelfNumber = TypeVar("SelfNumber", bound="Number") diff --git a/screenpy_selenium/questions/selected.py b/screenpy_selenium/questions/selected.py index 70e7ca8..01d861f 100644 --- a/screenpy_selenium/questions/selected.py +++ b/screenpy_selenium/questions/selected.py @@ -1,13 +1,15 @@ """Investigate the selected option or options from a dropdown or multi-select field.""" from __future__ import annotations -from typing import List, Type, TypeVar, Union +from typing import TYPE_CHECKING, List, Type, TypeVar, Union -from screenpy import Actor from screenpy.pacing import beat from selenium.webdriver.support.ui import Select as SeleniumSelect -from ..target import Target +if TYPE_CHECKING: + from screenpy import Actor + + from ..target import Target SelfSelected = TypeVar("SelfSelected", bound="Selected") diff --git a/screenpy_selenium/questions/text.py b/screenpy_selenium/questions/text.py index e1378e8..62cd3ab 100644 --- a/screenpy_selenium/questions/text.py +++ b/screenpy_selenium/questions/text.py @@ -1,12 +1,14 @@ """Investigate the text of an element or many elements.""" from __future__ import annotations -from typing import List, Type, TypeVar, Union +from typing import TYPE_CHECKING, List, Type, TypeVar, Union -from screenpy import Actor from screenpy.pacing import beat -from ..target import Target +if TYPE_CHECKING: + from screenpy import Actor + + from ..target import Target SelfText = TypeVar("SelfText", bound="Text") diff --git a/screenpy_selenium/questions/text_of_the_alert.py b/screenpy_selenium/questions/text_of_the_alert.py index 5ee5627..cdca0c9 100644 --- a/screenpy_selenium/questions/text_of_the_alert.py +++ b/screenpy_selenium/questions/text_of_the_alert.py @@ -1,11 +1,15 @@ """Investigate the text of an alert.""" from __future__ import annotations -from screenpy.actor import Actor +from typing import TYPE_CHECKING + from screenpy.pacing import beat from ..abilities import BrowseTheWeb +if TYPE_CHECKING: + from screenpy.actor import Actor + class TextOfTheAlert: """Ask what text appears in the alert. diff --git a/screenpy_selenium/resolutions/custom_matchers/is_clickable_element.py b/screenpy_selenium/resolutions/custom_matchers/is_clickable_element.py index ed62d53..1db802b 100644 --- a/screenpy_selenium/resolutions/custom_matchers/is_clickable_element.py +++ b/screenpy_selenium/resolutions/custom_matchers/is_clickable_element.py @@ -7,12 +7,14 @@ """ from __future__ import annotations -from typing import Optional +from typing import TYPE_CHECKING, Optional from hamcrest.core.base_matcher import BaseMatcher -from hamcrest.core.description import Description from selenium.webdriver.remote.webelement import WebElement +if TYPE_CHECKING: + from hamcrest.core.description import Description + class IsClickableElement(BaseMatcher[Optional[WebElement]]): """Matches an element which both ``is_enabled`` and ``is_displayed``.""" diff --git a/screenpy_selenium/resolutions/custom_matchers/is_invisible_element.py b/screenpy_selenium/resolutions/custom_matchers/is_invisible_element.py index 130452c..2317604 100644 --- a/screenpy_selenium/resolutions/custom_matchers/is_invisible_element.py +++ b/screenpy_selenium/resolutions/custom_matchers/is_invisible_element.py @@ -7,12 +7,14 @@ """ from __future__ import annotations -from typing import Optional +from typing import TYPE_CHECKING, Optional from hamcrest.core.base_matcher import BaseMatcher -from hamcrest.core.description import Description from selenium.webdriver.remote.webelement import WebElement +if TYPE_CHECKING: + from hamcrest.core.description import Description + class IsInvisibleElement(BaseMatcher[Optional[WebElement]]): """Matches an element whose ``is_displayed`` method returns False.""" diff --git a/screenpy_selenium/resolutions/custom_matchers/is_present_element.py b/screenpy_selenium/resolutions/custom_matchers/is_present_element.py index b3cd764..31c4606 100644 --- a/screenpy_selenium/resolutions/custom_matchers/is_present_element.py +++ b/screenpy_selenium/resolutions/custom_matchers/is_present_element.py @@ -7,12 +7,14 @@ """ from __future__ import annotations -from typing import Optional +from typing import TYPE_CHECKING, Optional from hamcrest.core.base_matcher import BaseMatcher -from hamcrest.core.description import Description from selenium.webdriver.remote.webelement import WebElement +if TYPE_CHECKING: + from hamcrest.core.description import Description + class IsPresentElement(BaseMatcher[Optional[WebElement]]): """Matches an element to be a present WebElement.""" diff --git a/screenpy_selenium/resolutions/custom_matchers/is_visible_element.py b/screenpy_selenium/resolutions/custom_matchers/is_visible_element.py index c6062e9..6f6d5c1 100644 --- a/screenpy_selenium/resolutions/custom_matchers/is_visible_element.py +++ b/screenpy_selenium/resolutions/custom_matchers/is_visible_element.py @@ -7,12 +7,14 @@ """ from __future__ import annotations -from typing import Optional +from typing import TYPE_CHECKING, Optional from hamcrest.core.base_matcher import BaseMatcher -from hamcrest.core.description import Description from selenium.webdriver.remote.webelement import WebElement +if TYPE_CHECKING: + from hamcrest.core.description import Description + class IsVisibleElement(BaseMatcher[Optional[WebElement]]): """Matches an element whose ``is_displayed`` method returns True.""" diff --git a/screenpy_selenium/resolutions/is_clickable.py b/screenpy_selenium/resolutions/is_clickable.py index 71b499a..54edf29 100644 --- a/screenpy_selenium/resolutions/is_clickable.py +++ b/screenpy_selenium/resolutions/is_clickable.py @@ -1,10 +1,14 @@ """Matches a clickable WebElement.""" from __future__ import annotations +from typing import TYPE_CHECKING + from screenpy.resolutions.base_resolution import BaseResolution from .custom_matchers import is_clickable_element -from .custom_matchers.is_clickable_element import IsClickableElement + +if TYPE_CHECKING: + from .custom_matchers.is_clickable_element import IsClickableElement class IsClickable(BaseResolution): diff --git a/screenpy_selenium/resolutions/is_invisible.py b/screenpy_selenium/resolutions/is_invisible.py index 9d56ce2..2f6f814 100644 --- a/screenpy_selenium/resolutions/is_invisible.py +++ b/screenpy_selenium/resolutions/is_invisible.py @@ -1,10 +1,14 @@ """Matches against an invisible WebElement.""" from __future__ import annotations +from typing import TYPE_CHECKING + from screenpy.resolutions.base_resolution import BaseResolution from .custom_matchers import is_invisible_element -from .custom_matchers.is_invisible_element import IsInvisibleElement + +if TYPE_CHECKING: + from .custom_matchers.is_invisible_element import IsInvisibleElement class IsInvisible(BaseResolution): diff --git a/screenpy_selenium/resolutions/is_present.py b/screenpy_selenium/resolutions/is_present.py index d7d6dcb..77e29e0 100644 --- a/screenpy_selenium/resolutions/is_present.py +++ b/screenpy_selenium/resolutions/is_present.py @@ -1,10 +1,14 @@ """Matches a present WebElement.""" from __future__ import annotations +from typing import TYPE_CHECKING + from screenpy.resolutions.base_resolution import BaseResolution from .custom_matchers import is_present_element -from .custom_matchers.is_present_element import IsPresentElement + +if TYPE_CHECKING: + from .custom_matchers.is_present_element import IsPresentElement class IsPresent(BaseResolution): diff --git a/screenpy_selenium/resolutions/is_visible.py b/screenpy_selenium/resolutions/is_visible.py index 0a6f46e..785ad06 100644 --- a/screenpy_selenium/resolutions/is_visible.py +++ b/screenpy_selenium/resolutions/is_visible.py @@ -1,10 +1,14 @@ """Matches against a visible WebElement.""" from __future__ import annotations +from typing import TYPE_CHECKING + from screenpy.resolutions.base_resolution import BaseResolution from .custom_matchers import is_visible_element -from .custom_matchers.is_visible_element import IsVisibleElement + +if TYPE_CHECKING: + from .custom_matchers.is_visible_element import IsVisibleElement class IsVisible(BaseResolution): diff --git a/screenpy_selenium/target.py b/screenpy_selenium/target.py index 073e216..fb5d694 100644 --- a/screenpy_selenium/target.py +++ b/screenpy_selenium/target.py @@ -7,16 +7,18 @@ """ from __future__ import annotations -from typing import Iterator, List, Optional, Tuple, Type, TypeVar, Union +from typing import TYPE_CHECKING, Iterator, List, Optional, Tuple, Type, TypeVar, Union -from screenpy.actor import Actor from selenium.common.exceptions import WebDriverException from selenium.webdriver.common.by import By -from selenium.webdriver.remote.webdriver import WebElement from .abilities.browse_the_web import BrowseTheWeb from .exceptions import TargetingError +if TYPE_CHECKING: + from screenpy.actor import Actor + from selenium.webdriver.remote.webdriver import WebElement + SelfTarget = TypeVar("SelfTarget", bound="Target") diff --git a/tests/test_resolutions.py b/tests/test_resolutions.py index 23cf502..2502168 100644 --- a/tests/test_resolutions.py +++ b/tests/test_resolutions.py @@ -1,11 +1,10 @@ from __future__ import annotations from dataclasses import dataclass +from typing import TYPE_CHECKING import pytest from hamcrest.core.string_description import StringDescription -from screenpy import BaseResolution -from selenium.webdriver.remote.webelement import WebElement from screenpy_selenium import IsClickable, IsInvisible, IsPresent, IsVisible from screenpy_selenium.resolutions.custom_matchers.is_clickable_element import ( @@ -23,6 +22,10 @@ from .useful_mocks import get_mocked_element +if TYPE_CHECKING: + from screenpy import BaseResolution + from selenium.webdriver.remote.webelement import WebElement + @dataclass class ExpectedDescriptions: diff --git a/tests/test_target.py b/tests/test_target.py index 76eb8ba..6449dc2 100644 --- a/tests/test_target.py +++ b/tests/test_target.py @@ -1,7 +1,8 @@ from __future__ import annotations +from typing import TYPE_CHECKING + import pytest -from screenpy import Actor from selenium.common.exceptions import WebDriverException from selenium.webdriver.common.by import By @@ -9,6 +10,9 @@ from .useful_mocks import get_mocked_browser +if TYPE_CHECKING: + from screenpy import Actor + def test_can_be_instantiated() -> None: t1 = Target.the("test") diff --git a/tests/useful_mocks.py b/tests/useful_mocks.py index cc6b8f3..69ac492 100644 --- a/tests/useful_mocks.py +++ b/tests/useful_mocks.py @@ -1,15 +1,17 @@ from __future__ import annotations -from typing import Tuple, cast +from typing import TYPE_CHECKING, Tuple, cast from unittest import mock -from screenpy import Actor from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.remote.webdriver import WebDriver from selenium.webdriver.remote.webelement import WebElement from screenpy_selenium import BrowseTheWeb, Target +if TYPE_CHECKING: + from screenpy import Actor + def get_mocked_element() -> mock.Mock: return mock.create_autospec(WebElement, instance=True)