|
4 | 4 | # See http://www.boost.org/LICENSE_1_0.txt |
5 | 5 |
|
6 | 6 | import sys |
7 | | -import unittest |
| 7 | +import pytest |
8 | 8 |
|
9 | | -from . import parser_test_case |
| 9 | +from . import autoconfig |
10 | 10 |
|
11 | 11 | from pygccxml import parser |
12 | 12 | from pygccxml import declarations |
13 | 13 |
|
14 | 14 |
|
15 | | -class Test(parser_test_case.parser_test_case_t): |
16 | | - |
17 | | - def __init__(self, *args): |
18 | | - parser_test_case.parser_test_case_t.__init__(self, *args) |
19 | | - self.__files = [ |
20 | | - 'core_ns_join_1.hpp', |
21 | | - 'core_ns_join_2.hpp', |
22 | | - 'core_ns_join_3.hpp', |
23 | | - 'core_membership.hpp', |
24 | | - 'core_class_hierarchy.hpp', |
25 | | - 'core_types.hpp', |
26 | | - 'core_diamand_hierarchy_base.hpp', |
27 | | - 'core_diamand_hierarchy_derived1.hpp', |
28 | | - 'core_diamand_hierarchy_derived2.hpp', |
29 | | - 'core_diamand_hierarchy_final_derived.hpp', |
30 | | - 'core_overloads_1.hpp', |
31 | | - 'core_overloads_2.hpp', |
32 | | - 'typedefs_base.hpp'] |
33 | | - |
34 | | - # for i, f in enumerate(self.__files): |
35 | | - # f = parser.create_cached_source_fc( |
36 | | - # os.path.join( autoconfig.data_directory, f) |
37 | | - # , os.path.join( autoconfig.data_directory, f + '.xml') ) |
38 | | - # self.__files[i] = f |
39 | | - prj_reader = parser.project_reader_t(self.config) |
40 | | - self.decls = prj_reader.read_files( |
41 | | - self.__files, |
42 | | - compilation_mode=parser.COMPILATION_MODE.FILE_BY_FILE) |
43 | | - |
44 | | - def test_printer(self): |
45 | | - |
46 | | - # Redirect sys.stdout to a class with a writer doing nothing |
47 | | - # This greatly reduces the size of the test output and makes |
48 | | - # test log files readable. |
49 | | - # Note: flush needs to be defined; because if not this will |
50 | | - # result in an AttributeError on call. |
51 | | - class DontPrint(object): |
52 | | - def write(*args): |
53 | | - pass |
54 | | - |
55 | | - def flush(*args): |
56 | | - pass |
57 | | - sys.stdout = DontPrint() |
58 | | - |
59 | | - declarations.print_declarations(self.decls) |
60 | | - |
61 | | - def test__str__(self): |
62 | | - decls = declarations.make_flatten(self.decls) |
63 | | - for decl in decls: |
64 | | - str(decl) |
65 | | - |
66 | | - |
67 | | -def create_suite(): |
68 | | - suite = unittest.TestSuite() |
69 | | - suite.addTest( |
70 | | - unittest.TestLoader().loadTestsFromTestCase(testCaseClass=Test)) |
71 | | - return suite |
72 | | - |
73 | | - |
74 | | -def run_suite(): |
75 | | - unittest.TextTestRunner(verbosity=2).run(create_suite()) |
76 | | - |
77 | | - |
78 | | -if __name__ == "__main__": |
79 | | - run_suite() |
| 15 | +TEST_FILES = [ |
| 16 | + 'core_ns_join_1.hpp', |
| 17 | + 'core_ns_join_2.hpp', |
| 18 | + 'core_ns_join_3.hpp', |
| 19 | + 'core_membership.hpp', |
| 20 | + 'core_class_hierarchy.hpp', |
| 21 | + 'core_types.hpp', |
| 22 | + 'core_diamand_hierarchy_base.hpp', |
| 23 | + 'core_diamand_hierarchy_derived1.hpp', |
| 24 | + 'core_diamand_hierarchy_derived2.hpp', |
| 25 | + 'core_diamand_hierarchy_final_derived.hpp', |
| 26 | + 'core_overloads_1.hpp', |
| 27 | + 'core_overloads_2.hpp', |
| 28 | + 'typedefs_base.hpp', |
| 29 | +] |
| 30 | + |
| 31 | + |
| 32 | +@pytest.fixture |
| 33 | +def decls(): |
| 34 | + COMPILATION_MODE = parser.COMPILATION_MODE.FILE_BY_FILE |
| 35 | + config = autoconfig.cxx_parsers_cfg.config.clone() |
| 36 | + config.castxml_epic_version = 1 |
| 37 | + decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) |
| 38 | + return decls |
| 39 | + |
| 40 | + |
| 41 | +def test_printer(decls): |
| 42 | + # Redirect sys.stdout to a class with a writer doing nothing |
| 43 | + # This greatly reduces the size of the test output and makes |
| 44 | + # test log files readable. |
| 45 | + # Note: flush needs to be defined; because if not this will |
| 46 | + # result in an AttributeError on call. |
| 47 | + class DontPrint(object): |
| 48 | + def write(*args): |
| 49 | + pass |
| 50 | + |
| 51 | + def flush(*args): |
| 52 | + pass |
| 53 | + sys.stdout = DontPrint() |
| 54 | + |
| 55 | + declarations.print_declarations(decls) |
| 56 | + |
| 57 | + |
| 58 | +def test__str__(decls): |
| 59 | + decls = declarations.make_flatten(decls) |
| 60 | + for decl in decls: |
| 61 | + str(decl) |
0 commit comments