|
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 | +TEST_FILES = [ |
| 14 | + # TODO: once gccxml is removed; rename this to something like |
| 15 | + # annotate_tester |
| 16 | + "attributes_castxml.hpp", |
| 17 | +] |
13 | 18 |
|
14 | | -class Test(parser_test_case.parser_test_case_t): |
15 | | - global_ns = None |
16 | | - |
17 | | - def __init__(self, *args): |
18 | | - parser_test_case.parser_test_case_t.__init__(self, *args) |
19 | | - # TODO: once gccxml is removed; rename this to something like |
20 | | - # annotate_tester |
21 | | - self.header = "attributes_" + self.config.xml_generator + ".hpp" |
22 | | - |
23 | | - def setUp(self): |
24 | | - # Reset flags before each test |
25 | | - self.config.flags = "" |
26 | | - |
27 | | - def test_attributes(self): |
28 | | - |
29 | | - decls = parser.parse([self.header], self.config) |
30 | | - Test.global_ns = declarations.get_global_namespace(decls) |
31 | | - Test.global_ns.init_optimizer() |
32 | | - |
33 | | - numeric = self.global_ns.class_('numeric_t') |
34 | | - do_nothing = numeric.member_function('do_nothing') |
35 | | - arg = do_nothing.arguments[0] |
36 | | - |
37 | | - generator = self.config.xml_generator_from_xml_file |
38 | | - if generator.is_castxml1 or \ |
39 | | - (generator.is_castxml and |
40 | | - float(generator.xml_output_version) >= 1.137): |
41 | | - # This works since: |
42 | | - # https://github.com/CastXML/CastXML/issues/25 |
43 | | - # https://github.com/CastXML/CastXML/pull/26 |
44 | | - # https://github.com/CastXML/CastXML/pull/27 |
45 | | - # The version bump to 1.137 came way later but this is the |
46 | | - # only way to make sure the test is running correctly |
47 | | - self.assertTrue("annotate(sealed)" == numeric.attributes) |
48 | | - self.assertTrue("annotate(no throw)" == do_nothing.attributes) |
49 | | - self.assertTrue("annotate(out)" == arg.attributes) |
50 | | - self.assertTrue( |
51 | | - numeric.member_operators(name="=")[0].attributes is None) |
52 | | - else: |
53 | | - self.assertTrue("gccxml(no throw)" == do_nothing.attributes) |
54 | | - self.assertTrue("gccxml(out)" == arg.attributes) |
55 | | - |
56 | | - def test_attributes_thiscall(self): |
57 | | - """ |
58 | | - Test attributes with the "f2" flag |
59 | | -
|
60 | | - """ |
61 | | - if self.config.compiler != "msvc": |
62 | | - return |
63 | | - |
64 | | - self.config.flags = ["f2"] |
65 | | - |
66 | | - decls = parser.parse([self.header], self.config) |
67 | | - Test.global_ns = declarations.get_global_namespace(decls) |
68 | | - Test.global_ns.init_optimizer() |
69 | | - |
70 | | - numeric = self.global_ns.class_('numeric_t') |
71 | | - do_nothing = numeric.member_function('do_nothing') |
72 | | - arg = do_nothing.arguments[0] |
73 | | - |
74 | | - generator = self.config.xml_generator_from_xml_file |
75 | | - if generator.is_castxml1 or ( |
76 | | - generator.is_castxml and |
77 | | - float(generator.xml_output_version) >= 1.137): |
78 | | - self.assertTrue("annotate(sealed)" == numeric.attributes) |
79 | | - self.assertTrue("annotate(out)" == arg.attributes) |
80 | | - |
81 | | - self.assertTrue( |
82 | | - "__thiscall__ annotate(no throw)" == do_nothing.attributes) |
83 | | - self.assertTrue( |
84 | | - numeric.member_operators(name="=")[0].attributes == |
85 | | - "__thiscall__") |
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() |
| 19 | + |
| 20 | +@pytest.fixture |
| 21 | +def global_ns(): |
| 22 | + COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE |
| 23 | + INIT_OPTIMIZER = True |
| 24 | + config = autoconfig.cxx_parsers_cfg.config.clone() |
| 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 |
| 30 | + |
| 31 | + |
| 32 | +def test_attributes(global_ns): |
| 33 | + numeric = global_ns.class_('numeric_t') |
| 34 | + do_nothing = numeric.member_function('do_nothing') |
| 35 | + arg = do_nothing.arguments[0] |
| 36 | + assert "annotate(sealed)" == numeric.attributes |
| 37 | + assert "annotate(no throw)" == do_nothing.attributes |
| 38 | + assert "annotate(out)" == arg.attributes |
| 39 | + assert numeric.member_operators(name="=")[0].attributes is None |
| 40 | + |
| 41 | + |
| 42 | +def test_attributes_thiscall(): |
| 43 | + """ |
| 44 | + Test attributes with the "f2" flag |
| 45 | +
|
| 46 | + """ |
| 47 | + |
| 48 | + COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE |
| 49 | + config = autoconfig.cxx_parsers_cfg.config.clone() |
| 50 | + |
| 51 | + config.flags = ["f2"] |
| 52 | + |
| 53 | + decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) |
| 54 | + global_ns = declarations.get_global_namespace(decls) |
| 55 | + global_ns.init_optimizer() |
| 56 | + |
| 57 | + numeric = global_ns.class_('numeric_t') |
| 58 | + do_nothing = numeric.member_function('do_nothing') |
| 59 | + arg = do_nothing.arguments[0] |
| 60 | + |
| 61 | + assert "annotate(sealed)" == numeric.attributes |
| 62 | + assert "annotate(out)" == arg.attributes |
| 63 | + |
| 64 | + assert "annotate(no throw)" == do_nothing.attributes |
| 65 | + assert numeric.member_operators(name="=")[0].attributes is None |
0 commit comments