Skip to content

Commit

Permalink
Snapshot test for backends
Browse files Browse the repository at this point in the history
  • Loading branch information
amol- committed Oct 9, 2024
1 parent d40040b commit d3cdd1c
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
64 changes: 63 additions & 1 deletion tests/__snapshots__/test_tbl_data.ambr
Original file line number Diff line number Diff line change
@@ -1,8 +1,70 @@
# serializer version: 1
# name: test_frame_rendering[arrow]
'''
<tbody class="gt_table_body">
<tr>
<td class="gt_row gt_right">$1.00</td>
<td class="gt_row gt_left">a</td>
<td class="gt_row gt_center">4</td>
</tr>
<tr>
<td class="gt_row gt_right">$2.00</td>
<td class="gt_row gt_left">b</td>
<td class="gt_row gt_center">5</td>
</tr>
<tr>
<td class="gt_row gt_right">$3.00</td>
<td class="gt_row gt_left">c</td>
<td class="gt_row gt_center">6</td>
</tr>
</tbody>
'''
# ---
# name: test_frame_rendering[pandas]
'''
<tbody class="gt_table_body">
<tr>
<td class="gt_row gt_right">$1.00</td>
<td class="gt_row gt_left">a</td>
<td class="gt_row gt_right">4</td>
</tr>
<tr>
<td class="gt_row gt_right">$2.00</td>
<td class="gt_row gt_left">b</td>
<td class="gt_row gt_right">5</td>
</tr>
<tr>
<td class="gt_row gt_right">$3.00</td>
<td class="gt_row gt_left">c</td>
<td class="gt_row gt_right">6</td>
</tr>
</tbody>
'''
# ---
# name: test_frame_rendering[polars]
'''
<tbody class="gt_table_body">
<tr>
<td class="gt_row gt_right">$1.00</td>
<td class="gt_row gt_left">a</td>
<td class="gt_row gt_right">4</td>
</tr>
<tr>
<td class="gt_row gt_right">$2.00</td>
<td class="gt_row gt_left">b</td>
<td class="gt_row gt_right">5</td>
</tr>
<tr>
<td class="gt_row gt_right">$3.00</td>
<td class="gt_row gt_left">c</td>
<td class="gt_row gt_right">6</td>
</tr>
</tbody>
'''
# ---
# name: test_validate_frame_non_str_cols_warning
'''
pandas DataFrame contains non-string column names. Coercing to strings. Here are the first few non-string columns:

* Position 1: 55
* Position 3: 99
'''
Expand Down
7 changes: 7 additions & 0 deletions tests/test_tbl_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import pyarrow as pa
import polars.testing
import pytest
from great_tables import GT
from great_tables._utils_render_html import create_body_component_h
from great_tables._tbl_data import (
DataFrameLike,
SeriesLike,
Expand Down Expand Up @@ -283,3 +285,8 @@ def test_cast_frame_to_string_polars_list_col():
assert new_df["x"].dtype.is_(pl.String)
assert new_df["y"].dtype.is_(pl.String)
assert new_df["z"].dtype.is_(pl.String)


def test_frame_rendering(df: DataFrameLike, snapshot):
gt = GT(df).fmt_number(columns="col3", decimals=0).fmt_currency(columns="col1")
assert create_body_component_h(gt._build_data("html")) == snapshot

0 comments on commit d3cdd1c

Please sign in to comment.