Skip to content

Commit fb5169b

Browse files
committed
Add test to ensure xml-model PI is excluded from output
Introduces a test verifying that xml-model processing instructions are not present in the output after pruning. Also updates macro search to use the _tag helper for consistency.
1 parent 38704d8 commit fb5169b

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

tests/test_prune.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from style_variant_builder.prune import NS, CSLPruner
1+
from style_variant_builder.prune import CSLPruner, _tag
22

33
EXAMPLE_XML = """<?xml version="1.0"?>
44
<style xmlns="http://purl.org/net/xbiblio/csl">
@@ -12,6 +12,18 @@
1212
</style>
1313
"""
1414

15+
EXAMPLE_WITH_XML_MODEL = """<?xml version="1.0"?>
16+
<?xml-model href="http://example.com/schema.rng" type="application/xml"?>
17+
<style xmlns="http://purl.org/net/xbiblio/csl">
18+
<macro name="test-macro"><text value="test"/></macro>
19+
<citation>
20+
<layout>
21+
<text macro="test-macro"/>
22+
</layout>
23+
</citation>
24+
</style>
25+
"""
26+
1527

1628
def test_prune_removes_unused_macros(tmp_path):
1729
xml_path = tmp_path / "test.csl"
@@ -22,7 +34,7 @@ def test_prune_removes_unused_macros(tmp_path):
2234
pruner.build_used_macros()
2335
pruner.prune_macros()
2436
assert pruner.root is not None
25-
macros = [m.get("name") for m in pruner.root.findall(f"{NS}macro")]
37+
macros = [m.get("name") for m in pruner.root.findall(_tag("macro"))]
2638
assert "used-macro" in macros
2739
assert "unused-macro" not in macros
2840

@@ -36,5 +48,24 @@ def test_prune_keeps_used_macros(tmp_path):
3648
pruner.build_used_macros()
3749
pruner.prune_macros()
3850
assert pruner.root is not None
39-
macros = [m.get("name") for m in pruner.root.findall(f"{NS}macro")]
51+
macros = [m.get("name") for m in pruner.root.findall(_tag("macro"))]
4052
assert "used-macro" in macros
53+
54+
55+
def test_xml_model_pi_excluded_from_output(tmp_path):
56+
"""Test that xml-model processing instructions are excluded from saved output."""
57+
input_path = tmp_path / "input.csl"
58+
output_path = tmp_path / "output.csl"
59+
input_path.write_text(EXAMPLE_WITH_XML_MODEL)
60+
61+
pruner = CSLPruner(input_path, output_path)
62+
pruner.parse_xml()
63+
pruner.prune_macros()
64+
pruner.save()
65+
66+
output_content = output_path.read_text()
67+
# Verify xml-model PI is not in output
68+
assert "<?xml-model" not in output_content
69+
# Verify the actual content is preserved
70+
assert "<macro" in output_content
71+
assert "<citation>" in output_content

0 commit comments

Comments
 (0)