[python] [tests] Rewrite to use standard unittest module
Rewrite the tests from using plain 'assert' mixed with some nosetests
methods to the standard unittest module layout. Improve the code
to use the most canonical assertion methods whenever possible.
This has a few major advantages:
- the code uses standard methods now, resulting in a reduced number
of WTFs whenever someone with basic Python knowledge gets to read it,
- completely unnecessary dependency on nosetests is removed since
the standard library supplies all that is necessary for the tests
to run,
- the tests can be run via any test runner, including the one built-in
in Python,
- the failure output for most of the tests is improved from 'assertion
x == y failed' to actually telling the values.
Differential Revision: https://reviews.llvm.org/D39763
llvm-svn: 317897
diff --git a/clang/bindings/python/tests/cindex/test_comment.py b/clang/bindings/python/tests/cindex/test_comment.py
index d8f3129..d6c6d8e 100644
--- a/clang/bindings/python/tests/cindex/test_comment.py
+++ b/clang/bindings/python/tests/cindex/test_comment.py
@@ -1,8 +1,12 @@
from clang.cindex import TranslationUnit
from tests.cindex.util import get_cursor
-def test_comment():
- files = [('fake.c', """
+import unittest
+
+
+class TestComment(unittest.TestCase):
+ def test_comment(self):
+ files = [('fake.c', """
/// Aaa.
int test1;
@@ -14,27 +18,25 @@
}
""")]
- # make a comment-aware TU
- tu = TranslationUnit.from_source('fake.c', ['-std=c99'], unsaved_files=files,
- options=TranslationUnit.PARSE_INCLUDE_BRIEF_COMMENTS_IN_CODE_COMPLETION)
- test1 = get_cursor(tu, 'test1')
- assert test1 is not None, "Could not find test1."
- assert test1.type.is_pod()
- raw = test1.raw_comment
- brief = test1.brief_comment
- assert raw == """/// Aaa."""
- assert brief == """Aaa."""
-
- test2 = get_cursor(tu, 'test2')
- raw = test2.raw_comment
- brief = test2.brief_comment
- assert raw == """/// Bbb.\n/// x"""
- assert brief == """Bbb. x"""
-
- f = get_cursor(tu, 'f')
- raw = f.raw_comment
- brief = f.brief_comment
- assert raw is None
- assert brief is None
+ # make a comment-aware TU
+ tu = TranslationUnit.from_source('fake.c', ['-std=c99'], unsaved_files=files,
+ options=TranslationUnit.PARSE_INCLUDE_BRIEF_COMMENTS_IN_CODE_COMPLETION)
+ test1 = get_cursor(tu, 'test1')
+ self.assertIsNotNone(test1, "Could not find test1.")
+ self.assertTrue(test1.type.is_pod())
+ raw = test1.raw_comment
+ brief = test1.brief_comment
+ self.assertEqual(raw, """/// Aaa.""")
+ self.assertEqual(brief, """Aaa.""")
+ test2 = get_cursor(tu, 'test2')
+ raw = test2.raw_comment
+ brief = test2.brief_comment
+ self.assertEqual(raw, """/// Bbb.\n/// x""")
+ self.assertEqual(brief, """Bbb. x""")
+ f = get_cursor(tu, 'f')
+ raw = f.raw_comment
+ brief = f.brief_comment
+ self.assertIsNone(raw)
+ self.assertIsNone(brief)