dirrao commented on code in PR #38223:
URL: https://github.com/apache/airflow/pull/38223#discussion_r1527400146


##########
tests/providers/cncf/kubernetes/operators/test_custom_object_launcher.py:
##########
@@ -14,3 +14,122 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+from unittest.mock import patch
+
+import pytest
+
+from airflow.exceptions import AirflowException
+from airflow.providers.cncf.kubernetes.operators.custom_object_launcher import 
(
+    SparkJobSpec,
+    SparkResources,
+)
+
+
+class TestSparkJobSpec:
+    
@patch("airflow.providers.cncf.kubernetes.operators.custom_object_launcher.SparkJobSpec.update_resources")
+    
@patch("airflow.providers.cncf.kubernetes.operators.custom_object_launcher.SparkJobSpec.validate")
+    def test_spark_job_spec_initialization(self, mock_validate, 
mock_update_resources):
+        entries = {
+            "spec": {
+                "dynamicAllocation": {
+                    "enabled": True,
+                    "initialExecutors": 1,
+                    "minExecutors": 1,
+                    "maxExecutors": 2,
+                },
+                "driver": {},
+                "executor": {},
+            }
+        }
+        SparkJobSpec(**entries)
+        mock_validate.assert_called_once()
+        mock_update_resources.assert_called_once()
+
+    def test_spark_job_spec_dynamicAllocation_enabled(self):
+        entries = {
+            "spec": {
+                "dynamicAllocation": {
+                    "enabled": True,
+                    "initialExecutors": 1,
+                    "minExecutors": 1,
+                    "maxExecutors": 2,
+                },
+                "driver": {},
+                "executor": {},
+            }
+        }
+        spark_job_spec = SparkJobSpec(**entries)
+
+        assert spark_job_spec.spec["dynamicAllocation"]["enabled"]
+
+    def 
test_spark_job_spec_dynamicAllocation_enabled_with_invalid_config(self):
+        entries = {
+            "spec": {
+                "dynamicAllocation": {
+                    "enabled": True,
+                    "initialExecutors": 1,
+                    "minExecutors": 1,
+                    "maxExecutors": 2,
+                },
+                "driver": {},
+                "executor": {},
+            }
+        }
+        with pytest.raises(
+            AirflowException, match="Make sure initial/min/max value for 
dynamic allocation is passed"
+        ):
+            entries.copy()["spec"]["dynamicAllocation"]["initialExecutors"] = 
None

Review Comment:
   Need to capture clone in a variable use instead of `entries`



-- 
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