From 5e723ef0b74b0233e382c224ff00c1a18408d028 Mon Sep 17 00:00:00 2001 From: Jared Snyder Date: Wed, 22 May 2024 11:11:44 -0500 Subject: [PATCH] remove configloader helper objects (#233) * remove configloader helper objects * linting: * removed deprecated doc files from sphinx * fixed mistake in docstring * removed redundant tests * remove path modification from conftest.py and consolidated desktop metric creation * linting * actually add stuff to the file I created instead of being a moron * import lists in test * consolidated lists in config_loader_lists --- docs/api/metrics/desktop.rst | 5 - docs/api/metrics/fenix.rst | 5 - docs/api/metrics/firefox_ios.rst | 5 - docs/api/segments/desktop.rst | 5 - src/mozanalysis/experiment.py | 5 +- .../{metrics/__init__.py => metrics.py} | 19 ---- src/mozanalysis/metrics/desktop.py | 82 -------------- src/mozanalysis/metrics/fenix.py | 30 ----- src/mozanalysis/metrics/firefox_ios.py | 21 ---- src/mozanalysis/metrics/focus_android.py | 21 ---- src/mozanalysis/metrics/focus_ios.py | 21 ---- src/mozanalysis/metrics/klar_android.py | 22 ---- src/mozanalysis/metrics/klar_ios.py | 21 ---- .../{segments/__init__.py => segments.py} | 21 ---- src/mozanalysis/segments/desktop.py | 26 ----- src/mozanalysis/sizing.py | 12 +- tests/__init__.py | 12 -- tests/conftest.py | 4 - .../test_sample_size_calc.py | 7 +- tests/helpers/config_loader_lists.py | 58 ++++++++++ tests/test_config.py | 2 +- tests/test_experiment.py | 73 ++++-------- tests/test_metric_libraries.py | 51 --------- tests/test_segment_libraries.py | 105 ------------------ tests/test_sizing.py | 28 +++-- 25 files changed, 119 insertions(+), 542 deletions(-) delete mode 100644 docs/api/metrics/desktop.rst delete mode 100644 docs/api/metrics/fenix.rst delete mode 100644 docs/api/metrics/firefox_ios.rst delete mode 100644 docs/api/segments/desktop.rst rename src/mozanalysis/{metrics/__init__.py => metrics.py} (96%) delete mode 100644 src/mozanalysis/metrics/desktop.py delete mode 100644 src/mozanalysis/metrics/fenix.py delete mode 100644 src/mozanalysis/metrics/firefox_ios.py delete mode 100644 src/mozanalysis/metrics/focus_android.py delete mode 100644 src/mozanalysis/metrics/focus_ios.py delete mode 100644 src/mozanalysis/metrics/klar_android.py delete mode 100644 src/mozanalysis/metrics/klar_ios.py rename src/mozanalysis/{segments/__init__.py => segments.py} (92%) delete mode 100644 src/mozanalysis/segments/desktop.py delete mode 100644 tests/__init__.py create mode 100644 tests/helpers/config_loader_lists.py delete mode 100644 tests/test_metric_libraries.py delete mode 100644 tests/test_segment_libraries.py diff --git a/docs/api/metrics/desktop.rst b/docs/api/metrics/desktop.rst deleted file mode 100644 index f12f8d1..0000000 --- a/docs/api/metrics/desktop.rst +++ /dev/null @@ -1,5 +0,0 @@ -:mod:`mozanalysis.metrics.desktop` ----------------------------------- - -.. automodule:: mozanalysis.metrics.desktop - :members: diff --git a/docs/api/metrics/fenix.rst b/docs/api/metrics/fenix.rst deleted file mode 100644 index 64f58c0..0000000 --- a/docs/api/metrics/fenix.rst +++ /dev/null @@ -1,5 +0,0 @@ -:mod:`mozanalysis.metrics.fenix` ----------------------------------- - -.. automodule:: mozanalysis.metrics.fenix - :members: diff --git a/docs/api/metrics/firefox_ios.rst b/docs/api/metrics/firefox_ios.rst deleted file mode 100644 index 32cdbb6..0000000 --- a/docs/api/metrics/firefox_ios.rst +++ /dev/null @@ -1,5 +0,0 @@ -:mod:`mozanalysis.metrics.firefox_ios` ---------------------------------------- - -.. automodule:: mozanalysis.metrics.firefox_ios - :members: diff --git a/docs/api/segments/desktop.rst b/docs/api/segments/desktop.rst deleted file mode 100644 index 402e8c1..0000000 --- a/docs/api/segments/desktop.rst +++ /dev/null @@ -1,5 +0,0 @@ -:mod:`mozanalysis.segments.desktop` ------------------------------------ - -.. automodule:: mozanalysis.segments.desktop - :members: diff --git a/src/mozanalysis/experiment.py b/src/mozanalysis/experiment.py index ea8debd..dd05f94 100644 --- a/src/mozanalysis/experiment.py +++ b/src/mozanalysis/experiment.py @@ -71,7 +71,10 @@ class Experiment: from mozanalysis.experiment import Experiment from mozanalysis.bq import BigQueryContext - from mozanalysis.metrics.desktop import active_hours, uri_count + from mozanalysis.config import ConfigLoader + + active_hours = ConfigLoader.get_metric("active_hours", "firefox_desktop") + uri_count = ConfigLoader.get_metric("uri_count", "firefox_desktop") bq_context = BigQueryContext( dataset_id='your-dataset-id', # e.g. mine's flawrence diff --git a/src/mozanalysis/metrics/__init__.py b/src/mozanalysis/metrics.py similarity index 96% rename from src/mozanalysis/metrics/__init__.py rename to src/mozanalysis/metrics.py index bd82ea2..ad5bf18 100644 --- a/src/mozanalysis/metrics/__init__.py +++ b/src/mozanalysis/metrics.py @@ -10,30 +10,11 @@ if TYPE_CHECKING: from mozanalysis.experiment import TimeLimits import logging -import warnings import attr logger = logging.getLogger(__name__) -warnings.simplefilter("default") -warnings.warn( - """ - metrics and data sources created in mozanalysis are deprecated - please create directly from metric-hub with ConfigLoader like - - from mozanalysis.config import ConfigLoader - metric=ConfigLoader.get_metric(metric_slug="active_hours",app_name="firefox_desktop") - - and data sources like - data_source=ConfigLoader.get_data_source(data_source_slug="active_hours", - app_name="firefox_desktop") - - """, - DeprecationWarning, - stacklevel=1, -) - class AnalysisBasis(Enum): """Determines what the population used for the analysis will be based on.""" diff --git a/src/mozanalysis/metrics/desktop.py b/src/mozanalysis/metrics/desktop.py deleted file mode 100644 index 45a6f63..0000000 --- a/src/mozanalysis/metrics/desktop.py +++ /dev/null @@ -1,82 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -# These metric definitions are deprecated. -# Instead use the metric slug to reference metrics defined -# in https://github.com/mozilla/metric-hub - -from mozanalysis.config import ConfigLoader - -clients_daily = ConfigLoader.get_data_source("clients_daily", "firefox_desktop") - -search_clients_engines_sources_daily = ConfigLoader.get_data_source( - "search_clients_engines_sources_daily", "firefox_desktop" -) - -search_clients_daily = search_clients_engines_sources_daily - -main_summary = ConfigLoader.get_data_source("main_summary", "firefox_desktop") - -events = ConfigLoader.get_data_source("events", "firefox_desktop") - -normandy_events = ConfigLoader.get_data_source("normandy_events", "firefox_desktop") - -main = ConfigLoader.get_data_source("main", "firefox_desktop") - -crash = ConfigLoader.get_data_source("crash", "firefox_desktop") - -cfr = ConfigLoader.get_data_source("cfr", "firefox_desktop") - -activity_stream_events = ConfigLoader.get_data_source( - "activity_stream_events", "firefox_desktop" -) - - -active_hours = ConfigLoader.get_metric("active_hours", "firefox_desktop") - -uri_count = ConfigLoader.get_metric("uri_count", "firefox_desktop") - -search_count = ConfigLoader.get_metric("search_count", "firefox_desktop") - -tagged_search_count = ConfigLoader.get_metric("tagged_search_count", "firefox_desktop") - -tagged_follow_on_search_count = ConfigLoader.get_metric( - "tagged_follow_on_search_count", "firefox_desktop" -) - -ad_clicks = ConfigLoader.get_metric("ad_clicks", "firefox_desktop") - -searches_with_ads = ConfigLoader.get_metric("searches_with_ads", "firefox_desktop") - -organic_search_count = ConfigLoader.get_metric( - "organic_search_count", "firefox_desktop" -) - -unenroll = ConfigLoader.get_metric("unenroll", "firefox_desktop") - -view_about_logins = ConfigLoader.get_metric("view_about_logins", "firefox_desktop") - -view_about_protections = ConfigLoader.get_metric( - "view_about_protections", "firefox_desktop" -) - -connect_fxa = ConfigLoader.get_metric("connect_fxa", "firefox_desktop") - -pocket_rec_clicks = ConfigLoader.get_metric("pocket_rec_clicks", "firefox_desktop") - -pocket_spoc_clicks = ConfigLoader.get_metric("pocket_spoc_clicks", "firefox_desktop") - -days_of_use = ConfigLoader.get_metric("days_of_use", "firefox_desktop") - -qualified_cumulative_days_of_use = ConfigLoader.get_metric( - "qualified_cumulative_days_of_use", "firefox_desktop" -) - -disable_pocket_clicks = ConfigLoader.get_metric( - "disable_pocket_clicks", "firefox_desktop" -) - -disable_pocket_spocs_clicks = ConfigLoader.get_metric( - "disable_pocket_spocs_clicks", "firefox_desktop" -) diff --git a/src/mozanalysis/metrics/fenix.py b/src/mozanalysis/metrics/fenix.py deleted file mode 100644 index 1365964..0000000 --- a/src/mozanalysis/metrics/fenix.py +++ /dev/null @@ -1,30 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -# These metric definitions are deprecated. -# Instead use the metric slug to reference metrics defined -# in https://github.com/mozilla/metric-hub - -from mozanalysis.config import ConfigLoader - -baseline = ConfigLoader.get_data_source("baseline", "fenix") - -events = ConfigLoader.get_data_source("events", "fenix") - -metrics = ConfigLoader.get_data_source("metrics", "fenix") - - -uri_count = ConfigLoader.get_metric("uri_count", "fenix") - -user_reports_site_issue_count = ConfigLoader.get_metric( - "user_reports_site_issue_count", "fenix" -) - -user_reload_count = ConfigLoader.get_metric("user_reload_count", "fenix") - -baseline_ping_count = ConfigLoader.get_metric("baseline_ping_count", "fenix") - -metric_ping_count = ConfigLoader.get_metric("metric_ping_count", "fenix") - -first_run_date = ConfigLoader.get_metric("first_run_date", "fenix") diff --git a/src/mozanalysis/metrics/firefox_ios.py b/src/mozanalysis/metrics/firefox_ios.py deleted file mode 100644 index b2522f7..0000000 --- a/src/mozanalysis/metrics/firefox_ios.py +++ /dev/null @@ -1,21 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -# These metric definitions are deprecated. -# Instead use the metric slug to reference metrics defined -# in https://github.com/mozilla/metric-hub - -from mozanalysis.config import ConfigLoader - -baseline = ConfigLoader.get_data_source("baseline", "firefox_ios") - -events = ConfigLoader.get_data_source("events", "firefox_ios") - -metrics = ConfigLoader.get_data_source("metrics", "firefox_ios") - -baseline_ping_count = ConfigLoader.get_metric("baseline_ping_count", "firefox_ios") - -metric_ping_count = ConfigLoader.get_metric("metric_ping_count", "firefox_ios") - -first_run_date = ConfigLoader.get_metric("first_run_date", "firefox_ios") diff --git a/src/mozanalysis/metrics/focus_android.py b/src/mozanalysis/metrics/focus_android.py deleted file mode 100644 index c506d3c..0000000 --- a/src/mozanalysis/metrics/focus_android.py +++ /dev/null @@ -1,21 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -# These metric definitions are deprecated. -# Instead use the metric slug to reference metrics defined -# in https://github.com/mozilla/metric-hub - -from mozanalysis.config import ConfigLoader - -baseline = ConfigLoader.get_data_source("baseline", "focus_android") - -events = ConfigLoader.get_data_source("events", "focus_android") - -metrics = ConfigLoader.get_data_source("metrics", "focus_android") - -baseline_ping_count = ConfigLoader.get_metric("baseline_ping_count", "focus_android") - -metric_ping_count = ConfigLoader.get_metric("metric_ping_count", "focus_android") - -first_run_date = ConfigLoader.get_metric("first_run_date", "focus_android") diff --git a/src/mozanalysis/metrics/focus_ios.py b/src/mozanalysis/metrics/focus_ios.py deleted file mode 100644 index 78f0adf..0000000 --- a/src/mozanalysis/metrics/focus_ios.py +++ /dev/null @@ -1,21 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -# These metric definitions are deprecated. -# Instead use the metric slug to reference metrics defined -# in https://github.com/mozilla/metric-hub - -from mozanalysis.config import ConfigLoader - -baseline = ConfigLoader.get_data_source("baseline", "focus_ios") - -events = ConfigLoader.get_data_source("events", "focus_ios") - -metrics = ConfigLoader.get_data_source("metrics", "focus_ios") - -baseline_ping_count = ConfigLoader.get_metric("baseline_ping_count", "focus_ios") - -metric_ping_count = ConfigLoader.get_metric("metric_ping_count", "focus_ios") - -first_run_date = ConfigLoader.get_metric("first_run_date", "focus_ios") diff --git a/src/mozanalysis/metrics/klar_android.py b/src/mozanalysis/metrics/klar_android.py deleted file mode 100644 index 5fda7a2..0000000 --- a/src/mozanalysis/metrics/klar_android.py +++ /dev/null @@ -1,22 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -# These metric definitions are deprecated. -# Instead use the metric slug to reference metrics defined -# in https://github.com/mozilla/metric-hub - -from mozanalysis.config import ConfigLoader - -baseline = ConfigLoader.get_data_source("baseline", "klar_android") - -events = ConfigLoader.get_data_source("events", "klar_android") - -metrics = ConfigLoader.get_data_source("metrics", "klar_android") - - -baseline_ping_count = ConfigLoader.get_metric("baseline_ping_count", "klar_android") - -metric_ping_count = ConfigLoader.get_metric("metric_ping_count", "klar_android") - -first_run_date = ConfigLoader.get_metric("first_run_date", "klar_android") diff --git a/src/mozanalysis/metrics/klar_ios.py b/src/mozanalysis/metrics/klar_ios.py deleted file mode 100644 index 70fab05..0000000 --- a/src/mozanalysis/metrics/klar_ios.py +++ /dev/null @@ -1,21 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -# These metric definitions are deprecated. -# Instead use the metric slug to reference metrics defined -# in https://github.com/mozilla/metric-hub - -from mozanalysis.config import ConfigLoader - -baseline = ConfigLoader.get_data_source("baseline", "klar_ios") - -events = ConfigLoader.get_data_source("events", "klar_ios") - -metrics = ConfigLoader.get_data_source("metrics", "klar_ios") - -baseline_ping_count = ConfigLoader.get_metric("baseline_ping_count", "klar_ios") - -metric_ping_count = ConfigLoader.get_metric("metric_ping_count", "klar_ios") - -first_run_date = ConfigLoader.get_metric("first_run_date", "klar_ios") diff --git a/src/mozanalysis/segments/__init__.py b/src/mozanalysis/segments.py similarity index 92% rename from src/mozanalysis/segments/__init__.py rename to src/mozanalysis/segments.py index bc5ca89..adc89de 100644 --- a/src/mozanalysis/segments/__init__.py +++ b/src/mozanalysis/segments.py @@ -2,29 +2,8 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -import warnings - import attr -warnings.simplefilter("default") -warnings.warn( - """ - segments and segment data source objects created in mozanalysis are deprecated - please create directly from metric-hub with ConfigLoader like - - from mozanalysis.config import ConfigLoader - segment=ConfigLoader.get_segment(segment_slug="regular_users_v3", - app_name="firefox_desktop") - - and data sources like - segment_data_source=ConfigLoader.get_segment_data_source("clients_last_seen", - "firefox_desktop") - - """, - DeprecationWarning, - stacklevel=1, -) - @attr.s(frozen=True, slots=True) class SegmentDataSource: diff --git a/src/mozanalysis/segments/desktop.py b/src/mozanalysis/segments/desktop.py deleted file mode 100644 index 7b56371..0000000 --- a/src/mozanalysis/segments/desktop.py +++ /dev/null @@ -1,26 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -# These segment definitions are deprecated. -# Instead use the segment slug to reference segments defined -# in https://github.com/mozilla/metric-hub - -from mozanalysis.config import ConfigLoader - -clients_last_seen = ConfigLoader.get_segment_data_source( - "clients_last_seen", "firefox_desktop" -) - - -regular_users_v3 = ConfigLoader.get_segment("regular_users_v3", "firefox_desktop") - -new_or_resurrected_v3 = ConfigLoader.get_segment( - "new_or_resurrected_v3", "firefox_desktop" -) - -weekday_regular_v1 = ConfigLoader.get_segment("weekday_regular_v1", "firefox_desktop") - -allweek_regular_v1 = ConfigLoader.get_segment("allweek_regular_v1", "firefox_desktop") - -new_unique_profiles = ConfigLoader.get_segment("new_unique_profiles", "firefox_desktop") diff --git a/src/mozanalysis/sizing.py b/src/mozanalysis/sizing.py index 9c4e2de..f02019a 100644 --- a/src/mozanalysis/sizing.py +++ b/src/mozanalysis/sizing.py @@ -38,9 +38,15 @@ class HistoricalTarget: auth.authenticate_user() print('Authenticated') - from mozanalysis.metrics.desktop import active_hours, uri_count - from mozanalysis.segments.desktop import allweek_regular_v1, \ - new_or_resurrected_v3 + from mozanalysis.config import ConfigLoader + + active_hours = ConfigLoader.get_metric("active_hours", "firefox_desktop") + uri_count = ConfigLoader.get_metric("uri_count", "firefox_desktop") + + new_or_resurrected_v3 = ConfigLoader.get_segment("new_or_resurrected_v3", + "firefox_desktop") + allweek_regular_v1 = ConfigLoader.get_segment("allweek_regular_v1", + "firefox_desktop") bq_context = BigQueryContext( dataset_id='mbowerman', # e.g. mine's mbowerman diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index bfcae0e..0000000 --- a/tests/__init__.py +++ /dev/null @@ -1,12 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - - -def enumerate_included(modules, klass): - collected = [] - for module in modules: - collected.extend( - [(k, v) for k, v in module.__dict__.items() if isinstance(v, klass)] - ) - return collected diff --git a/tests/conftest.py b/tests/conftest.py index 5fd24c3..88f5148 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,10 +2,6 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. import logging -import os -import sys - -sys.path.append(os.path.join(os.path.dirname(__file__), "helpers")) def pytest_configure(): diff --git a/tests/frequentist_stats/test_sample_size_calc.py b/tests/frequentist_stats/test_sample_size_calc.py index 4eef19a..01011e7 100644 --- a/tests/frequentist_stats/test_sample_size_calc.py +++ b/tests/frequentist_stats/test_sample_size_calc.py @@ -6,12 +6,17 @@ from dataclasses import dataclass import numpy as np import pandas as pd import pytest +from mozanalysis.config import ConfigLoader from mozanalysis.frequentist_stats.sample_size import ( empirical_effect_size_sample_size_calc, sample_size_curves, z_or_t_ind_sample_size_calc, ) -from mozanalysis.metrics.desktop import search_clients_daily, uri_count + +search_clients_daily = ConfigLoader.get_data_source( + "search_clients_engines_sources_daily", "firefox_desktop" +) +uri_count = ConfigLoader.get_metric("uri_count", "firefox_desktop") @pytest.fixture() diff --git a/tests/helpers/config_loader_lists.py b/tests/helpers/config_loader_lists.py new file mode 100644 index 0000000..e867153 --- /dev/null +++ b/tests/helpers/config_loader_lists.py @@ -0,0 +1,58 @@ +from mozanalysis.config import ConfigLoader + +desktop_segments = [ + ConfigLoader.get_segment("regular_users_v3", "firefox_desktop"), + ConfigLoader.get_segment("new_or_resurrected_v3", "firefox_desktop"), + ConfigLoader.get_segment("weekday_regular_v1", "firefox_desktop"), + ConfigLoader.get_segment("allweek_regular_v1", "firefox_desktop"), + ConfigLoader.get_segment("new_unique_profiles", "firefox_desktop"), +] + +desktop_metrics = [ + ConfigLoader.get_metric("active_hours", "firefox_desktop"), + ConfigLoader.get_metric("uri_count", "firefox_desktop"), + ConfigLoader.get_metric("search_count", "firefox_desktop"), + ConfigLoader.get_metric("tagged_search_count", "firefox_desktop"), + ConfigLoader.get_metric("tagged_follow_on_search_count", "firefox_desktop"), + ConfigLoader.get_metric("ad_clicks", "firefox_desktop"), + ConfigLoader.get_metric("searches_with_ads", "firefox_desktop"), + ConfigLoader.get_metric("organic_search_count", "firefox_desktop"), + ConfigLoader.get_metric("unenroll", "firefox_desktop"), + ConfigLoader.get_metric("view_about_logins", "firefox_desktop"), + ConfigLoader.get_metric("view_about_protections", "firefox_desktop"), + ConfigLoader.get_metric("connect_fxa", "firefox_desktop"), + ConfigLoader.get_metric("pocket_rec_clicks", "firefox_desktop"), + ConfigLoader.get_metric("pocket_spoc_clicks", "firefox_desktop"), + ConfigLoader.get_metric("days_of_use", "firefox_desktop"), + ConfigLoader.get_metric("qualified_cumulative_days_of_use", "firefox_desktop"), + ConfigLoader.get_metric("disable_pocket_clicks", "firefox_desktop"), + ConfigLoader.get_metric("disable_pocket_spocs_clicks", "firefox_desktop"), +] + +fenix_metrics = [ + ConfigLoader.get_metric("uri_count", "fenix"), + ConfigLoader.get_metric("user_reports_site_issue_count", "fenix"), + ConfigLoader.get_metric("user_reload_count", "fenix"), + ConfigLoader.get_metric("baseline_ping_count", "fenix"), + ConfigLoader.get_metric("metric_ping_count", "fenix"), + ConfigLoader.get_metric("first_run_date", "fenix"), +] + + +firefox_ios_metrics = [ + ConfigLoader.get_metric("baseline_ping_count", "firefox_ios"), + ConfigLoader.get_metric("metric_ping_count", "firefox_ios"), + ConfigLoader.get_metric("first_run_date", "firefox_ios"), +] + +klar_android_metrics = [ + ConfigLoader.get_metric("baseline_ping_count", "klar_android"), + ConfigLoader.get_metric("metric_ping_count", "klar_android"), + ConfigLoader.get_metric("first_run_date", "klar_android"), +] + +klar_ios_metrics = [ + ConfigLoader.get_metric("baseline_ping_count", "klar_ios"), + ConfigLoader.get_metric("metric_ping_count", "klar_ios"), + ConfigLoader.get_metric("first_run_date", "klar_ios"), +] diff --git a/tests/test_config.py b/tests/test_config.py index f79b20d..c692418 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -3,7 +3,7 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. import pytest -from cheap_lint import sql_lint +from helpers.cheap_lint import sql_lint # local helper file from mozanalysis.config import ConfigLoader from mozanalysis.metrics import DataSource, Metric from mozanalysis.segments import Segment, SegmentDataSource diff --git a/tests/test_experiment.py b/tests/test_experiment.py index f2d9bdb..670ee4d 100644 --- a/tests/test_experiment.py +++ b/tests/test_experiment.py @@ -1,11 +1,14 @@ -import mozanalysis.metrics.desktop as mad -import mozanalysis.metrics.fenix -import mozanalysis.metrics.firefox_ios -import mozanalysis.metrics.klar_android -import mozanalysis.metrics.klar_ios -import mozanalysis.segments.desktop as msd import pytest -from cheap_lint import sql_lint +from helpers.cheap_lint import sql_lint # local helper file +from helpers.config_loader_lists import ( + desktop_metrics, + desktop_segments, + fenix_metrics, + firefox_ios_metrics, + klar_android_metrics, + klar_ios_metrics, +) +from mozanalysis.config import ConfigLoader from mozanalysis.experiment import ( AnalysisWindow, EnrollmentsQueryType, @@ -319,7 +322,7 @@ def test_megaquery_not_detectably_malformed(): sql_lint(enrollments_sql) metrics_sql = exp.build_metrics_query( - metric_list=[m for m in mad.__dict__.values() if isinstance(m, Metric)], + metric_list=desktop_metrics, time_limits=tl, enrollments_table="enrollments", ) @@ -339,14 +342,14 @@ def test_segments_megaquery_not_detectably_malformed(): enrollments_sql = exp.build_enrollments_query( time_limits=tl, - segment_list=[s for s in msd.__dict__.values() if isinstance(s, Segment)], + segment_list=desktop_segments, enrollments_query_type=EnrollmentsQueryType.NORMANDY, ) sql_lint(enrollments_sql) metrics_sql = exp.build_metrics_query( - metric_list=[m for m in mad.__dict__.values() if isinstance(m, Metric)], + metric_list=desktop_metrics, time_limits=tl, enrollments_table="enrollments", ) @@ -385,11 +388,7 @@ def test_app_id_propagates(): sql_lint(enrollments_sql) metrics_sql = exp.build_metrics_query( - metric_list=[ - m - for m in mozanalysis.metrics.fenix.__dict__.values() - if isinstance(m, Metric) - ], + metric_list=fenix_metrics, time_limits=tl, enrollments_table="enrollments", ) @@ -460,11 +459,7 @@ def test_firefox_ios_app_id_propagation(): sql_lint(enrollments_sql) metrics_sql = exp.build_metrics_query( - metric_list=[ - m - for m in mozanalysis.metrics.firefox_ios.__dict__.values() - if isinstance(m, Metric) - ], + metric_list=firefox_ios_metrics, time_limits=tl, enrollments_table="enrollments", ) @@ -508,11 +503,7 @@ def test_firefox_klar_app_id_propagation(): sql_lint(enrollments_sql) metrics_sql = exp.build_metrics_query( - metric_list=[ - m - for m in mozanalysis.metrics.klar_android.__dict__.values() - if isinstance(m, Metric) - ], + metric_list=klar_android_metrics, time_limits=tl, enrollments_table="enrollments", ) @@ -556,11 +547,7 @@ def test_firefox_ios_klar_app_id_propagation(): sql_lint(enrollments_sql) metrics_sql = exp.build_metrics_query( - metric_list=[ - m - for m in mozanalysis.metrics.klar_ios.__dict__.values() - if isinstance(m, Metric) - ], + metric_list=klar_ios_metrics, time_limits=tl, enrollments_table="enrollments", ) @@ -631,7 +618,7 @@ def test_exposure_signal_query(): enrollments_query_type=EnrollmentsQueryType.GLEAN_EVENT, exposure_signal=ExposureSignal( name="exposures", - data_source=mozanalysis.metrics.fenix.baseline, + data_source=ConfigLoader.get_data_source("baseline", "fenix"), select_expr="metrics.counter.events_total_uri_count > 0", friendly_name="URI visited exposure", description="Exposed when URI visited", @@ -659,7 +646,7 @@ def test_exposure_signal_query_custom_windows(): enrollments_query_type=EnrollmentsQueryType.GLEAN_EVENT, exposure_signal=ExposureSignal( name="exposures", - data_source=mozanalysis.metrics.fenix.baseline, + data_source=ConfigLoader.get_data_source("baseline", "fenix"), select_expr="metrics.counter.events_total_uri_count > 0", friendly_name="URI visited exposure", description="Exposed when URI visited", @@ -693,11 +680,7 @@ def test_metrics_query_based_on_exposure(): sql_lint(enrollments_sql) metrics_sql = exp.build_metrics_query( - metric_list=[ - m - for m in mozanalysis.metrics.fenix.__dict__.values() - if isinstance(m, Metric) - ], + metric_list=fenix_metrics, time_limits=tl, enrollments_table="enrollments", analysis_basis=AnalysisBasis.EXPOSURES, @@ -725,17 +708,13 @@ def test_metrics_query_with_exposure_signal_custom_windows(): sql_lint(enrollments_sql) metrics_sql = exp.build_metrics_query( - metric_list=[ - m - for m in mozanalysis.metrics.fenix.__dict__.values() - if isinstance(m, Metric) - ], + metric_list=fenix_metrics, time_limits=tl, enrollments_table="enrollments", analysis_basis=AnalysisBasis.EXPOSURES, exposure_signal=ExposureSignal( name="exposures", - data_source=mozanalysis.metrics.fenix.baseline, + data_source=ConfigLoader.get_data_source("baseline", "fenix"), select_expr="metrics.counter.events_total_uri_count > 0", friendly_name="URI visited exposure", description="Exposed when URI visited", @@ -767,17 +746,13 @@ def test_metrics_query_with_exposure_signal(): sql_lint(enrollments_sql) metrics_sql = exp.build_metrics_query( - metric_list=[ - m - for m in mozanalysis.metrics.fenix.__dict__.values() - if isinstance(m, Metric) - ], + metric_list=fenix_metrics, time_limits=tl, enrollments_table="enrollments", analysis_basis=AnalysisBasis.EXPOSURES, exposure_signal=ExposureSignal( name="exposures", - data_source=mozanalysis.metrics.fenix.baseline, + data_source=ConfigLoader.get_data_source("baseline", "fenix"), select_expr="metrics.counter.events_total_uri_count > 0", friendly_name="URI visited exposure", description="Exposed when URI visited", diff --git a/tests/test_metric_libraries.py b/tests/test_metric_libraries.py deleted file mode 100644 index 4107f98..0000000 --- a/tests/test_metric_libraries.py +++ /dev/null @@ -1,51 +0,0 @@ -import mozanalysis.metrics.desktop as mmd -import mozanalysis.metrics.fenix as mmf -import mozanalysis.metrics.firefox_ios as mmios -import mozanalysis.metrics.focus_android as mmfoc -import mozanalysis.metrics.focus_ios as iosfoc -import mozanalysis.metrics.klar_android as mmk -import mozanalysis.metrics.klar_ios as iosk -import pytest -from cheap_lint import sql_lint -from mozanalysis.metrics import DataSource, Metric - -from . import enumerate_included - - -def test_imported_ok(): - assert mmd.active_hours - assert mmf.uri_count - assert mmios.baseline_ping_count - assert mmfoc.metric_ping_count - assert iosfoc.metric_ping_count - assert mmk.baseline_ping_count - assert iosk.baseline_ping_count - - -@pytest.fixture() -def included_metrics(): - return enumerate_included((mmd, mmf, mmios, mmk, mmfoc), Metric) - - -@pytest.fixture() -def included_datasources(): - return enumerate_included((mmd, mmf, mmios, mmk, mmfoc), DataSource) - - -def test_sql_not_detectably_malformed(included_metrics, included_datasources): - for _, m in included_metrics: - sql_lint(m.select_expr.format(experiment_slug="slug")) - - for _, ds in included_datasources: - sql_lint(ds.from_expr_for(None)) - - -def test_consistency_of_metric_and_variable_names(included_metrics): - for name, metric in included_metrics: - assert name == metric.name, metric - - -def test_included_metrics_have_docs(included_metrics): - for _, m in included_metrics: - assert m.friendly_name, m.name - assert m.description, m.name diff --git a/tests/test_segment_libraries.py b/tests/test_segment_libraries.py deleted file mode 100644 index 82d2f68..0000000 --- a/tests/test_segment_libraries.py +++ /dev/null @@ -1,105 +0,0 @@ -import mozanalysis.metrics.desktop as mmd -import mozanalysis.segments.desktop as msd -import pytest -from cheap_lint import sql_lint -from mozanalysis.segments import Segment, SegmentDataSource - -from . import enumerate_included - - -@pytest.fixture() -def included_segments(): - return enumerate_included((msd,), Segment) - - -@pytest.fixture() -def included_segment_datasources(): - return enumerate_included((msd,), SegmentDataSource) - - -def test_imported_ok(): - assert msd.regular_users_v3 - - -def test_sql_not_detectably_malformed(included_segments, included_segment_datasources): - for _name, s in included_segments: - sql_lint(s.select_expr) - - for _name, sds in included_segment_datasources: - sql_lint(sds.from_expr_for(None)) - - -def test_consistency_of_segment_and_variable_names(included_segments): - for name, segment in included_segments: - assert name == segment.name, segment - - -def test_segment_data_source_window_end_validates(): - SegmentDataSource( - name="bla", - from_expr="bla", - window_start=0, - window_end=0, - ) - - SegmentDataSource( - name="bla", - from_expr="bla", - window_start=0, - window_end=1, - ) - - SegmentDataSource( - name="bla", - from_expr="bla", - window_start=1, - window_end=3, - ) - - -def test_segment_data_source_window_start_validates(): - SegmentDataSource( - name="bla", - from_expr="bla", - window_start=-1, - window_end=-1, - ) - - with pytest.raises(ValueError, match="window_start must be <= window_end"): - SegmentDataSource( - name="bla", - from_expr="bla", - window_start=0, - window_end=-1, - ) - - -def test_segment_validates_not_metric_data_source(): - with pytest.raises(TypeError): - Segment( - name="bla", - data_source=mmd.clients_daily, - select_expr="bla", - ) - - -def test_included_segments_have_docs(included_segments): - for name, segment in included_segments: - assert segment.friendly_name - assert segment.description, name - - -def test_complains_about_template_without_default(): - with pytest.raises( - ValueError, - match="foo: from_expr contains a dataset template but no value was provided.", - ): - SegmentDataSource( - name="foo", - from_expr="moz-fx-data-shared-prod.{dataset}.foo", - ) - SegmentDataSource( - name="foo", - from_expr="moz-fx-data-shared-prod.{dataset}.foo", - default_dataset="dataset", - ) diff --git a/tests/test_sizing.py b/tests/test_sizing.py index 69127ce..ce0d8d6 100644 --- a/tests/test_sizing.py +++ b/tests/test_sizing.py @@ -1,8 +1,7 @@ -import mozanalysis.metrics.desktop as mad -import mozanalysis.segments.desktop as msd import pandas as pd import pytest -from cheap_lint import sql_lint +from helpers.cheap_lint import sql_lint # local helper file +from helpers.config_loader_lists import desktop_metrics, desktop_segments from mozanalysis.config import ConfigLoader from mozanalysis.experiment import TimeLimits from mozanalysis.metrics import DataSource, Metric @@ -139,7 +138,11 @@ def test_multiple_datasource(): test_seg = Segment("test_seg", test_sds, "TEST AGG SELECT STATEMENT", "", "") target_sql = test_target.build_targets_query( - time_limits=tl, target_list=[msd.new_unique_profiles, test_seg] + time_limits=tl, + target_list=[ + ConfigLoader.get_segment("new_unique_profiles", "firefox_desktop"), + test_seg, + ], ) sql_lint(target_sql) @@ -158,7 +161,10 @@ def test_query_not_detectably_malformed(): ) target_sql = test_target.build_targets_query( - time_limits=tl, target_list=[msd.new_unique_profiles] + time_limits=tl, + target_list=[ + ConfigLoader.get_segment("new_unique_profiles", "firefox_desktop") + ], ) sql_lint(target_sql) @@ -182,18 +188,18 @@ def test_megaquery_not_detectably_malformed(): target_sql = test_target.build_targets_query( time_limits=tl, - target_list=[s for s in msd.__dict__.values() if isinstance(s, Segment)], + target_list=desktop_segments, ) sql_lint(target_sql) + desktop_metrics_no_experiment_slug = [ + m for m in desktop_metrics if "experiment_slug" not in m.select_expr + ] + metrics_sql = test_target.build_metrics_query( time_limits=tl, - metric_list=[ - m - for m in mad.__dict__.values() - if isinstance(m, Metric) and "experiment_slug" not in m.select_expr - ], + metric_list=desktop_metrics_no_experiment_slug, targets_table="targets", )