[clang] 09b62ed - [libclang/python] Ignore our own DeprecationWarnings in tests (#178631)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 30 09:36:25 PST 2026
Author: Jannick Kremer
Date: 2026-01-31T02:36:20+09:00
New Revision: 09b62ed0c9316e790f8021095783e2d019963cec
URL: https://github.com/llvm/llvm-project/commit/09b62ed0c9316e790f8021095783e2d019963cec
DIFF: https://github.com/llvm/llvm-project/commit/09b62ed0c9316e790f8021095783e2d019963cec.diff
LOG: [libclang/python] Ignore our own DeprecationWarnings in tests (#178631)
Suppress `DeprecationWarnings` raised in the libclang python tests. Also
ensure that they are returned where expected.
Resolves #178203
Added:
Modified:
clang/bindings/python/tests/cindex/test_code_completion.py
Removed:
################################################################################
diff --git a/clang/bindings/python/tests/cindex/test_code_completion.py b/clang/bindings/python/tests/cindex/test_code_completion.py
index e3a340c061434..91faebfec66c0 100644
--- a/clang/bindings/python/tests/cindex/test_code_completion.py
+++ b/clang/bindings/python/tests/cindex/test_code_completion.py
@@ -9,6 +9,7 @@
import unittest
from pathlib import Path
+import warnings
class TestCodeCompletion(unittest.TestCase):
@@ -16,7 +17,11 @@ def check_completion_results(self, cr, expected):
self.assertIsNotNone(cr)
self.assertEqual(len(cr.diagnostics), 0)
- completions = [str(c) for c in cr.results]
+ with warnings.catch_warnings(record=True) as log:
+ completions = [str(c) for c in cr.results]
+ self.assertEqual(len(log), 2)
+ for warning in log:
+ self.assertIsInstance(warning.message, DeprecationWarning)
for c in expected:
self.assertIn(c, completions)
@@ -180,7 +185,10 @@ def test_compat_str(self):
}
for id, string in kindStringMap.items():
kind = CompletionString.AvailabilityKindCompat.from_id(id)
- self.assertEqual(str(kind), string)
+ with warnings.catch_warnings(record=True) as log:
+ self.assertEqual(str(kind), string)
+ self.assertEqual(len(log), 1)
+ self.assertIsInstance(log[0].message, DeprecationWarning)
def test_completion_chunk_kind_compatibility(self):
value_to_old_str = {
@@ -210,12 +218,18 @@ def test_completion_chunk_kind_compatibility(self):
# Check that all new kinds correspond to an old kind
for new_kind in CompletionChunkKind:
old_str = value_to_old_str[new_kind.value]
- self.assertEqual(old_str, str(new_kind))
+ with warnings.catch_warnings(record=True) as log:
+ self.assertEqual(old_str, str(new_kind))
+ self.assertEqual(len(log), 1)
+ self.assertIsInstance(log[0].message, DeprecationWarning)
# Check that all old kinds correspond to a new kind
for value, old_str in value_to_old_str.items():
new_kind = CompletionChunkKind.from_id(value)
- self.assertEqual(old_str, str(new_kind))
+ with warnings.catch_warnings(record=True) as log:
+ self.assertEqual(old_str, str(new_kind))
+ self.assertEqual(len(log), 1)
+ self.assertIsInstance(log[0].message, DeprecationWarning)
def test_spelling_cache_missing_attribute(self):
# Test that accessing missing attributes on SpellingCacheAlias raises
@@ -227,9 +241,13 @@ def test_spelling_cache_alias(self):
kind_keys = list(CompletionChunk.SPELLING_CACHE)
self.assertEqual(len(kind_keys), 13)
for kind_key in kind_keys:
- self.assertEqual(
- SPELLING_CACHE[kind_key.value], CompletionChunk.SPELLING_CACHE[kind_key]
- )
+ with warnings.catch_warnings(record=True) as log:
+ self.assertEqual(
+ SPELLING_CACHE[kind_key.value],
+ CompletionChunk.SPELLING_CACHE[kind_key],
+ )
+ self.assertEqual(len(log), 1)
+ self.assertIsInstance(log[0].message, DeprecationWarning)
def test_spelling_cache_missing_attribute(self):
# Test that accessing missing attributes on SpellingCacheAlias raises
More information about the cfe-commits
mailing list