Skip to content

Commit

Permalink
test(config): update configuration in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrugman committed Jul 4, 2022
1 parent 797aeac commit 2f5a4a0
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 32 deletions.
22 changes: 11 additions & 11 deletions tests/popmon/alerting/test_apply_tl_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
rolling_mean,
)
from popmon.base import Pipeline
from popmon.config import Settings
from popmon.visualization.section_generator import SectionGenerator


Expand Down Expand Up @@ -225,16 +226,14 @@ def test_rolling_window_funcs():

def test_report_traffic_light_bounds():
datastore = {"to_profile": {"asc_numbers": get_test_data()}}

conf = {
"monitoring_rules": {
"the_feature:mae": [8, 4, 2, 0.15],
"mse": [0.2, 0.11, 0.09, 0],
"mae": [1, 0, 0, 0],
"*_pull": [7, 4, -4, -7],
},
"pull_rules": {"*_pull": [7, 4, -4, -7]},
settings = Settings()
settings.monitoring.monitoring_rules = {
"the_feature:mae": [8, 4, 2, 0.15],
"mse": [0.2, 0.11, 0.09, 0],
"mae": [1, 0, 0, 0],
"*_pull": [7, 4, -4, -7],
}
settings.monitoring.pull_rules = {"*_pull": [7, 4, -4, -7]}

m1 = ApplyFunc(
apply_to_key="to_profile", features=["asc_numbers"], metrics=["a", "b"]
Expand All @@ -250,12 +249,12 @@ def test_report_traffic_light_bounds():
ctlb = ComputeTLBounds(
read_key="to_profile",
store_key="static_tlb",
monitoring_rules=conf["monitoring_rules"],
monitoring_rules=settings.monitoring.monitoring_rules,
)

m3 = ComputeTLBounds(
read_key="to_profile",
monitoring_rules=conf["pull_rules"],
monitoring_rules=settings.monitoring.pull_rules,
apply_funcs_key="dynamic_tlb",
func=pull_bounds,
metrics_wide=True,
Expand All @@ -272,6 +271,7 @@ def test_report_traffic_light_bounds():
section_name="Profiles",
dynamic_bounds="dtlb",
static_bounds="static_tlb",
settings=settings.report,
)

pipeline = Pipeline(modules=[m1, m2, ctlb, m3, m4, rg])
Expand Down
2 changes: 0 additions & 2 deletions tests/popmon/alerting/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def test_traffic_light_summary():

output = datastore["alerts"]["the_feature"]

assert output["worst"].values[-1] == 2
assert output["n_green"].values[-1] == 1
assert output["n_yellow"].values[-1] == 0
assert output["n_red"].values[-1] == 1
Expand Down Expand Up @@ -137,7 +136,6 @@ def test_traffic_light_summary_combination():
assert "_AGGREGATE_" in alerts
output = datastore["alerts"]["_AGGREGATE_"]

assert output["worst"].values[-1] == 2
assert output["n_green"].values[-1] == 1
assert output["n_yellow"].values[-1] == 0
assert output["n_red"].values[-1] == 1
4 changes: 1 addition & 3 deletions tests/popmon/analysis/comparison/test_hist_comparer.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def test_hist_compare():


def test_reference_hist_comparer():

hist_list = ["date:country", "date:bankrupt", "date:num_employees", "date:A_score"]
features = ["country", "bankrupt", "num_employees", "A_score"]

Expand Down Expand Up @@ -116,7 +115,7 @@ def test_reference_hist_comparer():

df = datastore["comparison"]["A_score"]
assert len(df) == 16
np.testing.assert_array_equal(sorted(df.columns), sorted(cols))
assert set(df.columns) == set(cols)
np.testing.assert_almost_equal(df["ref_chi2"].mean(), 2.623206018518519)

df = datastore["comparison"]["country"]
Expand All @@ -136,7 +135,6 @@ def test_reference_hist_comparer():


def test_expanding_hist_comparer():

hist_list = ["date:country", "date:bankrupt", "date:num_employees", "date:A_score"]
features = ["country", "bankrupt", "num_employees", "A_score"]

Expand Down
11 changes: 9 additions & 2 deletions tests/popmon/pipeline/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@

from popmon import resources
from popmon.base import Pipeline
from popmon.config import Settings
from popmon.io import JsonReader
from popmon.pipeline.metrics import df_stability_metrics, stability_metrics


def test_hists_stability_metrics():
settings = Settings()
settings.comparison.window = 5

# get histograms
pipeline = Pipeline(
modules=[
Expand All @@ -28,7 +32,7 @@ def test_hists_stability_metrics():
"date:A_score:num_employees",
]
ds = stability_metrics(
hists, reference_type="rolling", window=5, features=hist_list
hists, settings=settings, reference_type="rolling", features=hist_list
)

cols = ["profiles", "comparisons", "traffic_lights", "alerts"]
Expand All @@ -37,6 +41,8 @@ def test_hists_stability_metrics():


def test_df_stability_metrics():
settings = Settings()

# generate metrics directly from dataframe
features = ["date:isActive", "date:eyeColor", "date:latitude"]
bin_specs = {
Expand All @@ -47,7 +53,8 @@ def test_df_stability_metrics():
"latitude": {"bin_width": 5.0, "bin_offset": 0.0},
}
ds = df_stability_metrics(
pytest.test_df,
df=pytest.test_df,
settings=settings,
time_axis="date",
features=features,
binning="unit",
Expand Down
20 changes: 17 additions & 3 deletions tests/popmon/pipeline/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@

from popmon import resources
from popmon.base import Pipeline
from popmon.config import Report, Settings
from popmon.hist.filling import get_bin_specs
from popmon.io import JsonReader
from popmon.pipeline.report import df_stability_report, stability_report


def test_hists_stability_report():
settings = Settings()
settings.comparison.window = 5

# get histograms
pipeline = Pipeline(
modules=[
Expand All @@ -28,7 +32,9 @@ def test_hists_stability_report():
"date:A_score",
"date:A_score:num_employees",
]
stability_report(hists, reference_type="rolling", window=5, features=hist_list)
stability_report(
hists, reference_type="rolling", settings=settings, features=hist_list
)


def test_df_stability_report():
Expand All @@ -49,9 +55,17 @@ def test_df_stability_report():
bin_specs=bin_specs,
)

settings = Report()
settings.last_n = 4

# regenerate report, changing the plot window settings
rep.regenerate(last_n=4)
rep.regenerate(skip_first_n=1, skip_last_n=1)
rep.regenerate(report_settings=settings)

settings.last_n = 0
settings.skip_first_n = 1
settings.skip_last_n = 1

rep.regenerate(report_settings=settings)


def test_df_stability_report_self():
Expand Down
13 changes: 10 additions & 3 deletions tests/popmon/pipeline/test_report_pipelines.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from popmon import resources
from popmon.base import Pipeline
from popmon.config import Settings
from popmon.io import JsonReader
from popmon.pipeline.report_pipelines import (
ExpandingReference,
Expand All @@ -17,7 +18,7 @@ def test_self_reference():
JsonReader(
file_path=resources.data("example_histogram.json"), store_key="hists"
),
SelfReference(hists_key="hists", features=hist_list),
SelfReference(hists_key="hists", features=hist_list, settings=Settings()),
]
)
pipeline.transform(datastore={})
Expand All @@ -35,6 +36,7 @@ def test_external_reference():
hists_key="hists",
ref_hists_key="hists",
features=hist_list,
settings=Settings(),
),
]
)
Expand All @@ -44,14 +46,17 @@ def test_external_reference():
def test_rolling_reference():
hist_list = ["date:country", "date:A_score:num_employees"]

