This is an automated email from the ASF dual-hosted git repository.
HyukjinKwon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark-connect-rust.git
The following commit(s) were added to refs/heads/master by this push:
new 90d103a2 [SPARK-61230][CONNECT][PYTHON][TESTS] Leave the files
vendored from upstream out of the Python coverage, and check that every
vendored file is omitted
90d103a2 is described below
commit 90d103a200fc28abedbaffeddfaf70e51ba88476
Author: Hyukjin Kwon <[email protected]>
AuthorDate: Mon Nov 9 21:33:35 2026 +0900
[SPARK-61230][CONNECT][PYTHON][TESTS] Leave the files vendored from
upstream out of the Python coverage, and check that every vendored file is
omitted
### What changes were proposed in this pull request?
[SPARK-61230](https://issues.apache.org/jira/browse/SPARK-61230): Omit from
the Python coverage the seven files that are vendored verbatim from Apache
Spark but were still measured, and add a check that keeps the omit list in sync
with the vendored lists.
`python/.coveragerc` measures the hand-written Python of the drop-in. It
omits the files vendored byte-for-byte from the `v4.3.0` tag, which Apache's
own tests cover, and its comment says to keep that list in sync with
`VENDORED_DIRS`/`VENDORED_FILES` of `scripts/check_vendored_upstream.sh`. These
vendored files were still measured:
| file | units (statements + branches) | uncovered |
|---|---|---|
| `conf.py` | 141 | 56 |
| `taskcontext.py` | 157 | 101 |
| `traceback_utils.py` | 52 | 42 |
| `sql/geo_utils.py` | 50 | 5 |
| `sql/sql_formatter.py` | 58 | 45 |
| `sql/connect/profiler.py` | 13 | 0 |
| `sql/connect/shell/progress.py` | 107 | 18 |
This adds them to the omit list, and adds
`scripts/tests/test_coverage_scope.py`, which the lint workflow runs (`python3
-m unittest discover -s scripts/tests`). It fails when a Python file of the
vendored lists is not omitted, so the two lists cannot drift apart again.
### Why are the changes needed?
The Python coverage badge should measure what its scope says: the drop-in's
own code. On master it is 85.40% (4827 of 5652 units); with the vendored files
omitted it is 89.00% (4516 of 5074). Follow-up PRs add tests for the drop-in's
own uncovered code.
### Does this PR introduce _any_ user-facing change?
No, the coverage scope and a check only.
### How was this patch tested?
- The new test passes, and fails without the `.coveragerc` change (it lists
the seven files).
- `python3 -m unittest discover -s scripts/tests`: 16 tests pass. ruff
0.14.0 passes on `scripts/`.
- The numbers above are from the CI command of the coverage job (`coverage
run --rcfile=.coveragerc -m pytest tests/test_dropin_offline.py
tests/test_arrow_handoff.py tests/test_ml_offline.py`, 2819 passed) on master
`cefa44df`.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5
This pull request and its description were written by Isaac.
Closes #411 from HyukjinKwon/SPARK-61230-coverage-scope.
Authored-by: Hyukjin Kwon <[email protected]>
Signed-off-by: Hyukjin Kwon <[email protected]>
---
python/.coveragerc | 9 +++++
scripts/tests/test_coverage_scope.py | 72 ++++++++++++++++++++++++++++++++++++
2 files changed, 81 insertions(+)
diff --git a/python/.coveragerc b/python/.coveragerc
index 426e1c51..699ead7c 100644
--- a/python/.coveragerc
+++ b/python/.coveragerc
@@ -65,6 +65,15 @@ omit =
*/pyspark/sql/connect/logging.py
*/pyspark/sql/connect/_typing.py
*/pyspark/sql/connect/conversion.py
+ # The other files that scripts/check_vendored_upstream.sh keeps
byte-identical to the tag
+ # (scripts/tests/test_coverage_scope.py checks that every vendored file is
omitted here).
+ */pyspark/conf.py
+ */pyspark/taskcontext.py
+ */pyspark/traceback_utils.py
+ */pyspark/sql/geo_utils.py
+ */pyspark/sql/sql_formatter.py
+ */pyspark/sql/connect/profiler.py
+ */pyspark/sql/connect/shell/progress.py
# The native extension and its embedded Row source, which has a synthetic
filename.
*/pyspark/_pyspark*
*/pyspark/_row.py
diff --git a/scripts/tests/test_coverage_scope.py
b/scripts/tests/test_coverage_scope.py
new file mode 100644
index 00000000..31233ae0
--- /dev/null
+++ b/scripts/tests/test_coverage_scope.py
@@ -0,0 +1,72 @@
+#
+# 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.
+
+"""Check that the Python coverage leaves out every file vendored verbatim from
upstream.
+
+python/.coveragerc measures the hand-written drop-in only; the files that
+scripts/check_vendored_upstream.sh keeps byte-identical to the Apache Spark
tag are covered
+by Apache's own tests, so they must be in its omit list.
+"""
+
+import configparser
+import fnmatch
+import re
+import unittest
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[2]
+
+
+def vendored_entries():
+ src = (ROOT / "scripts" / "check_vendored_upstream.sh").read_text()
+
+ def array(name):
+ body = re.search(name + r"=\((.*?)\n\)", src, re.S).group(1)
+ return re.findall(r'^\s*"([^"]+)"', body, re.M)
+
+ return array("VENDORED_DIRS"), array("VENDORED_FILES")
+
+
+def omit_patterns():
+ config = configparser.ConfigParser()
+ config.read(ROOT / "python" / ".coveragerc")
+ lines = config["run"]["omit"].splitlines()
+ return [line.strip() for line in lines if line.strip() and not
line.strip().startswith("#")]
+
+
+class CoverageScopeTests(unittest.TestCase):
+ def test_every_vendored_python_file_is_omitted(self):
+ dirs, files = vendored_entries()
+ patterns = omit_patterns()
+ base = str(ROOT / "python" / "pyspark")
+ paths = [f"{base}/{d}/module.py" for d in dirs]
+ paths += [f"{base}/{f}" for f in files if f.endswith(".py")]
+ measured = [p for p in paths if not any(fnmatch.fnmatch(p, pat) for
pat in patterns)]
+ self.assertEqual(
+ measured,
+ [],
+ "vendored upstream files measured by python/.coveragerc; add them
to its omit list",
+ )
+
+ def test_the_lists_are_read(self):
+ dirs, files = vendored_entries()
+ self.assertIn("cloudpickle", dirs)
+ self.assertIn("taskcontext.py", files)
+ self.assertIn("*/cloudpickle/*", omit_patterns())
+
+
+if __name__ == "__main__":
+ unittest.main()
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]