Skip to content

Commit

Permalink
REFACTOR: for no warnings in codebase and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yashaka committed Jul 17, 2024
1 parent d4222d9 commit 1f26eb2
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 24 deletions.
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ check vscode pylance, mypy, jetbrains qodana...

consider customizing them via config

### TODO: ensure no warnings

### TODO: Consider passing Condition instance as by in Match

like in `clickable = Match('clickable', by=be.visible.and_(be.enabled))`
Expand Down
10 changes: 10 additions & 0 deletions selene/common/fp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# SOFTWARE.
from __future__ import annotations
import functools
import warnings

from typing_extensions import TypeVar, Callable, Any, Tuple, Optional, cast, Type

from selene.common.none_object import _NoneObject
Expand Down Expand Up @@ -199,6 +201,14 @@ def func(arg: T) -> T:
return func


def with_warn(*args, **kwargs):
def func(arg: T) -> T:
warnings.warn(*args, **kwargs)
return arg

return func


def write_silently(
file: str, string: str, encoding: str = 'utf-8'
) -> Optional[Tuple[str, str]]:
Expand Down
10 changes: 9 additions & 1 deletion selene/core/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import re
import warnings
from functools import reduce
from selene.common import fp

from selenium.common import NoSuchElementException
from selenium.webdriver.common.by import By
Expand Down Expand Up @@ -240,7 +241,14 @@ def __deprecated_is_present(element: Element) -> bool:

present: Condition[Element] = Match(
'is present in DOM',
by=__deprecated_is_present, # noqa
by=lambda element: fp.thread(
element,
fp.with_warn(
'be.present is deprecated, use be.present_in_dom instead',
DeprecationWarning,
),
lambda element: element.locate() is not None, # noqa
),
_falsy_exceptions=(
AssertionError,
NoSuchElementException,
Expand Down
4 changes: 3 additions & 1 deletion tests/acceptance/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def x_test_ecosia():

def test_duckduckgo():
browser.open('https://www.duckduckgo.org/')
browser.element(by.name('q')).type('github yashaka selene python').press_enter()
browser.element(by.name('q')).type(
'github yashaka selene python User-oriented'
).press_enter()

browser.all('[data-testid=result]').first.element(
'[data-testid=result-title-a]'
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/browser__actions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ def test_browser_actions_drags_source_and_drops_it_to_target_with_implicit_waiti
browser.element('#draggable'), browser.element('#target2')
).perform()

browser.element('#target1').element('#draggable').should(be.not_.present)
browser.element('#target2').element('#draggable').should(be.present)
browser.element('#target1').element('#draggable').should(be.not_.present_in_dom)
browser.element('#target2').element('#draggable').should(be.present_in_dom)

# WHEN
browser._actions.click_and_hold(browser.element('#draggable')).release(
browser.element('#target1')
).perform()

browser.element('#target1').element('#draggable').should(be.present)
browser.element('#target2').element('#draggable').should(be.not_.present)
browser.element('#target1').element('#draggable').should(be.present_in_dom)
browser.element('#target2').element('#draggable').should(be.not_.present_in_dom)


def test_browser_actions_fails_to_wait_for_drag_and_drop_before_perform(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ def test_drags_source_by_offset_and_drops_it_to_target(session_browser):
# WHEN
browser.element('#draggable').perform(command.drag_and_drop_by_offset(x=150, y=0))

browser.element('#target1').element('#draggable').should(be.not_.present)
browser.element('#target2').element('#draggable').should(be.present)
browser.element('#target1').element('#draggable').should(be.not_.present_in_dom)
browser.element('#target2').element('#draggable').should(be.present_in_dom)

# WHEN
browser.element('#draggable').perform(command.drag_and_drop_by_offset(x=-150, y=0))

browser.element('#target1').element('#draggable').should(be.present)
browser.element('#target2').element('#draggable').should(be.not_.present)
browser.element('#target1').element('#draggable').should(be.present_in_dom)
browser.element('#target2').element('#draggable').should(be.not_.present_in_dom)


class ReactContinuousSlider:
Expand Down
16 changes: 8 additions & 8 deletions tests/integration/element__perform__drag_and_drop_to_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ def test_drags_source_and_drops_it_to_target(session_browser):
command.drag_and_drop_to(browser.element('#target2'))
)

browser.element('#target1').element('#draggable').should(be.not_.present)
browser.element('#target2').element('#draggable').should(be.present)
browser.element('#target1').element('#draggable').should(be.not_.present_in_dom)
browser.element('#target2').element('#draggable').should(be.present_in_dom)

# WHEN
browser.element('#draggable').perform(
command.drag_and_drop_to(browser.element('#target1'))
)

browser.element('#target1').element('#draggable').should(be.present)
browser.element('#target2').element('#draggable').should(be.not_.present)
browser.element('#target1').element('#draggable').should(be.present_in_dom)
browser.element('#target2').element('#draggable').should(be.not_.present_in_dom)


def test_drags_source_and_drops_it_to_target_with_forced_retry(session_browser):
Expand Down Expand Up @@ -137,8 +137,8 @@ def test_drags_source_and_drops_it_to_target_with_forced_retry(session_browser):
command.drag_and_drop_to(browser.element('#target2'))
)

browser.element('#target1').element('#draggable').should(be.present)
browser.element('#target2').element('#draggable').should(be.not_.present)
browser.element('#target1').element('#draggable').should(be.present_in_dom)
browser.element('#target2').element('#draggable').should(be.not_.present_in_dom)

# WHEN
browser.element('#draggable').perform(
Expand All @@ -147,8 +147,8 @@ def test_drags_source_and_drops_it_to_target_with_forced_retry(session_browser):
)
)

browser.element('#target1').element('#draggable').should(be.not_.present)
browser.element('#target2').element('#draggable').should(be.present)
browser.element('#target1').element('#draggable').should(be.not_.present_in_dom)
browser.element('#target2').element('#draggable').should(be.present_in_dom)


class ReactContinuousSlider:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ def test_js_drags_source_and_drops_it_to_target(session_browser):
command.js.drag_and_drop_to(browser.element('#target2'))
)

browser.element('#target1').element('#draggable').should(be.not_.present)
browser.element('#target2').element('#draggable').should(be.present)
browser.element('#target1').element('#draggable').should(be.not_.present_in_dom)
browser.element('#target2').element('#draggable').should(be.present_in_dom)

# WHEN
browser.element('#draggable').perform(
command.js.drag_and_drop_to(browser.element('#target1'))
)

browser.element('#target1').element('#draggable').should(be.present)
browser.element('#target2').element('#draggable').should(be.not_.present)
browser.element('#target1').element('#draggable').should(be.present_in_dom)
browser.element('#target2').element('#draggable').should(be.not_.present_in_dom)


class ReactContinuousSlider:
Expand Down

0 comments on commit 1f26eb2

Please sign in to comment.