Files
TheRock/compiler/amd-llvm/clang/bindings/python/tests/cindex/test_file.py
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

81 lines
2.5 KiB
Python

import os
from clang.cindex import _CXUnsavedFile, File, Index, TranslationUnit
import unittest
import warnings
inputs_dir = os.path.join(os.path.dirname(__file__), "INPUTS")
class TestFile(unittest.TestCase):
def test_file(self):
index = Index.create()
tu = index.parse("t.c", unsaved_files=[("t.c", "")])
file = File.from_name(tu, "t.c")
self.assertEqual(str(file), "t.c")
self.assertEqual(file.name, "t.c")
self.assertEqual(repr(file), "<File: t.c>")
def test_file_eq(self):
path = os.path.join(inputs_dir, "testfile.c")
path_a = os.path.join(inputs_dir, "a.inc")
path_b = os.path.join(inputs_dir, "b.inc")
tu = TranslationUnit.from_source(path)
main_file = File.from_name(tu, path)
a_file = File.from_name(tu, path_a)
a_file2 = File.from_name(tu, path_a)
b_file = File.from_name(tu, path_b)
self.assertEqual(a_file, a_file2)
self.assertNotEqual(a_file, b_file)
self.assertNotEqual(main_file, a_file)
self.assertNotEqual(main_file, b_file)
self.assertNotEqual(main_file, "t.c")
def test_file_eq_in_memory(self):
tu = TranslationUnit.from_source(
"testfile.c",
unsaved_files=[
(
"testfile.c",
"""
int a[] = {
#include "a.inc"
};
int b[] = {
#include "b.inc"
};
""",
),
("a.inc", "1,2,3"),
("b.inc", "1,2,3"),
],
)
path = os.path.join(inputs_dir, "testfile.c")
path_a = os.path.join(inputs_dir, "a.inc")
path_b = os.path.join(inputs_dir, "b.inc")
tu = TranslationUnit.from_source(path)
main_file = File.from_name(tu, path)
a_file = File.from_name(tu, path_a)
a_file2 = File.from_name(tu, path_a)
b_file = File.from_name(tu, path_b)
self.assertEqual(a_file, a_file2)
self.assertNotEqual(a_file, b_file)
self.assertNotEqual(main_file, a_file)
self.assertNotEqual(main_file, b_file)
self.assertNotEqual(main_file, "a.inc")
class TestUnsavedFile(unittest.TestCase):
def test_deprecation_warning(self):
unsaved_file = _CXUnsavedFile()
with warnings.catch_warnings(record=True) as log:
unsaved_file.name
self.assertEqual(len(log), 1)
for warning in log:
self.assertIsInstance(warning.message, DeprecationWarning)