ashb commented on code in PR #58188:
URL: https://github.com/apache/airflow/pull/58188#discussion_r2514815907


##########
airflow-core/tests/unit/core/test_configuration.py:
##########
@@ -1105,6 +1105,86 @@ def test_order_of_secrets_backends_and_kwargs_on_workers(
             for key, value in expected_backend_kwargs.items():
                 assert getattr(secrets_backend, key) == value
 
+    def test_default_validators(self):
+        """Test that _validators property returns default validators."""
+        test_conf = AirflowConfigParser(default_config="")
+        validators = test_conf._validators
+
+        assert len(validators) == 4
+        expected_validators = [
+            "_validate_sqlite3_version",
+            "_validate_enums",
+            "_validate_deprecated_values",
+            "_upgrade_postgres_metastore_conn",
+        ]
+        assert [v.__name__ for v in validators] == expected_validators

Review Comment:
   Same comment as on the other PR -- I don't think this test adds anything 
other than a second place to update with identical code.



##########
airflow-core/tests/unit/core/test_configuration.py:
##########
@@ -1105,6 +1105,86 @@ def test_order_of_secrets_backends_and_kwargs_on_workers(
             for key, value in expected_backend_kwargs.items():
                 assert getattr(secrets_backend, key) == value
 
+    def test_default_validators(self):
+        """Test that _validators property returns default validators."""
+        test_conf = AirflowConfigParser(default_config="")
+        validators = test_conf._validators
+
+        assert len(validators) == 4
+        expected_validators = [
+            "_validate_sqlite3_version",
+            "_validate_enums",
+            "_validate_deprecated_values",
+            "_upgrade_postgres_metastore_conn",
+        ]
+        assert [v.__name__ for v in validators] == expected_validators
+
+    def test_validate_sets_is_validated_flag(self):
+        """Test that validate() sets is_validated to True."""
+        test_conf = AirflowConfigParser(default_config="")
+        assert test_conf.is_validated is False
+        test_conf.validate()
+        assert test_conf.is_validated is True
+
+    def test_validators_can_be_overridden_in_subclass(self):
+        """Test that subclasses can override _validators to customize 
validation."""
+
+        class CustomConfigParser(AirflowConfigParser):
+            @property
+            def _validators(self):
+                return [self._validate_enums]
+
+        test_conf = CustomConfigParser(default_config="")
+        validators = test_conf._validators
+        assert len(validators) == 1
+        assert validators[0].__name__ == "_validate_enums"
+
+    def test_validate_exception_is_handled(self):
+        """Test that exceptions from validators bubble up and is_validated 
remains False."""
+
+        class FailingValidatorsParser(AirflowConfigParser):
+            def failing_validator(self):
+                raise AirflowConfigException("Test validator failure")
+
+            @property
+            def _validators(self):
+                return [self.failing_validator]
+
+        failing_conf = FailingValidatorsParser(default_config="")
+        assert failing_conf.is_validated is False
+
+        with pytest.raises(AirflowConfigException, match="Test validator 
failure"):
+            failing_conf.validate()
+        assert failing_conf.is_validated is False
+
+    def test_validate_is_idempotent(self):
+        """Test that running validate() multiple times is idempotent."""
+        test_conf = AirflowConfigParser(default_config="")
+
+        test_conf.deprecated_values = {
+            "core": {"executor": (re.compile(re.escape("SequentialExecutor")), 
"LocalExecutor")},
+        }
+        test_conf.read_dict({"core": {"executor": "SequentialExecutor"}})
+
+        # first pass at validation
+        test_conf.validate()
+        assert test_conf.is_validated is True
+        first_upgraded_values = dict(test_conf.upgraded_values)
+
+        # deprecated value should be upgraded
+        assert ("core", "executor") in first_upgraded_values
+        assert first_upgraded_values[("core", "executor")] == 
"SequentialExecutor"
+
+        # second pass at validation
+        test_conf.validate()
+        assert test_conf.is_validated is True
+
+        # previously upgraded values should remain the same, no re-upgrade
+        second_upgraded_values = dict(test_conf.upgraded_values)
+        assert first_upgraded_values == second_upgraded_values
+
+        assert test_conf.get("core", "executor") == "LocalExecutor"

Review Comment:
   I don't quite see what this is testing?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to