-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Inclusion of new NAMED_COLORS for MS Excel #18392
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,9 @@ | |
""" | ||
|
||
import pytest | ||
import pandas.util.testing as tm | ||
|
||
from warnings import catch_warnings | ||
from pandas.io.formats.excel import CSSToExcelConverter | ||
|
||
|
||
|
@@ -212,3 +214,61 @@ def test_css_to_excel_multiple(): | |
def test_css_to_excel_inherited(css, inherited, expected): | ||
convert = CSSToExcelConverter(inherited) | ||
assert expected == convert(css) | ||
|
||
|
||
@pytest.mark.parametrize("input_color,output_color", ( | ||
[(name, rgb) for name, rgb in CSSToExcelConverter.NAMED_COLORS.items()] + | ||
[("#" + rgb, rgb) for rgb in CSSToExcelConverter.NAMED_COLORS.values()] + | ||
[("#F0F", "FF00FF"), ("#ABC", "AABBCC")]) | ||
) | ||
def test_css_to_excel_good_colors(input_color, output_color): | ||
# see gh-18392 | ||
css = ("border-top-color: {color}; " | ||
"border-right-color: {color}; " | ||
"border-bottom-color: {color}; " | ||
"border-left-color: {color}; " | ||
"background-color: {color}; " | ||
"color: {color}").format(color=input_color) | ||
|
||
expected = dict() | ||
|
||
expected["fill"] = { | ||
"patternType": "solid", | ||
"fgColor": output_color | ||
} | ||
|
||
expected["font"] = { | ||
"color": output_color | ||
} | ||
|
||
expected["border"] = { | ||
k: { | ||
"color": output_color, | ||
} for k in ("top", "right", "bottom", "left") | ||
} | ||
|
||
with tm.assert_produces_warning(None): | ||
convert = CSSToExcelConverter() | ||
assert expected == convert(css) | ||
|
||
|
||
@pytest.mark.parametrize("input_color", [None, "not-a-color"]) | ||
def test_css_to_excel_bad_colors(input_color): | ||
# see gh-18392 | ||
css = ("border-top-color: {color}; " | ||
"border-right-color: {color}; " | ||
"border-bottom-color: {color}; " | ||
"border-left-color: {color}; " | ||
"background-color: {color}; " | ||
"color: {color}").format(color=input_color) | ||
|
||
expected = dict() | ||
|
||
if input_color is not None: | ||
expected["fill"] = { | ||
"patternType": "solid" | ||
} | ||
|
||
with catch_warnings(record=True): | ||
convert = CSSToExcelConverter() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so these don't actually raise? rather just show a warning? ok I guess There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so we aren't actually testing anything then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note - I don't think they should raise as that puts a burden back on us. is it possible to check the warnings message? (note don't spend too much time on this, if its easy do it). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jreback : When I call |
||
assert expected == convert(css) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so these don't actually raise? rather just show a warning? ok I guess