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

Cruft and ruff updates #60

Merged
merged 9 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/ScreenPyHQ/cookiecutter_screenpy/",
"commit": "2b69298215c08160678dd749884c426a55828dce",
"commit": "0b13be19c9680a328c76323c4d799de8c25be1ff",
"checkout": null,
"context": {
"cookiecutter": {
Expand All @@ -11,7 +11,8 @@
"author": "Perry Goy",
"author_email": "perry.goy@gmail.com",
"github_username": "ScreenPyHQ",
"_template": "https://github.com/ScreenPyHQ/cookiecutter_screenpy/"
"_template": "https://github.com/ScreenPyHQ/cookiecutter_screenpy/",
"_commit": "0b13be19c9680a328c76323c4d799de8c25be1ff"
}
},
"directory": null
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repos:
language_version: python3.12
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.2.0
rev: v0.9.2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, dang, i guess it's been a while. 😅

hooks:
- id: ruff
- repo: https://github.com/pre-commit/mirrors-mypy
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022-2024 Perry Goy
Copyright (c) 2022-2025 Perry Goy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy new year! 🎉


Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ requirements:

.PHONY: requirements

cruft-update:
cruft update --allow-untracked-files

.PHONY: cruft-update

################################################################################
# sub-package specific

Expand Down
1,386 changes: 760 additions & 626 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ extend-exclude = '''
[tool.ruff]
target-version = "py38" # minimum supported version
line-length = 88 # same as Black.
output-format = "concise"
extend-exclude = [
"docs",
]
Expand Down Expand Up @@ -86,8 +87,6 @@ ignore = [
"D107", # missing __init__ docstring, we do that in the class docstring.
"D203", # one blank line before class docstring, no thanks!
"D212", # multi line summary first line, we want a one line summary.
"ANN101", # missing self annotation, we only annotate self when we return it.
"ANN102", # missing cls annotation, we only annotate cls when we return it.
]

extend-safe-fixes = [
Expand Down Expand Up @@ -122,13 +121,16 @@ split-on-trailing-comma = false
"D", # we don't need public-API-polished docstrings in tests.
"FBT", # using a boolean as a test object is useful!
"PLR", # likewise using specific numbers and strings in tests.
"A",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newer versions of ruff include more rules, which were triggering on tests. This ignores them.

]
"__version__.py" = ["D"]


################################################################################
# END OF BOILERPLATE ScreenPyHQ CONFIGURATIONS #
################################################################################
[tool.ruff.lint.flake8-builtins]
builtins-allowed-modules = ["select"]

[tool.poetry]
name = "screenpy_selenium"
Expand Down
4 changes: 2 additions & 2 deletions screenpy_selenium/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
ScreenPy Selenium is an extension for ScreenPy, enabling interaction with
Selenium.

:copyright: (c) 2022-2024, Perry Goy.
:copyright: (c) 2022-2025, Perry Goy.
:license: MIT, see LICENSE for more details.
"""

Expand All @@ -29,9 +29,9 @@
__all__ = [
"BrowsingError",
"Chainable",
"settings",
"Target",
"TargetingError",
"settings",
Copy link
Contributor

@bandophahita bandophahita Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ruff wants these in slightly different alphabetical order. it considers this "isort-style"
https://docs.astral.sh/ruff/rules/unsorted-dunder-all/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, since settings is lower-case.

]

__all__ += abilities.__all__ + actions.__all__ + questions.__all__ + resolutions.__all__
2 changes: 1 addition & 1 deletion screenpy_selenium/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
__author__ = metadata["Author"]
__author_email__ = metadata["Author-email"]
__license__ = metadata["License"]
__copyright__ = f"2019-2024 {__author__}"
__copyright__ = f"2019-2025 {__author__}"
43 changes: 27 additions & 16 deletions screenpy_selenium/abilities/browse_the_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import TYPE_CHECKING

from selenium.webdriver import Chrome, Firefox, Remote, Safari
from selenium.webdriver.common.options import ArgOptions

from ..exceptions import BrowsingError

Expand Down Expand Up @@ -67,18 +68,23 @@ def using_ios(cls) -> Self:
capabilities. Default is "iPhone Simulator"
"""
hub_url = os.getenv("APPIUM_HUB_URL", DEFAULT_APPIUM_HUB_URL)
IOS_CAPABILITIES = {
"platformName": "iOS",
"platformVersion": os.getenv("IOS_DEVICE_VERSION"),
"deviceName": os.getenv("IOS_DEVICE_NAME", "iPhone Simulator"),
"automationName": "xcuitest",
"browserName": "Safari",
}

opts = ArgOptions()
opts.set_capability("platformName", "iOS")
opts.set_capability("platformVersion", os.getenv("IOS_DEVICE_VERSION"))
opts.set_capability(
"deviceName", os.getenv("IOS_DEVICE_NAME", "iPhone Simulator")
)
opts.set_capability("automationName", "xcuitest")
opts.set_capability("browserName", "Safari")

IOS_CAPABILITIES = opts.to_capabilities()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm more than a little surprised mypy didn't complain about this sooner. For sure selenium 4.18 would have triggered it. Perhaps it's just been that long since we updated?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps! Either way, thanks for updating it.

if IOS_CAPABILITIES["platformVersion"] is None:
msg = "IOS_DEVICE_VERSION Environment variable must be set."
raise BrowsingError(msg)

return cls.using(browser=Remote(hub_url, IOS_CAPABILITIES))
return cls.using(browser=Remote(hub_url, options=opts))

@classmethod
def using_android(cls) -> Self:
Expand All @@ -100,18 +106,23 @@ def using_android(cls) -> Self:
capabilities. Default is "Android Emulator"
"""
hub_url = os.getenv("APPIUM_HUB_URL", DEFAULT_APPIUM_HUB_URL)
ANDROID_CAPABILITIES = {
"platformName": "Android",
"platformVersion": os.getenv("ANDROID_DEVICE_VERSION"),
"deviceName": os.getenv("ANDROID_DEVICE_NAME", "Android Emulator"),
"automationName": "UIAutomator2",
"browserName": "Chrome",
}

opts = ArgOptions()
opts.set_capability("platformName", "Android")
opts.set_capability("platformVersion", os.getenv("ANDROID_DEVICE_VERSION"))
opts.set_capability(
"deviceName", os.getenv("ANDROID_DEVICE_NAME", "Android Emulator")
)
opts.set_capability("automationName", "UIAutomator2")
opts.set_capability("browserName", "Chrome")

ANDROID_CAPABILITIES = opts.to_capabilities()

if ANDROID_CAPABILITIES["platformVersion"] is None:
msg = "ANDROID_DEVICE_VERSION environment variable must be set."
raise BrowsingError(msg)

return cls.using(browser=Remote(hub_url, ANDROID_CAPABILITIES))
return cls.using(browser=Remote(hub_url, options=opts))

@classmethod
def using(cls, browser: WebDriver) -> Self:
Expand Down
16 changes: 8 additions & 8 deletions screenpy_selenium/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@
"Enters",
"Enters2FAToken",
"GoBack",
"GoForward",
"GoesBack",
"GoesForward",
"GoForward",
"HoldDown",
"HoldsDown",
"Hover",
Expand All @@ -101,24 +101,24 @@
"Press",
"Presses",
"Refresh",
"RefreshPage",
"Refreshes",
"RefreshesPage",
"RefreshPage",
"Release",
"Releases",
"Reload",
"ReloadPage",
"Reloads",
"ReloadsPage",
"RespondsToPrompt",
"RespondsToThePrompt",
"RespondToPrompt",
"RespondToThePrompt",
"RespondsToPrompt",
"RespondsToThePrompt",
"RightClick",
"RightClicks",
"SaveConsoleLog",
"SavesConsoleLog",
"SaveScreenshot",
"SavesConsoleLog",
"SavesScreenshot",
"Select",
"SelectByIndex",
Expand All @@ -128,12 +128,12 @@
"SelectsByIndex",
"SelectsByText",
"SelectsByValue",
"SwitchesTo",
"SwitchesToTab",
"SwitchesToWindow",
"SwitchTo",
"SwitchToTab",
"SwitchToWindow",
"SwitchesTo",
"SwitchesToTab",
"SwitchesToWindow",
"TakeScreenshot",
"TakesScreenshot",
"Visit",
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from screenpy_selenium import BrowseTheWeb


@pytest.fixture()
@pytest.fixture
def Tester() -> AnActor:
"""Provide an Actor with mocked web browsing abilities."""
AuthenticateWith2FA_Mocked = mock.create_autospec(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def not_raises(ExpectedException: type[Exception]) -> Generator:
msg = f"Incorrectly Raised {error}"
raise AssertionError(msg) from error

except Exception as error: # noqa: BLE001
except Exception as error:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Did ruff decide this wasn't necessary?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did! There have been a few rules over the past several months that got updated in a similar fashion.

msg = f"Unexpected exception {error}"
raise AssertionError(msg) from error

Expand Down
8 changes: 4 additions & 4 deletions tests/test_resolutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_type_hint(self) -> None:
ic = IsClickable()
annotation = ic.resolve.__annotations__["return"]
assert annotation == "IsClickableElement"
assert type(ic.resolve()) == IsClickableElement
assert type(ic.resolve()) is IsClickableElement

def test_beat_logging(self, caplog: pytest.LogCaptureFixture) -> None:
caplog.set_level(logging.INFO)
Expand Down Expand Up @@ -150,7 +150,7 @@ def test_type_hint(self) -> None:
iv = IsVisible()
annotation = iv.resolve.__annotations__["return"]
assert annotation == "IsVisibleElement"
assert type(iv.resolve()) == IsVisibleElement
assert type(iv.resolve()) is IsVisibleElement

def test_beat_logging(self, caplog: pytest.LogCaptureFixture) -> None:
caplog.set_level(logging.INFO)
Expand Down Expand Up @@ -216,7 +216,7 @@ def test_type_hint(self) -> None:
ii = IsInvisible()
annotation = ii.resolve.__annotations__["return"]
assert annotation == "IsInvisibleElement"
assert type(ii.resolve()) == IsInvisibleElement
assert type(ii.resolve()) is IsInvisibleElement

def test_beat_logging(self, caplog: pytest.LogCaptureFixture) -> None:
caplog.set_level(logging.INFO)
Expand Down Expand Up @@ -268,7 +268,7 @@ def test_type_hint(self) -> None:
ip = IsPresent()
annotation = ip.resolve.__annotations__["return"]
assert annotation == "IsPresentElement"
assert type(ip.resolve()) == IsPresentElement
assert type(ip.resolve()) is IsPresentElement

def test_beat_logging(self, caplog: pytest.LogCaptureFixture) -> None:
caplog.set_level(logging.INFO)
Expand Down
Loading