amoghrajesh commented on code in PR #50446:
URL: https://github.com/apache/airflow/pull/50446#discussion_r2085977788


##########
providers/standard/tests/unit/standard/operators/test_python.py:
##########
@@ -1451,6 +1451,99 @@ def f(
 
         self.run_as_task(f, serializer=serializer, system_site_packages=False, 
requirements=None)
 
+    @pytest.mark.parametrize(
+        "requirements, system_site, want_airflow, want_pendulum",
+        [
+            # nothing → just base keys
+            ([], False, False, False),
+            # site-packages → base keys + pendulum keys
+            ([], True, True, True),
+            # apache-airflow / no version constraint
+            (["apache-airflow"], False, True, True),
+            # specific version
+            (["apache-airflow==2.10.2"], False, True, True),
+            # minimum version
+            (["apache-airflow>=2.10"], False, True, True),
+            # pendulum / no version constraint
+            (["pendulum"], False, False, True),
+            # compatible release
+            (["pendulum~=2.1.0"], False, False, True),
+            # other package
+            (["foo==1.0.0"], False, False, False),
+            # with other package
+            (["apache-airflow", "foo"], False, True, True),
+            # full-line comment only
+            (["# comment"], False, False, False),
+            # inline comment after requirement
+            (["apache-airflow==2.10.2  # comment"], False, True, True),
+            # blank line + requirement
+            (["", "pendulum"], False, False, True),
+            # indented comment + requirement
+            (["  # comment", "pendulum~=2.1.0"], False, False, True),
+        ],
+    )
+    def test_iter_serializable_context_keys(self, requirements, system_site, 
want_airflow, want_pendulum):
+        def func():
+            return "test_return_value"
+
+        op = PythonVirtualenvOperator(
+            task_id="task",
+            python_callable=func,
+            requirements=requirements,
+            system_site_packages=system_site,
+        )
+        keys = set(op._iter_serializable_context_keys())
+
+        base_keys = set(op.BASE_SERIALIZABLE_CONTEXT_KEYS)
+        airflow_keys = set(op.AIRFLOW_SERIALIZABLE_CONTEXT_KEYS)
+        pendulum_keys = set(op.PENDULUM_SERIALIZABLE_CONTEXT_KEYS)
+
+        # BASE keys always present
+        assert base_keys <= keys
+
+        # AIRFLOW keys only when expected
+        if want_airflow:
+            assert airflow_keys <= keys, f"expected AIRFLOW keys for 
requirements: {requirements}"
+        else:
+            assert not (airflow_keys & keys), f"unexpected AIRFLOW keys for 
requirements: {requirements}"
+
+        # PENDULUM keys only when expected
+        if want_pendulum:
+            assert pendulum_keys <= keys, f"expected PENDULUM keys for 
requirements: {requirements}"
+        else:
+            assert not (pendulum_keys & keys), f"unexpected PENDULUM keys for 
requirements: {requirements}"
+
+    @pytest.mark.parametrize(
+        "invalid_requirement",
+        [
+            # invalid version format
+            "pendulum==3..0",
+            # invalid operator (=< instead of <=)
+            "apache-airflow=<2.0",
+            # same invalid operator on pendulum
+            "pendulum=<3.0",
+            # totally malformed
+            "invalid requirement",

Review Comment:
   We do not account for the case when more than one are passed.



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to