예제 #1
0
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)
예제 #2
0
    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
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
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
예제 #6
0
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)
예제 #7
0
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
예제 #8
0
def test_css_to_excel_inherited(css, inherited, expected):
    convert = CSSToExcelConverter(inherited)
    assert expected == convert(css)
예제 #9
0
def test_css_to_excel(css, expected):
    convert = CSSToExcelConverter()
    assert expected == convert(css)
예제 #10
0
def test_css_to_excel_warns_when_not_supported():
    convert = CSSToExcelConverter()
    with pytest.warns(UserWarning):
        convert('background: red')