diff --git a/pipeline/features.py b/pipeline/features.py index 5ad4fe5..a007ca6 100644 --- a/pipeline/features.py +++ b/pipeline/features.py @@ -3,21 +3,28 @@ from types import SimpleNamespace -# The version of `project.yaml` where each feature was introduced +# The versions of `project.yaml` where each feature applies to +# Tuple of (version where the feature was introduced, version after which the feature is deprecated) FEATURE_FLAGS_BY_VERSION = { - "UNIQUE_OUTPUT_PATH": 2, - "EXPECTATIONS_POPULATION": 3, + "UNIQUE_OUTPUT_PATH": (2, None), + "EXPECTATIONS_POPULATION": (3, 3), + "REMOVE_SUPPORT_FOR_COHORT_EXTRACTOR": (4, None), } - -LATEST_VERSION = max(FEATURE_FLAGS_BY_VERSION.values()) +LATEST_VERSION = max([v[0] for v in FEATURE_FLAGS_BY_VERSION.values()]) def get_feature_flags_for_version(version: float) -> SimpleNamespace: + if version > LATEST_VERSION: + raise ValueError(f"The latest version is v{LATEST_VERSION}, but got v{version}") feat = SimpleNamespace() for k, v in FEATURE_FLAGS_BY_VERSION.items(): - value = v <= version # is this feature turned on the requested version? + # is this feature turned on the requested version? + if v[1] is None: + value = v[0] <= version + else: + value = v[0] <= version <= v[1] setattr(feat, k, value) diff --git a/tests/test_features.py b/tests/test_features.py index 019399a..5f44dfd 100644 --- a/tests/test_features.py +++ b/tests/test_features.py @@ -1,3 +1,5 @@ +import pytest + from pipeline.features import get_feature_flags_for_version @@ -6,6 +8,7 @@ def test_get_feature_flags_for_version_with_v1(): assert not flags.UNIQUE_OUTPUT_PATH assert not flags.EXPECTATIONS_POPULATION + assert not flags.REMOVE_SUPPORT_FOR_COHORT_EXTRACTOR def test_get_feature_flags_for_version_with_v2(): @@ -13,6 +16,7 @@ def test_get_feature_flags_for_version_with_v2(): assert flags.UNIQUE_OUTPUT_PATH assert not flags.EXPECTATIONS_POPULATION + assert not flags.REMOVE_SUPPORT_FOR_COHORT_EXTRACTOR def test_get_feature_flags_for_version_with_v3(): @@ -20,3 +24,18 @@ def test_get_feature_flags_for_version_with_v3(): assert flags.UNIQUE_OUTPUT_PATH assert flags.EXPECTATIONS_POPULATION + assert not flags.REMOVE_SUPPORT_FOR_COHORT_EXTRACTOR + + +def test_get_feature_flags_for_version_with_v4(): + flags = get_feature_flags_for_version(4) + + assert flags.UNIQUE_OUTPUT_PATH + assert not flags.EXPECTATIONS_POPULATION + assert flags.REMOVE_SUPPORT_FOR_COHORT_EXTRACTOR + + +def test_get_feature_flags_for_version_with_v5(): + msg = "The latest version is v4, but got v5" + with pytest.raises(ValueError, match=msg): + get_feature_flags_for_version(5)