Skip to content

Commit 7ecb3cf

Browse files
committed
Add text checking function
Add a comment text checking function. This print extra print signals when the test passes thanks to the absence of strings as opposed to the content matching.
1 parent 68933f7 commit 7ecb3cf

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

unittests/test_comments.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ def __init__(self, *args):
2020
self.global_ns = None
2121
self.config.castxml_epic_version = 1
2222

23+
def _check_comment_content(self, list, comment_decl):
24+
if comment_decl.text:
25+
self.assertEqual(list, comment_decl.text)
26+
else:
27+
print("No text in comment to check")
28+
2329
def setUp(self):
2430

2531
if not self.global_ns:
@@ -41,47 +47,40 @@ def test(self):
4147
tnamespace = self.global_ns.namespace("comment")
4248

4349
self.assertIn("comment", dir(tnamespace))
44-
if tnamespace.comment.text:
45-
self.assertEqual(["//! Namespace Comment",
46-
"//! Across multiple lines"],
47-
tnamespace.comment.text)
50+
self._check_comment_content(["//! Namespace Comment",
51+
"//! Across multiple lines"],
52+
tnamespace.comment)
4853

4954
tenumeration = tnamespace.enumeration("com_enum")
5055
self.assertIn("comment", dir(tenumeration))
51-
if tenumeration.comment.text:
52-
self.assertEqual(['/// Outside Class enum comment'],
53-
tenumeration.comment.text)
56+
self._check_comment_content(['/// Outside Class enum comment'],
57+
tenumeration.comment)
5458

5559
tclass = tnamespace.class_("test")
5660
self.assertIn("comment", dir(tclass))
57-
if tclass.comment.text:
58-
self.assertEqual(["/** class comment */"], tclass.comment.text)
61+
self._check_comment_content(["/** class comment */"], tclass.comment)
5962

6063
tcls_enumeration = tclass.enumeration("test_enum")
6164
self.assertIn("comment", dir(tcls_enumeration))
62-
if tcls_enumeration.comment.text:
63-
self.assertEqual(['/// inside class enum comment'],
64-
tcls_enumeration.comment.text)
65+
self._check_comment_content(['/// inside class enum comment'],
66+
tcls_enumeration.comment)
6567

6668
tmethod = tclass.member_functions()[0]
6769

6870
self.assertIn("comment", dir(tmethod))
69-
if tmethod.comment.text:
70-
self.assertEqual(["/// cxx comment", "/// with multiple lines"],
71-
tmethod.comment.text)
71+
self._check_comment_content(["/// cxx comment", "/// with multiple lines"],
72+
tmethod.comment)
7273

7374
tconstructor = tclass.constructors()[0]
7475

7576
self.assertIn("comment", dir(tconstructor))
76-
if tconstructor.comment.text:
77-
self.assertEqual(["/** doc comment */"], tconstructor.comment.text)
77+
self._check_comment_content(["/** doc comment */"], tconstructor.comment)
7878

7979
for indx, cmt in enumerate(['//! mutable field comment',
8080
"/// bit field comment"]):
8181
tvariable = tclass.variables()[indx]
8282
self.assertIn("comment", dir(tvariable))
83-
if tvariable.comment.text:
84-
self.assertEqual([cmt], tvariable.comment.text)
83+
self._check_comment_content([cmt], tvariable.comment)
8584

8685

8786
def create_suite():

0 commit comments

Comments
 (0)