|
3 | 3 | # Distributed under the Boost Software License, Version 1.0. |
4 | 4 | # See http://www.boost.org/LICENSE_1_0.txt |
5 | 5 |
|
6 | | -import unittest |
| 6 | +import pytest |
7 | 7 |
|
8 | | -from . import parser_test_case |
| 8 | +from . import autoconfig |
9 | 9 |
|
10 | 10 | from pygccxml import parser |
11 | 11 | from pygccxml import declarations |
12 | 12 |
|
13 | 13 |
|
14 | | -class Test(parser_test_case.parser_test_case_t): |
15 | | - global_ns = None |
| 14 | +TEST_FILES = [ |
| 15 | + "test_comments.hpp", |
| 16 | +] |
16 | 17 |
|
17 | | - def __init__(self, *args): |
18 | | - parser_test_case.parser_test_case_t.__init__(self, *args) |
19 | | - self.header = "test_comments.hpp" |
20 | | - self.global_ns = None |
21 | | - self.config.castxml_epic_version = 1 |
22 | 18 |
|
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") |
| 19 | +@pytest.fixture |
| 20 | +def global_ns(): |
| 21 | + COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE |
| 22 | + INIT_OPTIMIZER = True |
| 23 | + config = autoconfig.cxx_parsers_cfg.config.clone() |
| 24 | + config.castxml_epic_version = 1 |
| 25 | + decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) |
| 26 | + global_ns = declarations.get_global_namespace(decls) |
| 27 | + if INIT_OPTIMIZER: |
| 28 | + global_ns.init_optimizer() |
| 29 | + return global_ns |
28 | 30 |
|
29 | | - def setUp(self): |
30 | 31 |
|
31 | | - if not self.global_ns: |
32 | | - decls = parser.parse([self.header], self.config) |
33 | | - Test.global_ns = declarations.get_global_namespace(decls) |
34 | | - Test.xml_generator_from_xml_file = \ |
35 | | - self.config.xml_generator_from_xml_file |
36 | | - self.xml_generator_from_xml_file = Test.xml_generator_from_xml_file |
| 32 | +def _check_comment_content(list, comment_decl): |
| 33 | + if comment_decl.text: |
| 34 | + assert list == comment_decl.text |
| 35 | + else: |
| 36 | + print("No text in comment to check") |
37 | 37 |
|
38 | | - self.global_ns = Test.global_ns |
39 | 38 |
|
40 | | - def test(self): |
41 | | - """ |
42 | | - Check the comment parsing |
43 | | - """ |
44 | | - if self.config.castxml_epic_version != 1: |
45 | | - # Run this test only with castxml epic version == 1 |
46 | | - return |
47 | | - tnamespace = self.global_ns.namespace("comment") |
| 39 | +def test_comments(global_ns): |
| 40 | + """ |
| 41 | + Check the comment parsing |
| 42 | + """ |
| 43 | + tnamespace = global_ns.namespace("comment") |
48 | 44 |
|
49 | | - self.assertIn("comment", dir(tnamespace)) |
50 | | - self._check_comment_content(["//! Namespace Comment", |
51 | | - "//! Across multiple lines"], |
52 | | - tnamespace.comment) |
| 45 | + assert "comment" in dir(tnamespace) |
| 46 | + _check_comment_content(["//! Namespace Comment", |
| 47 | + "//! Across multiple lines"], |
| 48 | + tnamespace.comment) |
53 | 49 |
|
54 | | - tenumeration = tnamespace.enumeration("com_enum") |
55 | | - self.assertIn("comment", dir(tenumeration)) |
56 | | - self._check_comment_content(['/// Outside Class enum comment'], |
57 | | - tenumeration.comment) |
| 50 | + tenumeration = tnamespace.enumeration("com_enum") |
| 51 | + assert "comment" in dir(tenumeration) |
| 52 | + _check_comment_content(['/// Outside Class enum comment'], |
| 53 | + tenumeration.comment) |
58 | 54 |
|
59 | | - tclass = tnamespace.class_("test") |
60 | | - self.assertIn("comment", dir(tclass)) |
61 | | - self._check_comment_content(["/** class comment */"], tclass.comment) |
| 55 | + tclass = tnamespace.class_("test") |
| 56 | + assert "comment" in dir(tclass) |
| 57 | + _check_comment_content(["/** class comment */"], tclass.comment) |
62 | 58 |
|
63 | | - tcls_enumeration = tclass.enumeration("test_enum") |
64 | | - self.assertIn("comment", dir(tcls_enumeration)) |
65 | | - self._check_comment_content(['/// inside class enum comment'], |
66 | | - tcls_enumeration.comment) |
| 59 | + tcls_enumeration = tclass.enumeration("test_enum") |
| 60 | + assert "comment" in dir(tcls_enumeration) |
| 61 | + _check_comment_content(['/// inside class enum comment'], |
| 62 | + tcls_enumeration.comment) |
67 | 63 |
|
68 | | - tmethod = tclass.member_functions()[0] |
| 64 | + tmethod = tclass.member_functions()[0] |
69 | 65 |
|
70 | | - self.assertIn("comment", dir(tmethod)) |
71 | | - self._check_comment_content(["/// cxx comment", |
72 | | - "/// with multiple lines"], |
73 | | - tmethod.comment) |
| 66 | + assert "comment" in dir(tmethod) |
| 67 | + _check_comment_content(["/// cxx comment", |
| 68 | + "/// with multiple lines"], |
| 69 | + tmethod.comment) |
74 | 70 |
|
75 | | - tconstructor = tclass.constructors()[0] |
| 71 | + tconstructor = tclass.constructors()[0] |
76 | 72 |
|
77 | | - self.assertIn("comment", dir(tconstructor)) |
78 | | - self._check_comment_content(["/** doc comment */"], |
79 | | - tconstructor.comment) |
| 73 | + assert "comment" in dir(tconstructor) |
| 74 | + _check_comment_content(["/** doc comment */"], |
| 75 | + tconstructor.comment) |
80 | 76 |
|
81 | | - for indx, cmt in enumerate(['//! mutable field comment', |
82 | | - "/// bit field comment"]): |
83 | | - tvariable = tclass.variables()[indx] |
84 | | - self.assertIn("comment", dir(tvariable)) |
85 | | - self._check_comment_content([cmt], tvariable.comment) |
86 | | - |
87 | | - |
88 | | -def create_suite(): |
89 | | - suite = unittest.TestSuite() |
90 | | - suite.addTest( |
91 | | - unittest.TestLoader().loadTestsFromTestCase(testCaseClass=Test)) |
92 | | - return suite |
93 | | - |
94 | | - |
95 | | -def run_suite(): |
96 | | - unittest.TextTestRunner(verbosity=2).run(create_suite()) |
97 | | - |
98 | | - |
99 | | -if __name__ == "__main__": |
100 | | - run_suite() |
| 77 | + for indx, cmt in enumerate(['//! mutable field comment', |
| 78 | + "/// bit field comment"]): |
| 79 | + tvariable = tclass.variables()[indx] |
| 80 | + assert "comment" in dir(tvariable) |
| 81 | + _check_comment_content([cmt], tvariable.comment) |
0 commit comments