Open
Description
we see a test failure when MechanicalSoup is built using lxml 5.4.0 and libxml2 2.14.3, as in
https://autopkgtest.ubuntu.com/packages/p/python-mechanicalsoup/questing/amd64
The test passes whith an older libxml2 2.9.14.
77s =================================== FAILURES ===================================
77s _____________________ test_select_form_associated_elements _____________________
77s
77s def test_select_form_associated_elements():
77s """Test associated elements outside the form tag"""
77s forms = """<form id="a"><input><textarea></form><input form="a">
77s <textarea form="a"/><input form="b">
77s <form id="ab" action="/test.php"><input></form>
77s <textarea form="ab"></textarea>
77s """
77s with mechanicalsoup.StatefulBrowser() as browser:
77s browser.open_fake_page(forms)
77s elements_form_a = set([
77s "<input/>", "<textarea></textarea>",
77s '<input form="a"/>', '<textarea form="a"></textarea>'])
77s elements_form_ab = set(["<input/>", '<textarea form="ab"></textarea>'])
77s form_by_str = browser.select_form("#a")
77s form_by_tag = browser.select_form(browser.page.find("form", id='a'))
77s > form_by_css = browser.select_form("form[action$='.php']")
77s
77s tests/test_stateful_browser.py:514:
77s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
77s
77s self = <mechanicalsoup.stateful_browser.StatefulBrowser object at 0x711909fe4050>
77s selector = "form[action$='.php']", nr = 0
77s
77s def select_form(self, selector="form", nr=0):
77s """Select a form in the current page.
77s
77s :param selector: CSS selector or a bs4.element.Tag object to identify
77s the form to select.
77s If not specified, ``selector`` defaults to "form", which is
77s useful if, e.g., there is only one form on the page.
77s For ``selector`` syntax, see the `.select() method in BeautifulSoup
77s <https://www.crummy.com/software/BeautifulSoup/bs4/doc/#css-selectors>`__.
77s :param nr: A zero-based index specifying which form among those that
77s match ``selector`` will be selected. Useful when one or more forms
77s have the same attributes as the form you want to select, and its
77s position on the page is the only way to uniquely identify it.
77s Default is the first matching form (``nr=0``).
77s
77s :return: The selected form as a soup object. It can also be
77s retrieved later with the :attr:`form` attribute.
77s """
77s
77s def find_associated_elements(form_id):
77s """Find all elements associated to a form
77s (i.e. an element with a form attribute -> ``form=form_id``)
77s """
77s
77s # Elements which can have a form owner
77s elements_with_owner_form = ("input", "button", "fieldset",
77s "object", "output", "select",
77s "textarea")
77s
77s found_elements = []
77s
77s for element in elements_with_owner_form:
77s found_elements.extend(
77s self.page.find_all(element, form=form_id)
77s )
77s return found_elements
77s
77s if isinstance(selector, bs4.element.Tag):
77s if selector.name != "form":
77s raise LinkNotFoundError
77s form = selector
77s else:
77s # nr is a 0-based index for consistency with mechanize
77s found_forms = self.page.select(selector,
77s limit=nr + 1)
77s if len(found_forms) != nr + 1:
77s if self.__debug:
77s print('select_form failed for', selector)
77s self.launch_browser()
77s > raise LinkNotFoundError()
77s E mechanicalsoup.utils.LinkNotFoundError
77s
77s /usr/lib/python3/dist-packages/mechanicalsoup/stateful_browser.py:241: LinkNotFoundError
77s =========================== short test summary info ============================
77s FAILED tests/test_stateful_browser.py::test_select_form_associated_elements
77s ================= 1 failed, 112 passed, 8 deselected in 1.08s ==================
Metadata
Metadata
Assignees
Labels
No labels