Skip to content

Commit

Permalink
Add several snapshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rich-iannone committed Dec 12, 2023
1 parent 73723b1 commit e95a121
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 2 deletions.
108 changes: 108 additions & 0 deletions tests/__snapshots__/test_utils_render_html.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,111 @@
</tfoot>
'''
# ---
# name: test_styling_data_1
'''
<tbody class="gt_table_body">
<tr>
<td style="color: red;" class="gt_row gt_right">0.1111</td>
<td style="color: red;" class="gt_row gt_left">apricot</td>
</tr>
<tr>
<td style="color: red;" class="gt_row gt_right">2.222</td>
<td style="color: red;" class="gt_row gt_left">banana</td>
</tr>
<tr>
<td style="color: red;" class="gt_row gt_right">33.33</td>
<td style="color: red;" class="gt_row gt_left">coconut</td>
</tr>
</tbody>
'''
# ---
# name: test_styling_data_2
'''
<tbody class="gt_table_body">
<tr>
<td class="gt_row gt_right">0.1111</td>
<td style="color: red;" class="gt_row gt_left">apricot</td>
</tr>
<tr>
<td class="gt_row gt_right">2.222</td>
<td style="color: red;" class="gt_row gt_left">banana</td>
</tr>
<tr>
<td class="gt_row gt_right">33.33</td>
<td style="color: red;" class="gt_row gt_left">coconut</td>
</tr>
</tbody>
'''
# ---
# name: test_styling_data_3
'''
<tbody class="gt_table_body">
<tr>
<td class="gt_row gt_right">0.1111</td>
<td style="color: red;" class="gt_row gt_left">apricot</td>
</tr>
<tr>
<td class="gt_row gt_right">2.222</td>
<td class="gt_row gt_left">banana</td>
</tr>
<tr>
<td class="gt_row gt_right">33.33</td>
<td style="color: red;" class="gt_row gt_left">coconut</td>
</tr>
</tbody>
'''
# ---
# name: test_styling_data_4
'''
<tbody class="gt_table_body">
<tr>
<td class="gt_row gt_right">0.1111</td>
<td class="gt_row gt_left">apricot</td>
</tr>
<tr>
<td class="gt_row gt_right">2.222</td>
<td class="gt_row gt_left">banana</td>
</tr>
<tr>
<td class="gt_row gt_right">33.33</td>
<td class="gt_row gt_left">coconut</td>
</tr>
</tbody>
'''
# ---
# name: test_styling_data_5
'''
<tbody class="gt_table_body">
<tr>
<td class="gt_row gt_right">0.1111</td>
<td class="gt_row gt_left">apricot</td>
</tr>
<tr>
<td class="gt_row gt_right">2.222</td>
<td class="gt_row gt_left">banana</td>
</tr>
<tr>
<td class="gt_row gt_right">33.33</td>
<td class="gt_row gt_left">coconut</td>
</tr>
</tbody>
'''
# ---
# name: test_styling_data_6
'''
<tbody class="gt_table_body">
<tr>
<td class="gt_row gt_right">0.1111</td>
<td class="gt_row gt_left">apricot</td>
</tr>
<tr>
<td class="gt_row gt_right">2.222</td>
<td class="gt_row gt_left">banana</td>
</tr>
<tr>
<td class="gt_row gt_right">33.33</td>
<td class="gt_row gt_left">coconut</td>
</tr>
</tbody>
'''
# ---
67 changes: 65 additions & 2 deletions tests/test_utils_render_html.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from great_tables import GT, exibble, md, html
from great_tables._utils_render_html import create_source_notes_component_h
from great_tables import GT, exibble, md, html, style, loc
from great_tables._utils_render_html import create_source_notes_component_h, create_body_component_h

small_exibble = exibble[["num", "char"]].head(3)


def assert_rendered_source_notes(snapshot, gt):
Expand All @@ -9,6 +11,13 @@ def assert_rendered_source_notes(snapshot, gt):
assert snapshot == source_notes


def assert_rendered_body(snapshot, gt):
built = gt._build_data("html")
body = create_body_component_h(built)

assert snapshot == body


def test_source_notes_snap(snapshot):
new_gt = (
GT(exibble)
Expand All @@ -19,3 +28,57 @@ def test_source_notes_snap(snapshot):
)

assert_rendered_source_notes(snapshot, new_gt)


def test_styling_data_1(snapshot):
new_gt = GT(small_exibble).tab_style(
style=style.text(color="red"),
locations=loc.body(),
)

assert_rendered_body(snapshot, new_gt)


def test_styling_data_2(snapshot):
new_gt = GT(small_exibble).tab_style(
style=style.text(color="red"),
locations=loc.body(columns=["char"]),
)

assert_rendered_body(snapshot, new_gt)


def test_styling_data_3(snapshot):
new_gt = GT(small_exibble).tab_style(
style=style.text(color="red"),
locations=loc.body(columns="char", rows=[0, 2]),
)

assert_rendered_body(snapshot, new_gt)


def test_styling_data_4(snapshot):
new_gt = GT(small_exibble).tab_style(
style=style.text(color="red"),
locations=loc.body(columns=[], rows=[0, 2]),
)

assert_rendered_body(snapshot, new_gt)


def test_styling_data_5(snapshot):
new_gt = GT(small_exibble).tab_style(
style=style.text(color="red"),
locations=loc.body(columns="char", rows=[]),
)

assert_rendered_body(snapshot, new_gt)


def test_styling_data_6(snapshot):
new_gt = GT(small_exibble).tab_style(
style=style.text(color="red"),
locations=loc.body(columns=[], rows=[]),
)

assert_rendered_body(snapshot, new_gt)

0 comments on commit e95a121

Please sign in to comment.