settings = Settings()
settings.comparison.window = 5

pipeline = Pipeline(
modules=[
JsonReader(
file_path=resources.data("example_histogram.json"), store_key="hists"
),
RollingReference(
hists_key="hists",
window=5,
settings=settings,
features=hist_list,
),
]
Expand All @@ -67,7 +72,9 @@ def test_expanding_reference():
JsonReader(
file_path=resources.data("example_histogram.json"), store_key="hists"
),
ExpandingReference(hists_key="hists", features=hist_list),
ExpandingReference(
hists_key="hists", features=hist_list, settings=Settings()
),
]
)
pipeline.transform(datastore={})
10 changes: 4 additions & 6 deletions tests/popmon/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from popmon.config import config
from popmon.config import Report
from popmon.utils import filter_metrics


def test_filter_metrics():
settings = Report()

metrics = [
"distinct_pull",
"filled_pull",
Expand All @@ -19,7 +21,6 @@ def test_filter_metrics():
"fraction_true_trend10_zscore",
"ref_unknown_labels",
"prev1_ks_zscore",
"worst",
"ref_max_prob_diff",
]
expected = [
Expand All @@ -36,12 +37,9 @@ def test_filter_metrics():
"fraction_true_trend10_zscore",
"ref_unknown_labels",
"prev1_ks_zscore",
"worst",
"ref_max_prob_diff",
]
assert (
filter_metrics(
metrics, ignore_stat_endswith=[], show_stats=config["limited_stats"]
)
filter_metrics(metrics, ignore_stat_endswith=[], show_stats=settings.show_stats)
== expected
)
8 changes: 6 additions & 2 deletions tests/popmon/visualization/test_report_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from popmon import resources
from popmon.analysis.comparison.hist_comparer import ReferenceHistComparer
from popmon.base import Pipeline
from popmon.config import Settings
from popmon.hist.hist_splitter import HistSplitter
from popmon.io import JsonReader
from popmon.visualization import ReportGenerator, SectionGenerator
Expand All @@ -17,6 +18,8 @@ def test_report_generator():
hist_list = ["date:country", "date:bankrupt", "date:num_employees", "date:A_score"]
features = ["country", "bankrupt", "num_employees", "A_score"]

settings = Settings()

pipeline = Pipeline(
modules=[
JsonReader(
Expand All @@ -35,7 +38,7 @@ def test_report_generator():
read_key="comparison",
store_key="all_sections",
section_name="Comparisons",
last_n=2,
settings=settings.report,
),
ReportGenerator(read_key="all_sections", store_key="final_report"),
]
Expand All @@ -49,7 +52,8 @@ def test_report_generator():
for f in features:
assert isinstance(datastore["comparison"][f], pd.DataFrame)

assert pipeline.modules[-2].last_n == 2
assert isinstance(pipeline.modules[-2], SectionGenerator)
assert pipeline.modules[-2].last_n == 0
assert "final_report" in datastore
assert (
isinstance(datastore["final_report"], str)
Expand Down

0 comments on commit 2f5a4a0

Please sign in to comment.