From 84aad742781fd7eea7a075154ba204afa4d1e2bf Mon Sep 17 00:00:00 2001 From: micha91 Date: Thu, 21 Nov 2024 09:55:39 +0100 Subject: [PATCH] chore: Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ernst Würger --- tests/test_documents.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/tests/test_documents.py b/tests/test_documents.py index d67ae4e..2743b34 100644 --- a/tests/test_documents.py +++ b/tests/test_documents.py @@ -317,16 +317,15 @@ def test_mixed_authority_with_work_item( ), ) - def _find_links(content: list[etree._Element]): - links: list[str] = [] + def _find_links(content: list[etree._Element]) -> list[etree._Element]: + links: list[etree._Element] = [] for el in content: - if el.tag == "p": - for e in el.getchildren(): - if ( - e.tag == "span" - and e.get("class") == "polarion-rte-link" - ): - links.append(e) + if el.tag != "p": + continue + + for e in el: + if e.tag == "span" and e.get("class") == "polarion-rte-link": + links.append(e) return links @@ -344,14 +343,13 @@ def _find_links(content: list[etree._Element]): content: list[etree._Element] = html.fromstring( document_data.document.home_page_content.value ) - wis = list( - filter( - lambda el: el.tag == "div" - and el.get("id") == "polarion_wiki macro name=module-workitem;" - "params=id=ATSY-1234|layout=0|external=true", - content, - ) + target_id = ( + "polarion_wiki macro name=module-workitem;" + "params=id=ATSY-1234|layout=0|external=true" ) + wis = [ + el for el in content if el.tag == "div" and el.get("id") == target_id + ] wi_links = _find_links(content) assert len(wis) == 1