Skip to content

Commit

Permalink
xml input: Ensure namespaces don't break sheet titles
Browse files Browse the repository at this point in the history
Namespaces contain colons which aren't permitted in Excel sheet names.
  • Loading branch information
Bjwebb committed Aug 20, 2024
1 parent 3cd3ed4 commit c933ad0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion flattentool/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def make_sub_sheet_name(
x[:truncation_length] for x in parent_path.split(path_separator) if x != "0"
)
+ property_name
)
).replace(":", "-")


class TitleLookup(UserDict):
Expand Down
16 changes: 16 additions & 0 deletions flattentool/tests/fixtures/iati_namespaces.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version='1.0' encoding='utf-8'?>
<iati-activities xmlns:customns="http://example.com/2">
<!--XML generated by flatten-tool-->
<iati-activity xmlns:customns="http://example.com/1" last-updated-datetime="2011-10-01T00:00:00+00:00">
<customns:test>
<customns:part>two</customns:part>
<customns:part>two</customns:part>
</customns:test>
</iati-activity>
<iati-activity last-updated-datetime="2016-01-01T00:00:00+00:00">
<customns:test>
<customns:part>three</customns:part>
<customns:part>four</customns:part>
</customns:test>
</iati-activity>
</iati-activities>
12 changes: 11 additions & 1 deletion flattentool/tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import pytest

from flattentool import decimal_datetime_default, unflatten
from flattentool import decimal_datetime_default, flatten, unflatten


def original_cell_and_row_locations(data):
Expand Down Expand Up @@ -1452,3 +1452,13 @@ def test_commands_id_name(tmpdir, input_format):
],
"some": "data",
}


def test_flatten_xml(tmpdir):
flatten(
"flattentool/tests/fixtures/iati_namespaces.xml",
output_name=tmpdir.join("flattened_xml").strpath,
id_name="iati-identifier",
root_list_path="iati-activity",
xml=True,
)

0 comments on commit c933ad0

Please sign in to comment.