]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
try to improve coverage a bit
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 27 Oct 2025 14:56:49 +0000 (10:56 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 27 Oct 2025 14:56:49 +0000 (10:56 -0400)
use pyproject.toml so the options are safe from "rm .coverage*"
types of commands

omit some files

add test coverage for a big section of cache-key

Change-Id: Ia540c632d91ec09284e187e3edeb8ccf0214e1a6

.coveragerc [deleted file]
noxfile.py
pyproject.toml
test/sql/test_compare.py

diff --git a/.coveragerc b/.coveragerc
deleted file mode 100644 (file)
index e279765..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-[paths]
-source=lib/
-
-[run]
-relative_files=True
-
-
index 6b593b06fb3212da2e3bcb0555d22578c8238a89..a5afe3167392c19365636e8b2a7683ac8dade8da 100644 (file)
@@ -192,6 +192,10 @@ def _tests(
     timing_intensive: bool = True,
     coverage: bool = False,
 ) -> None:
+
+    # ensure external PYTHONPATH not interfering
+    session.env["PYTHONPATH"] = ""
+
     # PYTHONNOUSERSITE - this *MUST* be set so that the ./lib/ import
     # set up explicitly in test/conftest.py is *disabled*, so that
     # when SQLAlchemy is built into the .nox area, we use that and not the
index caeaf47c6e7f0b7d8d0f395ff7dc43e7981ae600..8179aa4832c73fe2de9260ff069be583581944eb 100644 (file)
@@ -196,6 +196,19 @@ mypy = [
 ]
 
 
+[tool.coverage.paths]
+source="lib/"
+
+[tool.coverage.run]
+relative_files = true
+omit = [
+    "lib/sqlalchemy/testing/plugin/*",
+    "lib/sqlalchemy/testing/fixtures/mypy.py",
+    "lib/sqlalchemy/testing/profiling.py",
+    "lib/sqlalchemy/util/tool_support.py",
+]
+
+
 [tool.setuptools]
 include-package-data = true
 
index 774f9792f443635ff137b31adfbd51e58daefb24..94f34ddfff4bddc6354ff19cc6833d55e07a693d 100644 (file)
@@ -49,6 +49,7 @@ from sqlalchemy.sql.base import DialectKWArgs
 from sqlalchemy.sql.base import HasCacheKey
 from sqlalchemy.sql.base import SingletonConstant
 from sqlalchemy.sql.base import SyntaxExtension
+from sqlalchemy.sql.cache_key import CacheKey
 from sqlalchemy.sql.elements import _label_reference
 from sqlalchemy.sql.elements import _textual_label_reference
 from sqlalchemy.sql.elements import BindParameter
@@ -2315,3 +2316,57 @@ class TypesTest(fixtures.TestBase):
 
         eq_(c1, c2)
         ne_(c1, c3)
+
+
+class TestWhatsDifferentUtil(fixtures.TestBase):
+    """Test the CacheKey._whats_different() utility method
+
+    Note: The _whats_different() method has a limitation where it can only
+    properly handle nested tuple structures. It was designed to work with
+    real cache keys which are always nested tuples.
+    """
+
+    def test_nested_tuple_difference(self):
+        """Test difference detection in nested tuples"""
+        k1 = CacheKey(key=((1, (2, 3, 4), 5),), bindparams=[])
+        k2 = CacheKey(key=((1, (2, 7, 4), 5),), bindparams=[])
+
+        eq_(list(k1._whats_different(k2)), ["key[0][1][1]:  3 != 7"])
+
+    def test_deeply_nested_tuple_difference(self):
+        """Test difference detection in deeply nested tuples"""
+        k1 = CacheKey(key=((1, (2, (3, 4, 5), 6), 7),), bindparams=[])
+        k2 = CacheKey(key=((1, (2, (3, 9, 5), 6), 7),), bindparams=[])
+
+        eq_(list(k1._whats_different(k2)), ["key[0][1][1][1]:  4 != 9"])
+
+    def test_multiple_differences_nested(self):
+        """Test detection of multiple differences in nested structure"""
+        k1 = CacheKey(key=((1, (2, 3), 4),), bindparams=[])
+        k2 = CacheKey(key=((1, (5, 7), 4),), bindparams=[])
+
+        eq_(
+            list(k1._whats_different(k2)),
+            ["key[0][1][0]:  2 != 5", "key[0][1][1]:  3 != 7"],
+        )
+
+    def test_diff_method(self):
+        """Test the _diff() method that returns a comma-separated string"""
+        k1 = CacheKey(key=((1, (2, 3)),), bindparams=[])
+        k2 = CacheKey(key=((1, (5, 7)),), bindparams=[])
+
+        eq_(k1._diff(k2), "key[0][1][0]:  2 != 5, key[0][1][1]:  3 != 7")
+
+    def test_with_string_differences(self):
+        """Test detection of string differences"""
+        k1 = CacheKey(key=(("name", ("x", "value")),), bindparams=[])
+        k2 = CacheKey(key=(("name", ("y", "value")),), bindparams=[])
+
+        eq_(list(k1._whats_different(k2)), ["key[0][1][0]:  x != y"])
+
+    def test_with_mixed_types(self):
+        """Test detection of differences with mixed types"""
+        k1 = CacheKey(key=(("id", 1, ("nested", 100)),), bindparams=[])
+        k2 = CacheKey(key=(("id", 1, ("nested", 200)),), bindparams=[])
+
+        eq_(list(k1._whats_different(k2)), ["key[0][2][1]:  100 != 200"])