/capybara/queries/sibling_query.py

https://github.com/elliterate/capybara.py
Python | 32 lines | 23 code | 9 blank | 0 comment | 1 complexity | e2c247c2743dc49009b12d0fe5111dd2 MD5 | raw file
  1. from xpath import dsl as x
  2. from xpath.renderer import to_xpath
  3. from capybara.queries.selector_query import SelectorQuery
  4. from capybara.result import Result
  5. class SiblingQuery(SelectorQuery):
  6. def resolve_for(self, node, exact=None):
  7. setattr(self, "_resolved_node", node)
  8. @node.synchronize()
  9. def resolve():
  10. match_result = super(type(self), self).resolve_for(
  11. node.session.current_scope, exact=exact)
  12. return node.find_all(
  13. "xpath", to_xpath(x.preceding_sibling().union(x.following_sibling())),
  14. filter=lambda el: el in match_result)
  15. return resolve()
  16. @property
  17. def description(self):
  18. description = super(type(self), self).description
  19. resolved_node = getattr(self, "_resolved_node", None)
  20. child_query = getattr(resolved_node, "query", None)
  21. if child_query:
  22. description += " that is a sibling of {}".format(child_query.description)
  23. return description