[clang] [libclang/python/tests] Remove Python <3.6 workarounds (PR #114399)
https://github.com/DeinAlptraum closed https://github.com/llvm/llvm-project/pull/114399 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libclang/python/tests] Remove Python <3.6 workarounds (PR #114399)
https://github.com/DeinAlptraum created https://github.com/llvm/llvm-project/pull/114399 This removes workarounds for Python versions before 3.6, since our minimum Python version has been bumped to 3.8 >From b3079f7a44d65c8d62fe201b7c5766b852a1 Mon Sep 17 00:00:00 2001 From: Jannick Kremer Date: Thu, 31 Oct 2024 13:38:48 +0100 Subject: [PATCH] [libclang/python/tests] Remove Python <3.6 workarounds --- .../bindings/python/tests/cindex/test_cdb.py | 11 ++-- .../tests/cindex/test_code_completion.py | 10 +++ .../tests/cindex/test_translation_unit.py | 28 +++ clang/bindings/python/tests/cindex/util.py| 17 --- 4 files changed, 17 insertions(+), 49 deletions(-) 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
[clang] [libclang/python/tests] Remove Python <3.6 workarounds (PR #114399)
https://github.com/Endilll approved this pull request. https://github.com/llvm/llvm-project/pull/114399 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libclang/python/tests] Remove Python <3.6 workarounds (PR #114399)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Jannick Kremer (DeinAlptraum) Changes This 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: - (modified) clang/bindings/python/tests/cindex/test_cdb.py (+3-8) - (modified) clang/bindings/python/tests/cindex/test_code_completion.py (+4-6) - (modified) clang/bindings/python/tests/cindex/test_translation_unit.py (+10-18) - (modified) clang/bindings/python/tests/cindex/util.py (-17) ``diff 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"], uns