Skip to content

Commit

Permalink
[#530] REFACTOR: rename match.text to match.text_containing...
Browse files Browse the repository at this point in the history
... to improve readability in context of match.* phrasing
  • Loading branch information
yashaka committed Jul 15, 2024
1 parent 4835b8a commit c4389ac
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ should we even refactor out them from Condition and move to Match only?

### TODO: rename all conditions inside match.py so match can be fully used instead be + have #530

### TODO: is text + exact_text naming still relevant for match.* case over have.*?

### Deprecated conditions

- `be.present` in favor of `be.present_in_dom`
Expand Down
45 changes: 33 additions & 12 deletions selene/core/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,39 @@ def __x_exact_text(expected: str | int | float, _ignore_case=False, _inverted=Fa
)


def text(expected: str | int | float, _ignore_case=False, _inverted=False):
# todo: is text + exact_text naming still relevant for match.* case over have.*?
# let's compare examples:
# > element.should(have.exact_text('full of partial!')) # 👍🏻
# > element.should(have.text('partial')) # 👍🏻
# > element.should(match.exact_text('full of partial!')) # 👍🏻
# > element.should(match.text('part')) # 🤨
# > element.should(match.text_containing('part')) # 🤔
# > element.should(match.partial_text('part')) # 👍🏻
# > match.text('part')(element) # 🤨
# > match.text_containing('part')(element) # ??
# > match.partial_text('part')(element) # 👍🏻
# let's see other conditions
# > element.should(have.value('full of partial!')) # 👍🏻
# > element.should(have.value_containing('part')) # 👍🏻
# > element.should(match.value('full of partial!')) # 👍🏻
# > element.should(match.value_containing('part')) # 👍🏻
# > element.should(match.partial_value('part')) # 👍🏻?
# > browser.should(match.url_containing('part')) # 👍🏻
# > browser.should(match.partial_url('part')) # 👍🏻?
# > match.url_containing('part')(browser) # 👍🏻
# > match.partial_url('part')(browser) # 👍🏻?
# Hm... There is something weird in "match.partial_*('part')" ...
# it's conciser but less consistent with have.*_containing
# and maybe it's subjective, but partial_ phrasing sounds
# less natural for me... from human-language perspective
# Hence, let's keep things simple and consistent.
# match.text is really a problem. Not others.
# So let's rename only it and rename only to the most consistent
# with other versions... i.e. to text_containing
# Let's not do anything else. For example,
# we could rename match.exact_text to match.text, but again,
# let's keep consistency with have.* as much as possible
def text_containing(expected: str | int | float, _ignore_case=False, _inverted=False):
return _EntityHasSomethingSupportingIgnoreCase(
'has text', # TODO: is it here name or description? probably it's even a "name prefix"
expected,
Expand All @@ -391,17 +423,6 @@ def text(expected: str | int | float, _ignore_case=False, _inverted=False):
)


# TODO: is text + exact_text naming still relevant for match.* case over have.*?
# let's compare examples:
# > element.should(have.exact_text('full of partial!')) # 👍🏻
# > element.should(have.text('partial')) # 👍🏻
# > element.should(match.exact_text('full of partial!')) # 👍🏻
# > element.should(match.text('partial')) # 🤨
# > element.should(match.text_containing('partial')) # 🤔
# > element.should(match.partial_text('partial')) # 👍🏻
# > match.text('partial')(element) # 🤨
# > match.text_containing('partial')(element) # ??
# > match.partial_text('partial')(element) # 👍🏻
def exact_text(expected: str | int | float, _ignore_case=False, _inverted=False):
return _EntityHasSomethingSupportingIgnoreCase(
'has exact text',
Expand Down
2 changes: 1 addition & 1 deletion selene/support/conditions/have.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def exact_text(value: str | int | float):


def text(partial_value: str | int | float):
return match.text(partial_value)
return match.text_containing(partial_value)


# todo: why not exact_text_matching o_O?
Expand Down
2 changes: 1 addition & 1 deletion selene/support/conditions/not_.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def exact_text(value: str | int | float):


def text(partial_value: str | int | float):
return _match.text(partial_value, _inverted=True)
return _match.text_containing(partial_value, _inverted=True)


def text_matching(regex_pattern: str):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,13 @@ def test_text_matching__regex_pattern__ignore_case__compared(session_browser):
browser.all('li').first.should(match.exact_text('1) one!!!').not_) # TODO: o_O
browser.all('li').first.should(have.no.exact_text('1) one!!!'))
browser.all('li').first.should(match.exact_text('1) one!!!', _ignore_case=True))
browser.all('li').first.with_(_ignore_case=True).should(
match.exact_text('1) one!!!')
)
browser.all('li').first.should(have.exact_text('1) one!!!').ignore_case)
browser.all('li').first.should(match.text('one', _ignore_case=True))
browser.all('li').first.should(match.text_containing('one', _ignore_case=True))
browser.all('li').first.should(have.text('one').ignore_case)
browser.all('li').first.with_(_ignore_case=True).should(have.text('one'))
browser.all('li').first.should(match.text_pattern(r'.*one.*', _flags=re.IGNORECASE))
browser.all('li').first.should(match.text_pattern(r'.*one.*').not_)
browser.all('li').first.should(
Expand Down

0 comments on commit c4389ac

Please sign in to comment.