Skip to content

Commit c04ef69

Browse files
committed
refactor tests
1 parent fcd318e commit c04ef69

File tree

1 file changed

+20
-34
lines changed

1 file changed

+20
-34
lines changed

gt_extras/tests/test_styling.py

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,59 @@
1+
import pytest
12
import pandas as pd
23
from great_tables import GT
34

45
from gt_extras.styling import gt_add_divider
56

67

7-
def test_gt_add_divider_basic():
8-
df = pd.DataFrame({"A": [1, 2], "B": [3, 4]})
9-
gt = GT(df)
8+
@pytest.fixture
9+
def sample_gt():
10+
sample_df = pd.DataFrame({"A": [1, 2], "B": [3, 4], "C": [5, 6]})
11+
return GT(sample_df)
1012

11-
html = gt_add_divider(gt, columns="A").as_raw_html()
13+
14+
def test_gt_add_divider_basic(sample_gt):
15+
html = gt_add_divider(sample_gt, columns="A").as_raw_html()
1216

1317
assert html.count("border-right:") == 3
1418
assert html.count("2px solid grey") == 3
1519

1620

17-
def test_gt_add_divider_multiple_columns():
18-
df = pd.DataFrame({"A": [1, 2], "B": [3, 4], "C": [5, 6]})
19-
gt = GT(df)
20-
21-
html = gt_add_divider(gt, columns=["A", "B"]).as_raw_html()
21+
def test_gt_add_divider_multiple_columns(sample_gt):
22+
html = gt_add_divider(sample_gt, columns=["A", "B"]).as_raw_html()
2223

2324
assert html.count("border-right: 2px solid grey") == 2 * 3
2425

2526

26-
def test_gt_add_divider_custom_sides():
27-
df = pd.DataFrame({"A": [1, 2], "B": [3, 4]})
28-
gt = GT(df)
29-
30-
html = gt_add_divider(gt, columns="A", sides="left").as_raw_html()
27+
def test_gt_add_divider_custom_sides(sample_gt):
28+
html = gt_add_divider(sample_gt, columns="A", sides="left").as_raw_html()
3129

3230
assert html.count("border-left:") == 3
3331
assert "border-right:" not in html
3432

3533

36-
def test_gt_add_divider_custom_color_and_style():
37-
df = pd.DataFrame({"A": [1, 2], "B": [3, 4]})
38-
gt = GT(df)
39-
40-
res = gt_add_divider(gt, columns="A", color="blue", divider_style="dashed")
34+
def test_gt_add_divider_custom_color_and_style(sample_gt):
35+
res = gt_add_divider(sample_gt, columns="A", color="blue", divider_style="dashed")
4136
html = res.as_raw_html()
4237

4338
assert "border-right: 2px dashed blue;" in html
4439
assert "grey" not in html
4540

4641

47-
def test_gt_add_divider_custom_weight():
48-
df = pd.DataFrame({"A": [1, 2], "B": [3, 4]})
49-
gt = GT(df)
50-
51-
html = gt_add_divider(gt, columns="A", weight=5).as_raw_html()
42+
def test_gt_add_divider_custom_weight(sample_gt):
43+
html = gt_add_divider(sample_gt, columns="A", weight=5).as_raw_html()
5244

5345
assert "border-right: 5px solid grey;" in html
5446
assert "2px solid grey" not in html
5547

5648

57-
def test_gt_add_divider_exclude_labels():
58-
df = pd.DataFrame({"A": [1, 2], "B": [3, 4]})
59-
gt = GT(df)
60-
61-
html = gt_add_divider(gt, columns="A", include_labels=False).as_raw_html()
49+
def test_gt_add_divider_exclude_labels(sample_gt):
50+
html = gt_add_divider(sample_gt, columns="A", include_labels=False).as_raw_html()
6251

6352
assert html.count("border-right:") == 2
6453

6554

66-
def test_gt_add_divider_multiple_sides():
67-
df = pd.DataFrame({"A": [1, 2], "B": [3, 4]})
68-
gt = GT(df)
69-
70-
html = gt_add_divider(gt, columns="A", sides=["top", "bottom"]).as_raw_html()
55+
def test_gt_add_divider_multiple_sides(sample_gt):
56+
html = gt_add_divider(sample_gt, columns="A", sides=["top", "bottom"]).as_raw_html()
7157

7258
assert "border-top:" in html
7359
assert "border-bottom:" in html

0 commit comments

Comments
 (0)