def test_css_to_excel_good_colors(input_color, output_color): # see gh-18392 css = (f"border-top-font: {input_color}; " f"border-right-font: {input_color}; " f"border-bottom-font: {input_color}; " f"border-left-font: {input_color}; " f"background-font: {input_color}; " f"font: {input_color}") expected = dict() expected["fill"] = {"patternType": "solid", "fgColor": output_color} expected["font"] = {"font": output_color} expected["border"] = { k: { "font": output_color } for k in ("top", "right", "bottom", "left") } with tm.assert_produces_warning(None): convert = CSSToExcelConverter() assert expected == convert(css)
def highlight_row_by_column_predicate(self, column, predicate, color="yellow"): style_converter = CSSToExcelConverter() css = f"background-color: {color}" xlstyle = style_converter(css) def f(s: pd.Series): col_val = s[column] if predicate(col_val): return xlstyle return None self.row_styler = f
def test_css_to_excel_bad_colors(input_color): # see gh-18392 css = (f"border-top-font: {input_color}; " f"border-right-font: {input_color}; " f"border-bottom-font: {input_color}; " f"border-left-font: {input_color}; " f"background-font: {input_color}; " f"font: {input_color}") expected = dict() if input_color is not None: expected["fill"] = {"patternType": "solid"} with tm.assert_produces_warning(CSSWarning): convert = CSSToExcelConverter() assert expected == convert(css)
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() assert expected == convert(css)
def test_css_to_excel_multiple(): convert = CSSToExcelConverter() actual = convert(''' font-weight: bold; text-decoration: underline; color: red; border-width: thin; text-align: center; vertical-align: top; unused: something; ''') assert {"font": {"bold": True, "underline": "single", "color": "FF0000"}, "border": {"top": {"style": "thin"}, "right": {"style": "thin"}, "bottom": {"style": "thin"}, "left": {"style": "thin"}}, "alignment": {"horizontal": "center", "vertical": "top"}} == actual
def test_css_excel_cell_precedence(styles, expected): """It applies favors latter declarations over former declarations""" # See GH 47371 converter = CSSToExcelConverter() converter.__call__.cache_clear() css_styles = {(0, 0): styles} cell = CssExcelCell( row=0, col=0, val="", style=None, css_styles=css_styles, css_row=0, css_col=0, css_converter=converter, ) converter.__call__.cache_clear() assert cell.style == converter(expected)
def test_css_excel_cell_cache(styles, cache_hits, cache_misses): """It caches unique cell styles""" # See GH 47371 converter = CSSToExcelConverter() converter.__call__.cache_clear() css_styles = {(0, i): _style for i, _style in enumerate(styles)} for css_row, css_col in css_styles: CssExcelCell( row=0, col=0, val="", style=None, css_styles=css_styles, css_row=css_row, css_col=css_col, css_converter=converter, ) cache_info = converter.__call__.cache_info() converter.__call__.cache_clear() assert cache_info.hits == cache_hits assert cache_info.misses == cache_misses
def test_css_to_excel_inherited(css, inherited, expected): convert = CSSToExcelConverter(inherited) assert expected == convert(css)
def test_css_to_excel(css, expected): convert = CSSToExcelConverter() assert expected == convert(css)
def test_css_to_excel_warns_when_not_supported(): convert = CSSToExcelConverter() with pytest.warns(UserWarning): convert('background: red')