from textwrap import ( dedent, indent, ) import numpy as np import pytest from pandas import ( DataFrame, MultiIndex, option_context, ) jinja2 = pytest.importorskip("jinja2") from pandas.io.formats.style import Styler @pytest.fixture def env(): loader = jinja2.PackageLoader("pandas", "io/formats/templates") env = jinja2.Environment(loader=loader, trim_blocks=True) return env @pytest.fixture def styler(): return Styler(DataFrame([[2.61], [2.69]], index=["a", "b"], columns=["A"])) @pytest.fixture def styler_mi(): midx = MultiIndex.from_product([["a", "b"], ["c", "d"]]) return Styler(DataFrame(np.arange(16).reshape(4, 4), index=midx, columns=midx)) @pytest.fixture def tpl_style(env): return env.get_template("html_style.tpl") @pytest.fixture def tpl_table(env): return env.get_template("html_table.tpl") def test_html_template_extends_options(): # make sure if templates are edited tests are updated as are setup fixtures # to understand the dependency with open("pandas/io/formats/templates/html.tpl", encoding="utf-8") as file: result = file.read() assert "{% include html_style_tpl %}" in result assert "{% include html_table_tpl %}" in result def test_exclude_styles(styler): result = styler.to_html(exclude_styles=True, doctype_html=True) expected = dedent( """\
  A
a 2.610000
b 2.690000