-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libclang/python/tests] Remove Python <3.6 workarounds #114399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-clang Author: Jannick Kremer (DeinAlptraum) ChangesThis removes workarounds for Python versions before 3.6, since our minimum Python version has been bumped to 3.8 Full diff: https://github.com/llvm/llvm-project/pull/114399.diff 4 Files Affected:
diff --git a/clang/bindings/python/tests/cindex/test_cdb.py b/clang/bindings/python/tests/cindex/test_cdb.py
index a5cc22796aa2ad..e841220016fbe8 100644
--- a/clang/bindings/python/tests/cindex/test_cdb.py
+++ b/clang/bindings/python/tests/cindex/test_cdb.py
@@ -12,9 +12,7 @@
import gc
import unittest
import sys
-from .util import skip_if_no_fspath
-from .util import str_to_path
-
+from pathlib import Path
kInputsDir = os.path.join(os.path.dirname(__file__), "INPUTS")
@@ -48,13 +46,10 @@ def test_lookup_succeed(self):
cmds = cdb.getCompileCommands("/home/john.doe/MyProject/project.cpp")
self.assertNotEqual(len(cmds), 0)
- @skip_if_no_fspath
def test_lookup_succeed_pathlike(self):
"""Same as test_lookup_succeed, but with PathLikes"""
- cdb = CompilationDatabase.fromDirectory(str_to_path(kInputsDir))
- cmds = cdb.getCompileCommands(
- str_to_path("/home/john.doe/MyProject/project.cpp")
- )
+ cdb = CompilationDatabase.fromDirectory(Path(kInputsDir))
+ cmds = cdb.getCompileCommands(Path("/home/john.doe/MyProject/project.cpp"))
self.assertNotEqual(len(cmds), 0)
def test_all_compilecommand(self):
diff --git a/clang/bindings/python/tests/cindex/test_code_completion.py b/clang/bindings/python/tests/cindex/test_code_completion.py
index 1d513dbca25364..921a8f1f0aac87 100644
--- a/clang/bindings/python/tests/cindex/test_code_completion.py
+++ b/clang/bindings/python/tests/cindex/test_code_completion.py
@@ -7,8 +7,7 @@
from clang.cindex import TranslationUnit
import unittest
-from .util import skip_if_no_fspath
-from .util import str_to_path
+from pathlib import Path
class TestCodeCompletion(unittest.TestCase):
@@ -57,11 +56,10 @@ def test_code_complete(self):
]
self.check_completion_results(cr, expected)
- @skip_if_no_fspath
def test_code_complete_pathlike(self):
files = [
(
- str_to_path("fake.c"),
+ Path("fake.c"),
"""
/// Aaa.
int test1;
@@ -77,14 +75,14 @@ def test_code_complete_pathlike(self):
]
tu = TranslationUnit.from_source(
- str_to_path("fake.c"),
+ Path("fake.c"),
["-std=c99"],
unsaved_files=files,
options=TranslationUnit.PARSE_INCLUDE_BRIEF_COMMENTS_IN_CODE_COMPLETION,
)
cr = tu.codeComplete(
- str_to_path("fake.c"),
+ Path("fake.c"),
9,
1,
unsaved_files=files,
diff --git a/clang/bindings/python/tests/cindex/test_translation_unit.py b/clang/bindings/python/tests/cindex/test_translation_unit.py
index ff7213c69dd0f1..6181463b0804f3 100644
--- a/clang/bindings/python/tests/cindex/test_translation_unit.py
+++ b/clang/bindings/python/tests/cindex/test_translation_unit.py
@@ -7,9 +7,9 @@
from contextlib import contextmanager
import gc
import os
-import sys
import tempfile
import unittest
+from pathlib import Path
from clang.cindex import CursorKind
from clang.cindex import Cursor
@@ -22,8 +22,6 @@
from clang.cindex import TranslationUnit
from .util import get_cursor
from .util import get_tu
-from .util import skip_if_no_fspath
-from .util import str_to_path
kInputsDir = os.path.join(os.path.dirname(__file__), "INPUTS")
@@ -47,7 +45,7 @@ def save_tu_pathlike(tu):
Returns the filename it was saved to.
"""
with tempfile.NamedTemporaryFile() as t:
- tu.save(str_to_path(t.name))
+ tu.save(Path(t.name))
yield t.name
@@ -105,24 +103,21 @@ def test_unsaved_files(self):
self.assertEqual(spellings[-1], "y")
def test_unsaved_files_2(self):
- if sys.version_info.major >= 3:
- from io import StringIO
- else:
- from io import BytesIO as StringIO
+ from io import StringIO
+
tu = TranslationUnit.from_source(
"fake.c", unsaved_files=[("fake.c", StringIO("int x;"))]
)
spellings = [c.spelling for c in tu.cursor.get_children()]
self.assertEqual(spellings[-1], "x")
- @skip_if_no_fspath
def test_from_source_accepts_pathlike(self):
tu = TranslationUnit.from_source(
- str_to_path("fake.c"),
+ Path("fake.c"),
["-Iincludes"],
unsaved_files=[
(
- str_to_path("fake.c"),
+ Path("fake.c"),
"""
#include "fake.h"
int x;
@@ -130,7 +125,7 @@ def test_from_source_accepts_pathlike(self):
""",
),
(
- str_to_path("includes/fake.h"),
+ Path("includes/fake.h"),
"""
#define SOME_DEFINE y
""",
@@ -192,7 +187,6 @@ def test_save(self):
self.assertTrue(os.path.exists(path))
self.assertGreater(os.path.getsize(path), 0)
- @skip_if_no_fspath
def test_save_pathlike(self):
"""Ensure TranslationUnit.save() works with PathLike filename."""
@@ -234,14 +228,13 @@ def test_load(self):
# Just in case there is an open file descriptor somewhere.
del tu2
- @skip_if_no_fspath
def test_load_pathlike(self):
"""Ensure TranslationUnits can be constructed from saved files -
PathLike variant."""
tu = get_tu("int foo();")
self.assertEqual(len(tu.diagnostics), 0)
with save_tu(tu) as path:
- tu2 = TranslationUnit.from_ast_file(filename=str_to_path(path))
+ tu2 = TranslationUnit.from_ast_file(filename=Path(path))
self.assertEqual(len(tu2.diagnostics), 0)
foo = get_cursor(tu2, "foo")
@@ -268,18 +261,17 @@ def test_get_file(self):
with self.assertRaises(Exception):
f = tu.get_file("foobar.cpp")
- @skip_if_no_fspath
def test_get_file_pathlike(self):
"""Ensure tu.get_file() works appropriately with PathLike filenames."""
tu = get_tu("int foo();")
- f = tu.get_file(str_to_path("t.c"))
+ f = tu.get_file(Path("t.c"))
self.assertIsInstance(f, File)
self.assertEqual(f.name, "t.c")
with self.assertRaises(Exception):
- f = tu.get_file(str_to_path("foobar.cpp"))
+ f = tu.get_file(Path("foobar.cpp"))
def test_get_source_location(self):
"""Ensure tu.get_source_location() works."""
diff --git a/clang/bindings/python/tests/cindex/util.py b/clang/bindings/python/tests/cindex/util.py
index 8ba3114b35d1e1..e2d150a7b6b431 100644
--- a/clang/bindings/python/tests/cindex/util.py
+++ b/clang/bindings/python/tests/cindex/util.py
@@ -1,16 +1,5 @@
# This file provides common utility functions for the test suite.
-import os
-
-HAS_FSPATH = hasattr(os, "fspath")
-
-if HAS_FSPATH:
- from pathlib import Path as str_to_path
-else:
- str_to_path = None
-
-import unittest
-
from clang.cindex import Cursor
from clang.cindex import TranslationUnit
@@ -81,14 +70,8 @@ def get_cursors(source, spelling):
return cursors
-skip_if_no_fspath = unittest.skipUnless(
- HAS_FSPATH, "Requires file system path protocol / Python 3.6+"
-)
-
__all__ = [
"get_cursor",
"get_cursors",
"get_tu",
- "skip_if_no_fspath",
- "str_to_path",
]
|
Endilll
approved these changes
Oct 31, 2024
smallp-o-p
pushed a commit
to smallp-o-p/llvm-project
that referenced
this pull request
Nov 3, 2024
This removes workarounds for Python versions before 3.6, since our minimum Python version has been bumped to 3.8
NoumanAmir657
pushed a commit
to NoumanAmir657/llvm-project
that referenced
this pull request
Nov 4, 2024
This removes workarounds for Python versions before 3.6, since our minimum Python version has been bumped to 3.8
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This removes workarounds for Python versions before 3.6, since our minimum Python version has been bumped to 3.8