Skip to content

Commit b6cfeef

Browse files
mzeitlin11yeshsurya
authored andcommitted
TST: use expected_html for to_html tests (pandas-dev#40981)
1 parent 0f906b3 commit b6cfeef

File tree

3 files changed

+44
-42
lines changed

3 files changed

+44
-42
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<table border="1" class="dataframe">
2+
<thead>
3+
<tr style="text-align: right;">
4+
<th></th>
5+
<th>Group</th>
6+
<th>Data</th>
7+
</tr>
8+
</thead>
9+
<tbody>
10+
<tr>
11+
<th>0</th>
12+
<td>A</td>
13+
<td>1.22</td>
14+
</tr>
15+
<tr>
16+
<th>1</th>
17+
<td>A</td>
18+
<td>{na_rep}</td>
19+
</tr>
20+
</tbody>
21+
</table>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<table border="1" class="dataframe">
2+
<thead>
3+
<tr style="text-align: right;">
4+
<th></th>
5+
<th>x</th>
6+
</tr>
7+
</thead>
8+
<tbody>
9+
<tr>
10+
<th>0</th>
11+
<td>1,000</td>
12+
</tr>
13+
<tr>
14+
<th>1</th>
15+
<td>test</td>
16+
</tr>
17+
</tbody>
18+
</table>

pandas/tests/io/formats/test_to_html.py

+5-42
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ def test_to_html_multilevel(multiindex_year_month_day_dataframe_random_data):
851851

852852

853853
@pytest.mark.parametrize("na_rep", ["NaN", "Ted"])
854-
def test_to_html_na_rep_and_float_format(na_rep):
854+
def test_to_html_na_rep_and_float_format(na_rep, datapath):
855855
# https://github.com/pandas-dev/pandas/issues/13828
856856
df = DataFrame(
857857
[
@@ -861,51 +861,14 @@ def test_to_html_na_rep_and_float_format(na_rep):
861861
columns=["Group", "Data"],
862862
)
863863
result = df.to_html(na_rep=na_rep, float_format="{:.2f}".format)
864-
expected = f"""<table border="1" class="dataframe">
865-
<thead>
866-
<tr style="text-align: right;">
867-
<th></th>
868-
<th>Group</th>
869-
<th>Data</th>
870-
</tr>
871-
</thead>
872-
<tbody>
873-
<tr>
874-
<th>0</th>
875-
<td>A</td>
876-
<td>1.22</td>
877-
</tr>
878-
<tr>
879-
<th>1</th>
880-
<td>A</td>
881-
<td>{na_rep}</td>
882-
</tr>
883-
</tbody>
884-
</table>"""
864+
expected = expected_html(datapath, "gh13828_expected_output")
865+
expected = expected.format(na_rep=na_rep)
885866
assert result == expected
886867

887868

888-
def test_to_html_float_format_object_col():
869+
def test_to_html_float_format_object_col(datapath):
889870
# GH#40024
890871
df = DataFrame(data={"x": [1000.0, "test"]})
891872
result = df.to_html(float_format=lambda x: f"{x:,.0f}")
892-
expected = """<table border="1" class="dataframe">
893-
<thead>
894-
<tr style="text-align: right;">
895-
<th></th>
896-
<th>x</th>
897-
</tr>
898-
</thead>
899-
<tbody>
900-
<tr>
901-
<th>0</th>
902-
<td>1,000</td>
903-
</tr>
904-
<tr>
905-
<th>1</th>
906-
<td>test</td>
907-
</tr>
908-
</tbody>
909-
</table>"""
910-
873+
expected = expected_html(datapath, "gh40024_expected_output")
911874
assert result == expected

0 commit comments

Comments
 (0)