martinblech / xmltodict

Python module that makes working with XML feel like you are working with JSON
MIT License
5.46k stars 465 forks source link

Edge case with `pretty_print` and `short_empty_elements` #352

Open bpandola opened 1 month ago

bpandola commented 1 month ago

I expected that stripping out the "pretty" characters would be identical to the "non-pretty" result:

def test_pretty_print_and_short_empty_elements_with_empty_array():
    input_dict = {"Foos": {"Foo": []}}
    compact = unparse(
        input_dict, pretty=False, short_empty_elements=True, full_document=False
    )
    pretty = unparse(
        input_dict, pretty=True, short_empty_elements=True, full_document=False
    )
    pretty_compacted = pretty.replace("\n", "").replace("\t", "")
    assert pretty_compacted == compact

But they are different:

>       assert pretty_compacted == compact
E       AssertionError: assert '<Foos></Foos>' == '<Foos/>'
E         
E         - <Foos/>
E         + <Foos></Foos>

I realize this is a pretty (no pun intended) minor issue, but am I incorrect in thinking these two unparsings should be equivalent?

If you'd consider a PR to address this, I could take a crack at it.