|
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 |
| - # tester source reader |
16 |
| - COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE |
17 |
| - |
18 |
| - def __init__(self, *args): |
19 |
| - parser_test_case.parser_test_case_t.__init__(self, *args) |
20 |
| - self.header = 'core_membership.hpp' |
21 |
| - self.global_ns = None |
22 |
| - |
23 |
| - def setUp(self): |
24 |
| - decls = parser.parse([self.header], self.config) |
25 |
| - self.xml_generator_from_xml_file = \ |
26 |
| - self.config.xml_generator_from_xml_file |
27 |
| - self.global_ns = declarations.get_global_namespace(decls) |
28 |
| - |
29 |
| - def test_name_based(self): |
30 |
| - cls = self.global_ns.class_(name='class_for_nested_enums_t') |
| 14 | +TEST_FILES = ['core_membership.hpp'] |
31 | 15 |
|
32 |
| - cls_full_name = declarations.full_name(cls) |
33 |
| - self.assertTrue(cls.cache.full_name == cls_full_name) |
34 | 16 |
|
35 |
| - cls_declaration_path = declarations.declaration_path(cls) |
36 |
| - self.assertTrue(cls.cache.declaration_path == cls_declaration_path) |
37 |
| - |
38 |
| - enum = cls.enumeration('ENestedPublic') |
39 |
| - |
40 |
| - enum_full_name = declarations.full_name(enum) |
41 |
| - self.assertTrue(enum.cache.full_name == enum_full_name) |
| 17 | +@pytest.fixture |
| 18 | +def global_ns(): |
| 19 | + COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE |
| 20 | + config = autoconfig.cxx_parsers_cfg.config.clone() |
| 21 | + decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) |
| 22 | + global_ns = declarations.get_global_namespace(decls) |
| 23 | + global_ns.init_optimizer() |
| 24 | + return global_ns |
42 | 25 |
|
43 |
| - enum_declaration_path = declarations.declaration_path(enum) |
44 |
| - self.assertTrue(enum.cache.declaration_path == enum_declaration_path) |
45 | 26 |
|
46 |
| - # now we change class name, all internal decls cache should be cleared |
47 |
| - cls.name = "new_name" |
48 |
| - self.assertTrue(not cls.cache.full_name) |
49 |
| - self.assertTrue(not cls.cache.declaration_path) |
| 27 | +def test_name_based(global_ns): |
| 28 | + cls = global_ns.class_(name='class_for_nested_enums_t') |
50 | 29 |
|
51 |
| - self.assertTrue(not enum.cache.full_name) |
52 |
| - self.assertTrue(not enum.cache.declaration_path) |
| 30 | + cls_full_name = declarations.full_name(cls) |
| 31 | + assert cls.cache.full_name == cls_full_name |
53 | 32 |
|
54 |
| - def test_access_type(self): |
55 |
| - cls = self.global_ns.class_(name='class_for_nested_enums_t') |
56 |
| - enum = cls.enumeration('ENestedPublic') |
57 |
| - self.assertTrue(enum.cache.access_type == 'public') |
58 |
| - enum.cache.reset_access_type() |
59 |
| - self.assertTrue(not enum.cache.access_type) |
60 |
| - self.assertTrue('public' == cls.find_out_member_access_type(enum)) |
61 |
| - self.assertTrue(enum.cache.access_type == 'public') |
| 33 | + cls_declaration_path = declarations.declaration_path(cls) |
| 34 | + assert cls.cache.declaration_path == cls_declaration_path |
62 | 35 |
|
| 36 | + enum = cls.enumeration('ENestedPublic') |
63 | 37 |
|
64 |
| -def create_suite(): |
65 |
| - suite = unittest.TestSuite() |
66 |
| - suite.addTest( |
67 |
| - unittest.TestLoader().loadTestsFromTestCase(testCaseClass=Test)) |
| 38 | + enum_full_name = declarations.full_name(enum) |
| 39 | + assert enum.cache.full_name == enum_full_name |
68 | 40 |
|
69 |
| - return suite |
| 41 | + enum_declaration_path = declarations.declaration_path(enum) |
| 42 | + assert enum.cache.declaration_path == enum_declaration_path |
70 | 43 |
|
| 44 | + # now we change class name, all internal decls cache should be cleared |
| 45 | + cls.name = "new_name" |
| 46 | + assert not cls.cache.full_name |
| 47 | + assert not cls.cache.declaration_path |
71 | 48 |
|
72 |
| -def run_suite(): |
73 |
| - unittest.TextTestRunner(verbosity=2).run(create_suite()) |
| 49 | + assert not enum.cache.full_name |
| 50 | + assert not enum.cache.declaration_path |
74 | 51 |
|
75 | 52 |
|
76 |
| -if __name__ == "__main__": |
77 |
| - run_suite() |
| 53 | +def test_access_type(global_ns): |
| 54 | + cls = global_ns.class_(name='class_for_nested_enums_t') |
| 55 | + enum = cls.enumeration('ENestedPublic') |
| 56 | + assert enum.cache.access_type == 'public' |
| 57 | + enum.cache.reset_access_type() |
| 58 | + assert not enum.cache.access_type |
| 59 | + assert 'public' == cls.find_out_member_access_type(enum) |
| 60 | + assert enum.cache.access_type == 'public' |
0 commit comments