Skip to content

Commit 7e72296

Browse files
Ruff pre-commit & workflow added
1 parent fed739b commit 7e72296

35 files changed

Lines changed: 399 additions & 334 deletions

.github/workflows/ruff.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Ruff
2+
3+
on:
4+
push:
5+
branches:
6+
- 'master'
7+
paths-ignore:
8+
- 'docs/**'
9+
- 'README.md'
10+
- 'CHANGELOG.md'
11+
- 'LICENSE'
12+
- '.gitignore'
13+
pull_request:
14+
15+
jobs:
16+
ruff:
17+
runs-on: ubuntu-24.04
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Setup Environment
24+
uses: ./.github/actions/setup
25+
with:
26+
python-version: '3.12'
27+
28+
- name: Ruff lint
29+
run: uv run ruff check
30+
31+
- name: Ruff format
32+
run: uv run ruff format --check

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.15.8
4+
hooks:
5+
- id: ruff
6+
args: [--fix]
7+
pass_filenames: false
8+
- id: ruff-format
9+
pass_filenames: false

mops/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
"""Wrapper of Selenium, Appium and Playwright with a single API."""
2+
23
__version__ = '3.5.0'
34
__project_name__ = 'mops'

mops/abstraction/driver_wrapper_abc.py

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,10 @@ def get_window_size(self) -> Size:
291291
raise NotImplementedError
292292

