Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always create description tag #372

Merged
merged 4 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/lib/appdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,23 @@ def add_release(
releases.insert(0, release)
_fill_padding(release)

description = ElementTree.Element("description")

# Give <description> a closing </description> rather than it being
# self-closing
description.text = ""

# Indent the opening <description> tag one level
# deeper than the <release> tag.
if releases.text:
release.text = "\n" + ((releases.text[1::2]) * 3)

# Indent the closing </release> tag by the same amount as the opening
# <release> tag (which we know to be the first child of <releases> since
# we just prepended it above)
description.tail = releases.text
release.append(description)

tree.write(
dst,
# XXX: lxml uses single quotes for doctype line if generated with
Expand Down
113 changes: 103 additions & 10 deletions tests/test_appdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,90 @@ def test_simple(self):
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop">
<releases>
<release version="4.5.6" date="2020-02-02"/>
<release version="4.5.6" date="2020-02-02">
<description></description>
</release>
<release version="1.2.3" date="2019-01-01"/>
</releases>
</component>
""".strip(),
)

@unittest.expectedFailure
def test_four_space_no_releases_element(self):
# FIXME: This ends up indenting <releases> correctly, but
# <release> and <description> incorrectly get the default 2-space
Comment on lines +60 to +61
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I'd forgotten about this one. I think it's such an edge case that we can accept the failure for now.

# indent.
self._do_test(
"""
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop">
<id>com.example.Workaround</id>
<name>My history is a mystery</name>
</component>
""".strip(),
"""
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop">
<id>com.example.Workaround</id>
<name>My history is a mystery</name>
<releases>
<release version="4.5.6" date="2020-02-02">
<description></description>
</release>
</releases>
</component>
""".strip(),
)

def test_four_space_one_prior_release(self):
self._do_test(
"""
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop">
<releases>
<release version="1.2.3" date="2019-01-01"/>
</releases>
</component>
""".strip(),
"""
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop">
<releases>
<release version="4.5.6" date="2020-02-02">
<description></description>
</release>
<release version="1.2.3" date="2019-01-01"/>
</releases>
</component>
""".strip(),
)

def test_four_space_many_prior_releases(self):
self._do_test(
"""
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop">
<releases>
<release version="1.2.3" date="2019-01-01"/>
<release version="1.1.2" date="2018-01-01"/>
</releases>
</component>
""".strip(),
"""
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop">
<releases>
<release version="4.5.6" date="2020-02-02">
<description></description>
</release>
<release version="1.2.3" date="2019-01-01"/>
<release version="1.1.2" date="2018-01-01"/>
</releases>
</component>
""".strip(),
)

def test_mixed_indentation(self):
"""This input uses 3-space indentation for one existing <release> and 4-space
for another. Match the top one."""
Expand All @@ -70,7 +147,9 @@ def test_mixed_indentation(self):
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop">
<releases>
<release version="4.5.6" date="2020-02-02"/>
<release version="4.5.6" date="2020-02-02">
<description></description>
</release>
<release version="1.2.3" date="2019-01-01"/>
<release version="1.2.3" date="2019-01-01"/>
</releases>
Expand Down Expand Up @@ -119,7 +198,9 @@ def test_comment(self):
<component type="desktop">
<!-- I am the walrus -->
<releases>
<release version="4.5.6" date="2020-02-02"/>
<release version="4.5.6" date="2020-02-02">
<description></description>
</release>
<release version="1.2.3" date="2019-01-01"/>
</releases>
</component>
Expand All @@ -137,14 +218,16 @@ def test_no_releases(self):
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop">
<releases>
<release version="4.5.6" date="2020-02-02"/>
<release version="4.5.6" date="2020-02-02">
<description></description>
</release>
</releases>
</component>
""".strip(),
)

def test_empty_releases(self):
"""No whitespace is generated between <release /> and </releases>."""
"""No whitespace is generated between </release> and </releases>."""
self._do_test(
"""
<?xml version="1.0" encoding="UTF-8"?>
Expand All @@ -156,7 +239,9 @@ def test_empty_releases(self):
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop">
<releases>
<release version="4.5.6" date="2020-02-02"/>
<release version="4.5.6" date="2020-02-02">
<description></description>
</release>
</releases>
</component>
""".strip(),
Expand Down Expand Up @@ -186,7 +271,9 @@ def test_double_comment_within_root(self):
-->
<name>First element needed</name>
<releases>
<release version="4.5.6" date="2020-02-02"/>
<release version="4.5.6" date="2020-02-02">
<description></description>
</release>
</releases>
</application>
""".strip(),
Expand Down Expand Up @@ -219,7 +306,9 @@ def test_comment_outside_root(self):
-->
<application>
<releases>
<release version="4.5.6" date="2020-02-02"/>
<release version="4.5.6" date="2020-02-02">
<description></description>
</release>
</releases>
</application>
""".strip(),
Expand All @@ -238,7 +327,9 @@ def test_amp_as_amp(self):
<component type="desktop">
<name>🍦 &amp; 🎂</name>
<releases>
<release version="4.5.6" date="2020-02-02"/>
<release version="4.5.6" date="2020-02-02">
<description></description>
</release>
</releases>
</component>
""".strip(),
Expand All @@ -259,7 +350,9 @@ def test_amp_as_codepoint(self):
<component type="desktop">
<name>🦝 &#38; 🍒</name>
<releases>
<release version="4.5.6" date="2020-02-02"/>
<release version="4.5.6" date="2020-02-02">
<description></description>
</release>
</releases>
</component>
""".strip(),
Expand Down
Loading