This is an automated email from the ASF dual-hosted git repository.

shahar1 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new ff22d7313ca Add tests for airflowctl utils helpers and module loading 
(#76271)
ff22d7313ca is described below

commit ff22d7313cad812ad2c5021c9fb5ed9a3871b0bd
Author: ZJ-lucky-0915 <[email protected]>
AuthorDate: Tue Nov 3 23:42:30 2026 +0800

    Add tests for airflowctl utils helpers and module loading (#76271)
---
 airflow-ctl/tests/airflow_ctl/utils/__init__.py    | 16 ++++++++
 .../tests/airflow_ctl/utils/test_helpers.py        | 45 ++++++++++++++++++++++
 .../tests/airflow_ctl/utils/test_module_loading.py | 43 +++++++++++++++++++++
 3 files changed, 104 insertions(+)

diff --git a/airflow-ctl/tests/airflow_ctl/utils/__init__.py 
b/airflow-ctl/tests/airflow_ctl/utils/__init__.py
new file mode 100644
index 00000000000..13a83393a91
--- /dev/null
+++ b/airflow-ctl/tests/airflow_ctl/utils/__init__.py
@@ -0,0 +1,16 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
diff --git a/airflow-ctl/tests/airflow_ctl/utils/test_helpers.py 
b/airflow-ctl/tests/airflow_ctl/utils/test_helpers.py
new file mode 100644
index 00000000000..026e8d623c1
--- /dev/null
+++ b/airflow-ctl/tests/airflow_ctl/utils/test_helpers.py
@@ -0,0 +1,45 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+from __future__ import annotations
+
+from airflowctl.utils.helpers import partition
+
+
+def test_partition_splits_false_and_true_entries():
+    false_entries, true_entries = partition(lambda value: value % 2 == 0, [0, 
1, 2, 3, 4])
+
+    assert list(false_entries) == [1, 3]
+    assert list(true_entries) == [0, 2, 4]
+
+
+def test_partition_handles_empty_iterable():
+    false_entries, true_entries = partition(bool, [])
+
+    assert list(false_entries) == []
+    assert list(true_entries) == []
+
+
+def test_partition_works_with_one_shot_iterators():
+    source = (value for value in range(4))
+
+    false_entries, true_entries = partition(lambda value: value >= 2, source)
+
+    # Consume the true group first; tee must still let both sides see the full 
input.
+    assert list(true_entries) == [2, 3]
+    assert list(false_entries) == [0, 1]
diff --git a/airflow-ctl/tests/airflow_ctl/utils/test_module_loading.py 
b/airflow-ctl/tests/airflow_ctl/utils/test_module_loading.py
new file mode 100644
index 00000000000..101465b18a9
--- /dev/null
+++ b/airflow-ctl/tests/airflow_ctl/utils/test_module_loading.py
@@ -0,0 +1,43 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+from __future__ import annotations
+
+import pytest
+
+from airflowctl.utils.helpers import partition
+from airflowctl.utils.module_loading import import_string
+
+
+def test_import_string_returns_attribute():
+    assert import_string("airflowctl.utils.helpers.partition") is partition
+
+
+def test_import_string_rejects_path_without_dot():
+    with pytest.raises(ImportError, match="doesn't look like a module path"):
+        import_string("not_a_module")
+
+
+def test_import_string_propagates_missing_module():
+    with pytest.raises(ModuleNotFoundError):
+        import_string("definitely_not_a_module.attribute")
+
+
+def test_import_string_reports_missing_attribute():
+    with pytest.raises(ImportError, match='does not define a "missing" 
attribute/class'):
+        import_string("airflowctl.utils.helpers.missing")

Reply via email to