293293
def save_screenshot(
294-
self,
295-
file_name: str,
296-
screenshot_base: Image | bytes = None,
297-
convert_type: str | None = None,
294+
self,
295+
file_name: str,
296+
screenshot_base: Image | bytes = None,
297+
convert_type: str | None = None,
298298
) -> Image:
299299
"""
300300
Take a full screenshot of the driver and save it to the specified path/filename.
@@ -318,15 +318,15 @@ def get_scroll_position(self) -> int:
318318
raise NotImplementedError
319319

320320
def assert_screenshot(
321-
self,
322-
filename: str = '',
323-
test_name: str = '',
324-
name_suffix: str = '',
325-
threshold: float | None = None,
326-
delay: float | None = None,
327-
remove: Element | list[Element] = None,
328-
cut_box: Box = None,
329-
hide: Element | list[Element] = None,
321+
self,
322+
filename: str = '',
323+
test_name: str = '',
324+
name_suffix: str = '',
325+
threshold: float | None = None,
326+
delay: float | None = None,
327+
remove: Element | list[Element] = None,
328+
cut_box: Box = None,
329+
hide: Element | list[Element] = None,
330330
) -> None:
331331
"""
332332
Assert that the given screenshot matches the currently taken screenshot.
@@ -360,15 +360,15 @@ def assert_screenshot(
360360
raise NotImplementedError
361361

362362
def soft_assert_screenshot(
363-
self,
364-
filename: str = '',
365-
test_name: str = '',
366-
name_suffix: str = '',
367-
threshold: float | None = None,
368-
delay: float | None = None,
369-
remove: Element | list[Element] = None,
370-
cut_box: Box = None,
371-
hide: Element | list[Element] = None,
363+
self,
364+
filename: str = '',
365+
test_name: str = '',
366+
name_suffix: str = '',
367+
threshold: float | None = None,
368+
delay: float | None = None,
369+
remove: Element | list[Element] = None,
370+
cut_box: Box = None,
371+
hide: Element | list[Element] = None,
372372
) -> tuple[bool, str]:
373373
"""
374374
Compare the currently taken screenshot to the expected screenshot and return a result.
@@ -638,5 +638,3 @@ def dismiss_alert(self) -> DriverWrapper:
638638
:return: :obj:`.DriverWrapper` - The current instance of the driver wrapper.
639639
"""
640640
raise NotImplementedError
641-
642-

mops/abstraction/element_abc.py

Lines changed: 71 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323

2424
class ElementABC(MixinABC, ABC):
25-
2625
name: str
2726
parent: Any | bool | None
2827
wait: bool | None
@@ -170,11 +169,11 @@ def uncheck(self) -> Element:
170169
raise NotImplementedError
171170

172171
def wait_visibility(
173-
self,
174-
*,
175-
timeout: int = WAIT_EL,
176-
silent: bool = False,
177-
continuous: bool | float = False,
172+
self,
173+
*,
174+
timeout: int = WAIT_EL,
175+
silent: bool = False,
176+
continuous: bool | float = False,
178177
) -> Element:
179178
"""
180179
Wait until the element becomes visible.
@@ -206,11 +205,11 @@ def wait_visibility(
206205
raise NotImplementedError
207206

208207
def wait_hidden(
209-
self,
210-
*,
211-
timeout: int = WAIT_EL,
212-
silent: bool = False,
213-
continuous: bool | float = False,
208+
self,
209+
*,
210+
timeout: int = WAIT_EL,
211+
silent: bool = False,
212+
continuous: bool | float = False,
214213
) -> Element:
215214
"""
216215
Wait until the element becomes hidden.
@@ -266,10 +265,10 @@ def wait_availability(self, *, timeout: int = WAIT_EL, silent: bool = False) ->
266265
raise NotImplementedError
267266

268267
def save_screenshot(
269-
self,
270-
file_name: str,
271-
screenshot_base: bytes | Image = None,
272-
convert_type: str | None = None,
268+
self,
269+
file_name: str,
270+
screenshot_base: bytes | Image = None,
271+
convert_type: str | None = None,
273272
) -> Image:
274273
"""
275274
Save a screenshot of the element.
@@ -534,11 +533,11 @@ def send_keyboard_action(self, action: str | KeyboardKeys) -> Element:
534533
raise NotImplementedError
535534

536535
def wait_elements_count(
537-
self,
538-
expected_count: int,
539-
*,
540-
timeout: float = WAIT_EL,
541-
silent: bool = False,
536+
self,
537+
expected_count: int,
538+
*,
539+
timeout: float = WAIT_EL,
540+
silent: bool = False,
542541
) -> Element:
543542
"""
544543
Wait until the number of matching elements equals the expected count.
@@ -567,11 +566,11 @@ def wait_elements_count(
567566
raise NotImplementedError
568567

569568
def wait_for_text(
570-
self,
571-
expected_text: str | None = None,
572-
*,
573-
timeout: float = WAIT_EL,
574-
silent: bool = False,
569+
self,
570+
expected_text: str | None = None,
571+
*,
572+
timeout: float = WAIT_EL,
573+
silent: bool = False,
575574
) -> Element:
576575
"""
577576
Wait for the presence of a specific text in the current element, or for any non-empty text.
@@ -600,11 +599,11 @@ def wait_for_text(
600599
raise NotImplementedError
601600

602601
def wait_for_value(
603-
self,
604-
expected_value: str | None = None,
605-
*,
606-
timeout: float = WAIT_EL,
607-
silent: bool = False,
602+
self,
603+
expected_value: str | None = None,
604+
*,
605+
timeout: float = WAIT_EL,
606+
silent: bool = False,
608607
) -> Element:
609608
"""
610609
Wait for a specific value in the current element, or for any non-empty value.
@@ -633,11 +632,11 @@ def wait_for_value(
633632
raise NotImplementedError
634633

635634
def wait_visibility_without_error(
636-
self,
637-
*,
638-
timeout: float = QUARTER_WAIT_EL,
639-
silent: bool = False,
640-
continuous: bool | float = False,
635+
self,
636+
*,
637+
timeout: float = QUARTER_WAIT_EL,
638+
silent: bool = False,
639+
continuous: bool | float = False,
641640
) -> Element:
642641
"""
643642
Wait for the element to become visible, without raising an error if it does not.
@@ -669,11 +668,11 @@ def wait_visibility_without_error(
669668
raise NotImplementedError
670669

671670
def wait_hidden_without_error(
672-
self,
673-
*,
674-
timeout: float = QUARTER_WAIT_EL,
675-
silent: bool = False,
676-
continuous: bool | float = False,
671+
self,
672+
*,
673+
timeout: float = QUARTER_WAIT_EL,
674+
silent: bool = False,
675+
continuous: bool | float = False,
677676
) -> Element:
678677
"""
679678
Wait for the element to become hidden, without raising an error if it does not.
@@ -755,11 +754,11 @@ def wait_disabled(self, *, timeout: float = WAIT_EL, silent: bool = False) -> El
755754
raise NotImplementedError
756755

757756
def wait_for_size(
758-
self,
759-
expected_size: Size,
760-
*,
761-
timeout: float = WAIT_EL,
762-
silent: bool = False,
757+
self,
758+
expected_size: Size,
759+
*,
760+
timeout: float = WAIT_EL,
761+
silent: bool = False,
763762
) -> Element:
764763
"""
765764
Wait until element size will be equal to given :class:`.Size` object
@@ -814,11 +813,11 @@ def is_fully_visible(self, check_displaying: bool = True, silent: bool = False)
814813
raise NotImplementedError
815814

816815
def scroll_into_view(
817-
self,
818-
block: ScrollTo = ScrollTo.CENTER,
819-
behavior: ScrollTypes = ScrollTypes.INSTANT,
820-
sleep: float = 0,
821-
silent: bool = False,
816+
self,
817+
block: ScrollTo = ScrollTo.CENTER,
818+
behavior: ScrollTypes = ScrollTypes.INSTANT,
819+
sleep: float = 0,
820+
silent: bool = False,
822821
) -> Element:
823822
"""
824823
Scrolls the element into view using a JavaScript script.
@@ -836,17 +835,17 @@ def scroll_into_view(
836835
raise NotImplementedError
837836

838837
def assert_screenshot(
839-
self,
840-
filename: str = '',
841-
test_name: str = '',
842-
name_suffix: str = '',
843-
threshold: float | None = None,
844-
delay: float | None = None,
845-
scroll: bool = False,
846-
remove: Element | list[Element] = None,
847-
fill_background: str | bool = False,
848-
cut_box: Box = None,
849-
hide: Element | list[Element] = None,
838+
self,
839+
filename: str = '',
840+
test_name: str = '',
841+
name_suffix: str = '',
842+
threshold: float | None = None,
843+
delay: float | None = None,
844+
scroll: bool = False,
845+
remove: Element | list[Element] = None,
846+
fill_background: str | bool = False,
847+
cut_box: Box = None,
848+
hide: Element | list[Element] = None,
850849
) -> None:
851850
"""
852851
Assert that the given screenshot matches the currently taken screenshot.
@@ -885,17 +884,17 @@ def assert_screenshot(
885884
raise NotImplementedError
886885

887886
def soft_assert_screenshot(
888-
self,
889-
filename: str = '',
890-
test_name: str = '',
891-
name_suffix: str = '',
892-
threshold: float | None = None,
893-
delay: float | None = None,
894-
scroll: bool = False,
895-
remove: Element | list[Element] = None,
896-
fill_background: str | bool = False,
897-
cut_box: Box = None,
898-
hide: Element | list[Element] = None,
887+
self,
888+
filename: str = '',
889+
test_name: str = '',
890+
name_suffix: str = '',
891+
threshold: float | None = None,
892+
delay: float | None = None,
893+
scroll: bool = False,
894+
remove: Element | list[Element] = None,
895+
fill_background: str | bool = False,
896+
cut_box: Box = None,
897+
hide: Element | list[Element] = None,
899898
) -> tuple[bool, str]:
900899
"""
901900
Compare the currently taken screenshot to the expected screenshot and return a result.

mops/abstraction/mixin_abc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111

1212
class MixinABC(ABC):
13-
1413
@property
1514
def driver(self) -> SeleniumWebDriver | AppiumWebDriver | PlaywrightSourcePage:
1615
r"""

mops/abstraction/page_abc.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313

1414
class PageABC(MixinABC, ABC):
15-
1615
anchor: Element
1716

1817
def reload_page(self, wait_page_load: bool = True) -> Page:
@@ -64,13 +63,13 @@ def is_page_opened(self, with_elements: bool = False, with_url: bool = False) ->
6463
raise NotImplementedError
6564

6665
def swipe(
67-
self,
68-
start_x: int,
69-
start_y: int,
70-
end_x: int,
71-
end_y: int,
72-
duration: int = 0,
73-
sleep: float = 0,
66+
self,
67+
start_x: int,
68+
start_y: int,
69+
end_x: int,
70+
end_y: int,
71+
duration: int = 0,
72+
sleep: float = 0,
7473
) -> Page:
7574
"""
7675
Appium only: Swipe from one point to another, with an optional duration and post-swipe delay.

0 commit comments

Comments
 (0)