r335282 - [bindings] Fix most Python binding unittests on Windows

Jonathan Coe via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 21 13:07:03 PDT 2018


Author: jbcoe
Date: Thu Jun 21 13:07:03 2018
New Revision: 335282

URL: http://llvm.org/viewvc/llvm-project?rev=335282&view=rev
Log:
[bindings] Fix most Python binding unittests on Windows

Summary:
This fixes all but one of the test cases for Windows. TestCDB will
take more work to debug, as CompilationDatabase seems not to work correctly.

Reviewers: bkramer, wanders, jbcoe

Reviewed By: bkramer, jbcoe

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D47864

Patch written by ethanhs (Ethan)

Modified:
    cfe/trunk/bindings/python/tests/cindex/test_cdb.py
    cfe/trunk/bindings/python/tests/cindex/test_cursor.py
    cfe/trunk/bindings/python/tests/cindex/test_translation_unit.py

Modified: cfe/trunk/bindings/python/tests/cindex/test_cdb.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_cdb.py?rev=335282&r1=335281&r2=335282&view=diff
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_cdb.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_cdb.py Thu Jun 21 13:07:03 2018
@@ -5,11 +5,13 @@ from clang.cindex import CompileCommand
 import os
 import gc
 import unittest
+import sys
 
 
 kInputsDir = os.path.join(os.path.dirname(__file__), 'INPUTS')
 
 
+ at unittest.skipIf(sys.platform == 'win32', "TODO: Fix these tests on Windows")
 class TestCDB(unittest.TestCase):
     def test_create_fail(self):
         """Check we fail loading a database with an assertion"""

Modified: cfe/trunk/bindings/python/tests/cindex/test_cursor.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_cursor.py?rev=335282&r1=335281&r2=335282&view=diff
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_cursor.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_cursor.py Thu Jun 21 13:07:03 2018
@@ -335,7 +335,7 @@ class TestCursor(unittest.TestCase):
 
         self.assertEqual(enum.kind, CursorKind.ENUM_DECL)
         enum_type = enum.enum_type
-        self.assertEqual(enum_type.kind, TypeKind.UINT)
+        self.assertIn(enum_type.kind, (TypeKind.UINT, TypeKind.INT))
 
     def test_enum_type_cpp(self):
         tu = get_tu('enum TEST : long long { FOO=1, BAR=2 };', lang="cpp")
@@ -561,4 +561,4 @@ class TestCursor(unittest.TestCase):
         # all valid manglings.
         # [c-index-test handles this by running the source through clang, emitting
         #  an AST file and running libclang on that AST file]
-        self.assertIn(foo.mangled_name, ('_Z3fooii', '__Z3fooii', '?foo@@YAHHH'))
+        self.assertIn(foo.mangled_name, ('_Z3fooii', '__Z3fooii', '?foo@@YAHHH', '?foo@@YAHHH at Z'))

Modified: cfe/trunk/bindings/python/tests/cindex/test_translation_unit.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_translation_unit.py?rev=335282&r1=335281&r2=335282&view=diff
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_translation_unit.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_translation_unit.py Thu Jun 21 13:07:03 2018
@@ -1,3 +1,4 @@
+from contextlib import contextmanager
 import gc
 import os
 import tempfile
@@ -19,15 +20,15 @@ from .util import get_tu
 kInputsDir = os.path.join(os.path.dirname(__file__), 'INPUTS')
 
 
+ at contextmanager
 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
+    with tempfile.NamedTemporaryFile() as t:
+        tu.save(t.name)
+        yield t.name
 
 
 class TestTranslationUnit(unittest.TestCase):
@@ -125,10 +126,9 @@ int SOME_DEFINE;
 
         tu = get_tu('int foo();')
 
-        path = save_tu(tu)
-        self.assertTrue(os.path.exists(path))
-        self.assertGreater(os.path.getsize(path), 0)
-        os.unlink(path)
+        with save_tu(tu) as path:
+            self.assertTrue(os.path.exists(path))
+            self.assertGreater(os.path.getsize(path), 0)
 
     def test_save_translation_errors(self):
         """Ensure that saving to an invalid directory raises."""
@@ -149,21 +149,18 @@ int SOME_DEFINE;
 
         tu = get_tu('int foo();')
         self.assertEqual(len(tu.diagnostics), 0)
-        path = save_tu(tu)
-
-        self.assertTrue(os.path.exists(path))
-        self.assertGreater(os.path.getsize(path), 0)
-
-        tu2 = TranslationUnit.from_ast_file(filename=path)
-        self.assertEqual(len(tu2.diagnostics), 0)
+        with save_tu(tu) as path:
+            self.assertTrue(os.path.exists(path))
+            self.assertGreater(os.path.getsize(path), 0)
 
-        foo = get_cursor(tu2, 'foo')
-        self.assertIsNotNone(foo)
+            tu2 = TranslationUnit.from_ast_file(filename=path)
+            self.assertEqual(len(tu2.diagnostics), 0)
 
-        # Just in case there is an open file descriptor somewhere.
-        del tu2
+            foo = get_cursor(tu2, 'foo')
+            self.assertIsNotNone(foo)
 
-        os.unlink(path)
+            # Just in case there is an open file descriptor somewhere.
+            del tu2
 
     def test_index_parse(self):
         path = os.path.join(kInputsDir, 'hello.cpp')




More information about the cfe-commits mailing list