[PATCH] [PATCH] Add test for Python binding Index read.
Brian Gesiak
modocache at gmail.com
Sun Mar 2 08:48:51 PST 2014
Replace FIXME by adding test for Index read method.
- Add Index read method test.
- Move save_tu method to test util module.
- Place imports on separate lines to conform with style in other test files.
http://llvm-reviews.chandlerc.com/D2916
Files:
bindings/python/tests/cindex/test_index.py
bindings/python/tests/cindex/test_translation_unit.py
bindings/python/tests/cindex/util.py
Index: bindings/python/tests/cindex/test_index.py
===================================================================
--- bindings/python/tests/cindex/test_index.py
+++ bindings/python/tests/cindex/test_index.py
@@ -1,12 +1,26 @@
-from clang.cindex import *
import os
+from clang.cindex import Index
+from clang.cindex import TranslationUnit
+from .util import get_cursor
+from .util import get_tu
+from .util import save_tu
+
kInputsDir = os.path.join(os.path.dirname(__file__), 'INPUTS')
def test_create():
index = Index.create()
-# FIXME: test Index.read
+def test_read():
+ translation_unit = get_tu('int foo();')
+ path = save_tu(translation_unit)
+
+ index = Index.create()
+ read_unit = index.read(path)
+ assert len(read_unit.diagnostics) == 0
+
+ cursor = get_cursor(read_unit, 'foo')
+ assert cursor is not None
def test_parse():
index = Index.create()
Index: bindings/python/tests/cindex/test_translation_unit.py
===================================================================
--- bindings/python/tests/cindex/test_translation_unit.py
+++ bindings/python/tests/cindex/test_translation_unit.py
@@ -1,6 +1,5 @@
import gc
import os
-import tempfile
from clang.cindex import CursorKind
from clang.cindex import Cursor
@@ -13,6 +12,7 @@
from clang.cindex import TranslationUnit
from .util import get_cursor
from .util import get_tu
+from .util import save_tu
kInputsDir = os.path.join(os.path.dirname(__file__), 'INPUTS')
@@ -89,16 +89,6 @@
for i in zip(inc, tu.get_includes()):
assert eq(i[0], i[1])
-def save_tu(tu):
- """Convenience API to save a TranslationUnit to a file.
-
- Returns the filename it was saved to.
- """
- _, path = tempfile.mkstemp()
- tu.save(path)
-
- return path
-
def test_save():
"""Ensure TranslationUnit.save() works."""
Index: bindings/python/tests/cindex/util.py
===================================================================
--- bindings/python/tests/cindex/util.py
+++ bindings/python/tests/cindex/util.py
@@ -1,5 +1,7 @@
# This file provides common utility functions for the test suite.
+import tempfile
+
from clang.cindex import Cursor
from clang.cindex import TranslationUnit
@@ -30,6 +32,16 @@
return TranslationUnit.from_source(name, args, unsaved_files=[(name,
source)])
+def save_tu(tu):
+ """Convenience API to save a TranslationUnit to a file.
+
+ Returns the filename it was saved to.
+ """
+ _, path = tempfile.mkstemp()
+ tu.save(path)
+
+ return path
+
def get_cursor(source, spelling):
"""Obtain a cursor from a source object.
@@ -56,7 +68,7 @@
return result
return None
-
+
def get_cursors(source, spelling):
"""Obtain all cursors from a source object with a specific spelling.
@@ -83,9 +95,6 @@
return cursors
-
-
-
__all__ = [
'get_cursor',
'get_cursors',
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2916.1.patch
Type: text/x-patch
Size: 2958 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140302/011fad5f/attachment.bin>
More information about the cfe-commits
mailing list