Skip to content

Commit 6051671

Browse files
committed
Update test_validate.py
1 parent c261be8 commit 6051671

File tree

1 file changed

+236
-1
lines changed

1 file changed

+236
-1
lines changed

tests/test_validate.py

Lines changed: 236 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,14 @@ class StrEnum(str, Enum):
8585
from pointblank.validate import (
8686
Actions,
8787
FinalActions,
88+
config,
8889
connect_to_table,
8990
get_action_metadata,
9091
get_column_count,
9192
get_data_path,
9293
get_row_count,
9394
get_validation_summary,
95+
global_config,
9496
load_dataset,
9597
missing_vals_tbl,
9698
PointblankConfig,
@@ -11018,7 +11020,7 @@ def test_pointblank_config_class():
1101811020

1101911021
assert (
1102011022
str(config)
11021-
== "PointblankConfig(report_incl_header=True, report_incl_footer=True, preview_incl_header=True)"
11023+
== "PointblankConfig(report_incl_header=True, report_incl_footer=True, report_incl_footer_timings=True, report_incl_footer_notes=True, preview_incl_header=True)"
1102211024
)
1102311025

1102411026

@@ -19865,3 +19867,236 @@ def test_threshold_notes_no_note_when_thresholds_match():
1986519867
# No threshold notes should appear
1986619868
assert "Step-specific thresholds set with" not in html
1986719869
assert "Global thresholds explicitly not used" not in html
19870+
19871+
19872+
def test_config_footer_timings_and_notes():
19873+
"""Test footer timings and notes configuration options."""
19874+
19875+
# Test default configuration includes selected fields
19876+
config = PointblankConfig()
19877+
assert config.report_incl_footer_timings is True
19878+
assert config.report_incl_footer_notes is True
19879+
19880+
# Test configuration with the two fields disabled
19881+
config_no_footer_details = PointblankConfig(
19882+
report_incl_header=True,
19883+
report_incl_footer=True,
19884+
report_incl_footer_timings=False,
19885+
report_incl_footer_notes=False,
19886+
preview_incl_header=True,
19887+
)
19888+
assert config_no_footer_details.report_incl_footer_timings is False
19889+
assert config_no_footer_details.report_incl_footer_notes is False
19890+
19891+
# Test string representation for inclusion of the fields
19892+
str_repr = str(config)
19893+
assert "report_incl_footer_timings=True" in str_repr
19894+
assert "report_incl_footer_notes=True" in str_repr
19895+
19896+
19897+
def test_get_tabular_report_footer_timings_control():
19898+
"""Test that incl_footer_timings= parameter controls timing display in reports."""
19899+
19900+
small_table = load_dataset(dataset="small_table")
19901+
19902+
# Create validation with an error to trigger a note
19903+
validation = (
19904+
Validate(data=small_table, label="Test Validation")
19905+
.col_vals_gt(columns="d", value=100)
19906+
.col_vals_regex(columns="invalid_column", pattern=r"test")
19907+
.interrogate()
19908+
)
19909+
19910+
# Test with default settings (timings should be present)
19911+
html_with_timings = validation.get_tabular_report()._repr_html_()
19912+
19913+
# Timing information is rendered with specific styling in _create_table_time_html
19914+
assert "font-variant-numeric: tabular-nums" in html_with_timings
19915+
assert "solid 1px #999999" in html_with_timings # Part of timing badge styling
19916+
19917+
# Test with timings disabled
19918+
html_no_timings = validation.get_tabular_report(incl_footer_timings=False)._repr_html_()
19919+
19920+
# When timings are disabled, there should be fewer timing-related style elements so
19921+
# count occurrences to verify reduction
19922+
timing_style_count_with = html_with_timings.count("font-variant-numeric: tabular-nums")
19923+
timing_style_count_without = html_no_timings.count("font-variant-numeric: tabular-nums")
19924+
19925+
assert timing_style_count_without < timing_style_count_with
19926+
19927+
19928+
def test_get_tabular_report_footer_notes_control():
19929+
"""Test that incl_footer_notes= parameter controls notes display in reports."""
19930+
19931+
small_table = load_dataset(dataset="small_table")
19932+
19933+
# Create validation with an error to trigger a note
19934+
validation = (
19935+
Validate(data=small_table, label="Test Validation")
19936+
.col_vals_gt(columns="d", value=100)
19937+
.col_vals_regex(columns="invalid_column", pattern=r"test")
19938+
.interrogate()
19939+
)
19940+
19941+
# Test with default settings (notes should be present)
19942+
html_with_notes = validation.get_tabular_report()._repr_html_()
19943+
19944+
assert "<strong>Notes</strong>" in html_with_notes
19945+
# Notes include step references with small caps formatting
19946+
assert "font-variant: small-caps" in html_with_notes or "Step" in html_with_notes.lower()
19947+
19948+
# Test with notes disabled
19949+
html_no_notes = validation.get_tabular_report(incl_footer_notes=False)._repr_html_()
19950+
19951+
assert "<strong>Notes</strong>" not in html_no_notes
19952+
19953+
19954+
def test_get_tabular_report_footer_controls_combined():
19955+
"""Test combinations of footer timing and notes controls."""
19956+
19957+
small_table = load_dataset(dataset="small_table")
19958+
19959+
validation = (
19960+
Validate(data=small_table, label="Test Validation")
19961+
.col_vals_gt(columns="d", value=100)
19962+
.col_vals_regex(columns="invalid_column", pattern=r"test")
19963+
.interrogate()
19964+
)
19965+
19966+
# Test with both timings and notes enabled (default)
19967+
html_both = validation.get_tabular_report()._repr_html_()
19968+
19969+
assert "font-variant-numeric: tabular-nums" in html_both
19970+
assert "<strong>Notes</strong>" in html_both
19971+
19972+
# Test with both disabled but footer still enabled
19973+
html_neither = validation.get_tabular_report(
19974+
incl_footer_timings=False, incl_footer_notes=False
19975+
)._repr_html_()
19976+
timing_count = html_neither.count("font-variant-numeric: tabular-nums")
19977+
19978+
assert "<strong>Notes</strong>" not in html_neither
19979+
assert timing_count < html_both.count("font-variant-numeric: tabular-nums")
19980+
19981+
# Test with timings enabled, notes disabled
19982+
html_timings_only = validation.get_tabular_report(incl_footer_notes=False)._repr_html_()
19983+
19984+
assert "font-variant-numeric: tabular-nums" in html_timings_only
19985+
assert "<strong>Notes</strong>" not in html_timings_only
19986+
19987+
# Test with notes enabled, timings disabled
19988+
html_notes_only = validation.get_tabular_report(incl_footer_timings=False)._repr_html_()
19989+
19990+
assert "<strong>Notes</strong>" in html_notes_only
19991+
19992+
19993+
def test_global_config_footer_controls():
19994+
"""Test that global config settings for footer controls work correctly."""
19995+
19996+
small_table = load_dataset(dataset="small_table")
19997+
19998+
validation = (
19999+
Validate(data=small_table, label="Test Validation")
20000+
.col_vals_gt(columns="d", value=100)
20001+
.col_vals_regex(columns="invalid_column", pattern=r"test")
20002+
.interrogate()
20003+
)
20004+
20005+
# Save original config
20006+
original_config = PointblankConfig(
20007+
report_incl_header=global_config.report_incl_header,
20008+
report_incl_footer=global_config.report_incl_footer,
20009+
report_incl_footer_timings=global_config.report_incl_footer_timings,
20010+
report_incl_footer_notes=global_config.report_incl_footer_notes,
20011+
preview_incl_header=global_config.preview_incl_header,
20012+
)
20013+
20014+
try:
20015+
# Set global config to disable timings
20016+
config(
20017+
report_incl_header=True,
20018+
report_incl_footer=True,
20019+
report_incl_footer_timings=False,
20020+
report_incl_footer_notes=True,
20021+
preview_incl_header=True,
20022+
)
20023+
20024+
# Report should respect global config
20025+
html = validation.get_tabular_report()._repr_html_()
20026+
timing_count = html.count("font-variant-numeric: tabular-nums")
20027+
assert "<strong>Notes</strong>" in html
20028+
# Should have fewer timing elements
20029+
assert timing_count < 3
20030+
20031+
# Set global config to disable notes
20032+
config(
20033+
report_incl_header=True,
20034+
report_incl_footer=True,
20035+
report_incl_footer_timings=True,
20036+
report_incl_footer_notes=False,
20037+
preview_incl_header=True,
20038+
)
20039+
20040+
html = validation.get_tabular_report()._repr_html_()
20041+
assert "font-variant-numeric: tabular-nums" in html
20042+
assert "<strong>Notes</strong>" not in html
20043+
20044+
finally:
20045+
# Restore original config
20046+
config(
20047+
report_incl_header=original_config.report_incl_header,
20048+
report_incl_footer=original_config.report_incl_footer,
20049+
report_incl_footer_timings=original_config.report_incl_footer_timings,
20050+
report_incl_footer_notes=original_config.report_incl_footer_notes,
20051+
preview_incl_header=original_config.preview_incl_header,
20052+
)
20053+
20054+
20055+
def test_footer_controls_override_global_config():
20056+
"""Test that method parameters override global config settings."""
20057+
20058+
small_table = load_dataset(dataset="small_table")
20059+
20060+
validation = (
20061+
Validate(data=small_table, label="Test Validation")
20062+
.col_vals_gt(columns="d", value=100)
20063+
.col_vals_regex(columns="invalid_column", pattern=r"test")
20064+
.interrogate()
20065+
)
20066+
20067+
# Save original config
20068+
original_config = PointblankConfig(
20069+
report_incl_header=global_config.report_incl_header,
20070+
report_incl_footer=global_config.report_incl_footer,
20071+
report_incl_footer_timings=global_config.report_incl_footer_timings,
20072+
report_incl_footer_notes=global_config.report_incl_footer_notes,
20073+
preview_incl_header=global_config.preview_incl_header,
20074+
)
20075+
20076+
try:
20077+
# Set global config to disable both
20078+
config(
20079+
report_incl_header=True,
20080+
report_incl_footer=True,
20081+
report_incl_footer_timings=False,
20082+
report_incl_footer_notes=False,
20083+
preview_incl_header=True,
20084+
)
20085+
20086+
# Override with method parameters to enable both
20087+
html = validation.get_tabular_report(
20088+
incl_footer_timings=True, incl_footer_notes=True
20089+
)._repr_html_()
20090+
20091+
assert "font-variant-numeric: tabular-nums" in html
20092+
assert "<strong>Notes</strong>" in html
20093+
20094+
finally:
20095+
# Restore original config
20096+
config(
20097+
report_incl_header=original_config.report_incl_header,
20098+
report_incl_footer=original_config.report_incl_footer,
20099+
report_incl_footer_timings=original_config.report_incl_footer_timings,
20100+
report_incl_footer_notes=original_config.report_incl_footer_notes,
20101+
preview_incl_header=original_config.preview_incl_header,
20102+
)

0 commit comments

Comments
 (0)