Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
realtimeprojects committed Oct 24, 2023
1 parent 9f8e48b commit 3f3a66d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/yaxp/_xpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ def _add_filter(self, **kwargs):
if wildcard:
filter += f'[contains({arg}, "{value}")]'
elif value[0] == "*":
filter += f'[{arg}[contains(., "{value[1:]}")]]'
if arg == ".":
filter += f'[contains(., "{value[1:]}")]'
else:
filter += f'[{arg}[contains(., "{value[1:]}")]]'
elif value[0] == "#":
filter += f'[contains(concat(" ", normalize-space({arg}), " "), " {value[1:]} ")]'
else:
Expand Down
10 changes: 5 additions & 5 deletions tests/test_xpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@
(xp.by(_id="huhu"), '//*[@id="huhu"]'),

# partial-match specification
(xp.span(_id="*huhu"), '//span[contains(@id, "huhu")]'),
(xp.span.contains(_id="huhu"), '//span[contains(@id, "huhu")]'),
(xp.span(_id="*huhu"), '//span[@id[contains(., "huhu")]]'),
(xp.span.contains(_id="huhu"), '//span[@id[contains(., "huhu")]]'),

# text match exactly
(xp.span(text="Hello"), '//span[text()="Hello"]'),

# text match exactly
(xp.span(text="*Hello3"), '//span[contains(text(), "Hello3")]'),
(xp.span(text="*Hello3"), '//span[text()[contains(., "Hello3")]]'),

# text attribute match
(xp.span(_text="Hello2"), '//span[@text="Hello2"]'),

# text attribute match
(xp.span(_text="*Hello4"), '//span[contains(@text, "Hello4")]'),
(xp.span(_text="*Hello4"), '//span[@text[contains(., "Hello4")]]'),

# text match partial
(xp.span(_="*World"), '//span[contains(., "World")]'),
Expand All @@ -39,7 +39,7 @@
(xp.span(_="World"), '//span[.="World"]'),

# text match partial
(xp.span(_id="myid").contains(_="Hello", _class="myclass"), '//span[@id="myid"][contains(., "Hello")][contains(@class, "myclass")]'),
(xp.span(_id="myid").contains(_="Hello", _class="myclass"), '//span[@id="myid"][contains(., "Hello")][@class[contains(., "myclass")]]'),

# word-match specification
(xp.div(_class="#part"), '//div[contains(concat(" ", normalize-space(@class), " "), " part ")]'),
Expand Down

0 comments on commit 3f3a66d

Please sign in to comment.