-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: prevent processing errors from empty XML tags
Create helper function to remove empty XML tags to avoid unexpected behavior when processing elements like keywords in `workbook.get_description`.
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""Test utilities module""" | ||
|
||
from lxml import etree | ||
from spinneret import datasets | ||
from spinneret.utilities import delete_empty_tags | ||
|
||
|
||
def test_delete_empty_tags(): | ||
"""Test that empty tags are removed from an XML file""" | ||
|
||
# Read test file | ||
eml_file = datasets.get_example_eml_dir() + "/" + "edi.3.9.xml" | ||
eml = etree.parse(eml_file) | ||
|
||
# Add an empty tag to the XML and check that it is added | ||
# to the XML | ||
empty_tag = etree.Element("empty_tag") | ||
eml.getroot().append(empty_tag) | ||
assert len(eml.xpath(".//empty_tag")) == 1 | ||
|
||
# Remove empty tags | ||
eml = delete_empty_tags(eml) | ||
|
||
# Check that the empty tag has been removed | ||
assert len(eml.xpath(".//empty_tag")) == 0 |