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

fix color bug in svg template #20

Merged
merged 4 commits into from
Sep 21, 2021
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
4 changes: 2 additions & 2 deletions genbadge/badge-template.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions genbadge/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,52 @@ def test_genbadge(tmpdir, use_shields):
svgtxt = f.read()
assert standardize_xml("\n" + svgtxt) == standardize_xml(refsvg_str)

@pytest.mark.parametrize("use_shields", [False], # TODO True but the contents are slightly different
ids="use_shields={}".format)
def test_genbadge_red(tmpdir, use_shields):
smarie marked this conversation as resolved.
Show resolved Hide resolved
"""Test that the `Badge` class works as expected"""

b = Badge(left_txt="verytring", right_txt="1XYZ", color="red")

# Console representation
assert repr(b) == "[ verytring | 1XYZ ] color: red"

# SVG representation
if platform.system() == "Windows" or LooseVersion(PIL.__version__) < "8.0":
ref_nbs = dict(left_width=63, right_width=41, tot_width=104, left_x=325.0, left_txt_length=530, right_x=825.0, right_txt_length=310)
else:
ref_nbs = dict(left_width=61, right_width=39, tot_width=100, left_x=315.0, left_txt_length=510, right_x=795.0, right_txt_length=290)

refsvg_str = """
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="{tot_width}" height="20" role="img" aria-label="verytring: 1XYZ">
<title>verytring: 1XYZ</title>
<linearGradient id="s" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
<stop offset="1" stop-opacity=".1"/>
</linearGradient>
<clipPath id="r">
<rect width="{tot_width}" height="20" rx="3" fill="#fff"/>
</clipPath>
<g clip-path="url(#r)">
<rect width="{left_width}" height="20" fill="#555"/>
<rect x="{left_width}" width="{right_width}" height="20" fill="#e05d44"/>
<rect width="{tot_width}" height="20" fill="url(#s)"/>
</g>
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110">
<text aria-hidden="true" x="{left_x}" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="{left_txt_length}">verytring</text>
<text x="{left_x}" y="140" transform="scale(.1)" fill="#fff" textLength="{left_txt_length}">verytring</text>
<text aria-hidden="true" x="{right_x}" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="{right_txt_length}">1XYZ</text>
<text x="{right_x}" y="140" transform="scale(.1)" fill="#fff" textLength="{right_txt_length}">1XYZ</text>
</g>
</svg>""".format(**ref_nbs) # noqa
assert standardize_xml("\n" + b.as_svg(use_shields=use_shields)) == standardize_xml(refsvg_str)

# Write to file
b.write_to(str(tmpdir / "tmp_badge.svg"), use_shields=use_shields)
with open(str(tmpdir / "tmp_badge.svg"), mode="rt") as f:
svgtxt = f.read()
assert standardize_xml("\n" + svgtxt) == standardize_xml(refsvg_str)


def standardize_xml(xmltxt):
import xml.dom.minidom
Expand Down
2 changes: 1 addition & 1 deletion genbadge/utils_badge.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

COLORS = {
'brightgreen': '#4c1',
'green': '#97CA00',
'green': '#97ca00',
'yellowgreen': '#a4a61d',
'yellow': '#dfb317',
'orange': '#fe7d37',
Expand Down