From b6538740e93803c3fd9c331f9ce6a91df3e5faec Mon Sep 17 00:00:00 2001 From: KaifAhmad1 Date: Tue, 8 Sep 2026 12:47:26 +0530 Subject: [PATCH] fix(tests): guard lxml-specific assertions in slim-core comment tests test_xml_parser_handles_comments and test_public_api_ingestor_handles_xml_comments called XMLParser(engine="lxml") / forced the lxml fallback path unconditionally, but the core-only CI step installs from base-deps.txt, which no longer bundles lxml or defusedxml under this PR's slim dependency layout. Skip the lxml-only assertions when lxml/defusedxml aren't installed, while still exercising the always-available etree path. Co-Authored-By: Claude Sonnet 5 --- tests/test_issue_1513_slim_core.py | 35 ++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/tests/test_issue_1513_slim_core.py b/tests/test_issue_1513_slim_core.py index f4de58a3..e617ac06 100644 --- a/tests/test_issue_1513_slim_core.py +++ b/tests/test_issue_1513_slim_core.py @@ -369,19 +369,13 @@ def test_spacy_load_missing_hint(): def test_xml_parser_handles_comments(): + from semantica.parse.xml_parser import etree as real_lxml_etree + xml_content = ( "Value" "" ) - # lxml engine - p_lxml = XMLParser(engine="lxml") - res_lxml = p_lxml.parse(xml_content) - assert res_lxml.root.tag == "root" - assert len(res_lxml.root.children) == 1 - assert res_lxml.root.children[0].tag == "item" - assert res_lxml.root.children[0].text == "Value" - - # etree engine + # etree engine (always available in a core-only install) p_etree = XMLParser(engine="etree") res_etree = p_etree.parse(xml_content) assert res_etree.root.tag == "root" @@ -389,9 +383,26 @@ def test_xml_parser_handles_comments(): assert res_etree.root.children[0].tag == "item" assert res_etree.root.children[0].text == "Value" + # lxml engine (only meaningful when the 'documents' extra is installed) + if real_lxml_etree is None: + pytest.skip("lxml not installed (requires semantica[documents])") + p_lxml = XMLParser(engine="lxml") + res_lxml = p_lxml.parse(xml_content) + assert res_lxml.root.tag == "root" + assert len(res_lxml.root.children) == 1 + assert res_lxml.root.children[0].tag == "item" + assert res_lxml.root.children[0].text == "Value" + def test_public_api_ingestor_handles_xml_comments(): - from semantica.ingest.public_api_ingestor import PublicAPIIngestor + from semantica.ingest.public_api_ingestor import ( + PublicAPIIngestor, + lxml_etree as real_lxml_etree, + safe_xml_etree as real_safe_xml_etree, + ) + + if real_lxml_etree is None and real_safe_xml_etree is None: + pytest.skip("neither defusedxml nor lxml installed (requires semantica[documents]/[explorer])") xml_content = "Value" ingestor = PublicAPIIngestor(rate_limit_delay=0) @@ -403,7 +414,9 @@ def test_public_api_ingestor_handles_xml_comments(): assert parsed["children"][0]["tag"] == "item" assert parsed["children"][0]["text"] == "Value" - # 2. lxml fallback + # 2. lxml fallback (only meaningful when lxml is actually installed) + if real_lxml_etree is None: + pytest.skip("lxml not installed (requires semantica[documents])") with patch("semantica.ingest.public_api_ingestor.safe_xml_etree", None): parsed_lxml = ingestor._parse_xml(xml_content) assert parsed_lxml["tag"] == "root"