Skip to content

Commit 6012b67

Browse files
committed
Update test_validate.py
1 parent 61a2644 commit 6012b67

File tree

1 file changed

+166
-0
lines changed

1 file changed

+166
-0
lines changed

tests/test_validate.py

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10534,6 +10534,172 @@ def test_simple_column_not_found_note_different_table_types(request, tbl_fixture
1053410534
assert "does not match any columns" in note["text"]
1053510535

1053610536

10537+
def test_comparison_column_not_found_note_basic():
10538+
"""Test that comparison_column_not_found note is generated for missing comparison columns."""
10539+
10540+
validation = (
10541+
Validate(data=pl.DataFrame({"a": [5, 6, 5], "b": [4, 2, 3]}))
10542+
.col_vals_gt(columns="a", value=col("missing_comparison"))
10543+
.interrogate()
10544+
)
10545+
10546+
# Check that eval_error is set
10547+
assert validation.validation_info[0].eval_error is True
10548+
10549+
# Check that comparison_column_not_found note exists
10550+
notes = validation.get_notes(i=1)
10551+
assert notes is not None
10552+
assert "comparison_column_not_found" in notes
10553+
10554+
# Check note content
10555+
note = validation.get_note(i=1, key="comparison_column_not_found")
10556+
assert note is not None
10557+
assert "missing_comparison" in note["text"]
10558+
assert "does not match any columns in the table" in note["text"]
10559+
10560+
10561+
def test_comparison_column_not_found_note_between_left():
10562+
"""Test comparison_column_not_found note for missing LEFT column in col_vals_between."""
10563+
10564+
validation = (
10565+
Validate(data=pl.DataFrame({"a": [5, 6, 5], "b": [4, 2, 3]}))
10566+
.col_vals_between(columns="a", left=col("missing_left"), right=10)
10567+
.interrogate()
10568+
)
10569+
10570+
# Check that eval_error is set
10571+
assert validation.validation_info[0].eval_error is True
10572+
10573+
# Check note content includes position
10574+
note = validation.get_note(i=1, key="comparison_column_not_found")
10575+
assert note is not None
10576+
assert "missing_left" in note["text"]
10577+
assert "for left=" in note["text"]
10578+
assert "does not match any columns" in note["text"]
10579+
10580+
10581+
def test_comparison_column_not_found_note_between_right():
10582+
"""Test comparison_column_not_found note for missing RIGHT column in col_vals_between."""
10583+
10584+
validation = (
10585+
Validate(data=pl.DataFrame({"a": [5, 6, 5], "b": [4, 2, 3]}))
10586+
.col_vals_between(columns="a", left=0, right=col("missing_right"))
10587+
.interrogate()
10588+
)
10589+
10590+
# Check that eval_error is set
10591+
assert validation.validation_info[0].eval_error is True
10592+
10593+
# Check note content includes position
10594+
note = validation.get_note(i=1, key="comparison_column_not_found")
10595+
assert note is not None
10596+
assert "missing_right" in note["text"]
10597+
assert "for right=" in note["text"]
10598+
assert "does not match any columns" in note["text"]
10599+
10600+
10601+
def test_comparison_column_not_found_note_outside():
10602+
"""Test comparison_column_not_found note for missing column in col_vals_outside."""
10603+
10604+
validation = (
10605+
Validate(data=pl.DataFrame({"a": [5, 6, 5], "b": [4, 2, 3]}))
10606+
.col_vals_outside(columns="a", left=col("missing_low"), right=100)
10607+
.interrogate()
10608+
)
10609+
10610+
# Check that eval_error is set
10611+
assert validation.validation_info[0].eval_error is True
10612+
10613+
# Check note content includes position
10614+
note = validation.get_note(i=1, key="comparison_column_not_found")
10615+
assert note is not None
10616+
assert "missing_low" in note["text"]
10617+
assert "for left=" in note["text"]
10618+
10619+
10620+
def test_comparison_column_not_found_note_multilingual():
10621+
"""Test that comparison_column_not_found note works in multiple languages."""
10622+
10623+
# Test French
10624+
validation_fr = (
10625+
Validate(data=pl.DataFrame({"a": [5, 6], "b": [4, 2]}), lang="fr")
10626+
.col_vals_gt(columns="a", value=col("missing"))
10627+
.interrogate()
10628+
)
10629+
note_fr = validation_fr.get_note(i=1, key="comparison_column_not_found", format="markdown")
10630+
assert note_fr is not None
10631+
assert "La colonne de comparaison fournie" in note_fr or "comparaison" in note_fr
10632+
assert "missing" in note_fr
10633+
10634+
# Test Japanese
10635+
validation_ja = (
10636+
Validate(data=pl.DataFrame({"a": [5, 6], "b": [4, 2]}), lang="ja")
10637+
.col_vals_gt(columns="a", value=col("missing"))
10638+
.interrogate()
10639+
)
10640+
note_ja = validation_ja.get_note(i=1, key="comparison_column_not_found", format="markdown")
10641+
assert note_ja is not None
10642+
assert "比較列" in note_ja
10643+
assert "missing" in note_ja
10644+
10645+
10646+
def test_comparison_column_not_found_note_multiple_methods():
10647+
"""Test comparison_column_not_found notes across different validation methods."""
10648+
10649+
validation = (
10650+
Validate(data=pl.DataFrame({"a": [5, 6, 5], "b": [4, 2, 3]}))
10651+
.col_vals_gt(columns="a", value=col("miss1"))
10652+
.col_vals_lt(columns="a", value=col("miss2"))
10653+
.col_vals_ge(columns="a", value=col("miss3"))
10654+
.interrogate()
10655+
)
10656+
10657+
# All three steps should have eval_error and comparison_column_not_found notes
10658+
for i, col_name in enumerate(["miss1", "miss2", "miss3"], start=1):
10659+
assert validation.validation_info[i - 1].eval_error is True
10660+
note = validation.get_note(i=i, key="comparison_column_not_found")
10661+
assert note is not None
10662+
assert col_name in note["text"]
10663+
10664+
10665+
def test_column_error_notes_monospace_font():
10666+
"""Test that column names and parameter names use monospace font in HTML notes."""
10667+
10668+
validation = (
10669+
Validate(data=pl.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]}))
10670+
# Simple column error
10671+
.col_vals_not_null(columns="missing_col")
10672+
# Selector error
10673+
.col_vals_gt(columns=starts_with("xyz_"), value=0)
10674+
# Comparison column error without position
10675+
.col_vals_gt(columns="a", value=col("missing_comp"))
10676+
# Comparison column error with position
10677+
.col_vals_between(columns="a", left=col("missing_left"), right=10)
10678+
.interrogate()
10679+
)
10680+
10681+
# Check simple column error has monospace font
10682+
note_1 = validation.get_note(i=1, key="column_not_found", format="markdown")
10683+
assert "IBM Plex Mono" in note_1
10684+
assert "missing_col" in note_1
10685+
10686+
# Check selector error has monospace font
10687+
note_2 = validation.get_note(i=2, key="no_columns_resolved", format="markdown")
10688+
assert "IBM Plex Mono" in note_2
10689+
assert "StartsWith" in note_2
10690+
10691+
# Check comparison column error has monospace font for column name
10692+
note_3 = validation.get_note(i=3, key="comparison_column_not_found", format="markdown")
10693+
assert "IBM Plex Mono" in note_3
10694+
assert "missing_comp" in note_3
10695+
10696+
# Check comparison column error with position has monospace font for both column and parameter
10697+
note_4 = validation.get_note(i=4, key="comparison_column_not_found", format="markdown")
10698+
assert note_4.count("IBM Plex Mono") >= 2 # Should appear for both parameter and column
10699+
assert "missing_left" in note_4
10700+
assert "left=" in note_4
10701+
10702+
1053710703
def test_process_data_dataframe_passthrough_pandas():
1053810704
pd = pytest.importorskip("pandas")
1053910705

0 commit comments

Comments
 (0)