Skip to content

Commit b69063e

Browse files
committed
tests: refactor / simplify
1 parent e54dcce commit b69063e

15 files changed

+574
-924
lines changed

tests/parser_test_case.py

Lines changed: 0 additions & 103 deletions
This file was deleted.

tests/test_algorithms_cache.py

Lines changed: 36 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,75 +3,58 @@
33
# Distributed under the Boost Software License, Version 1.0.
44
# See http://www.boost.org/LICENSE_1_0.txt
55

6-
import unittest
6+
import pytest
77

8-
from . import parser_test_case
8+
from . import autoconfig
99

1010
from pygccxml import parser
1111
from pygccxml import declarations
1212

1313

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']
3115

32-
cls_full_name = declarations.full_name(cls)
33-
self.assertTrue(cls.cache.full_name == cls_full_name)
3416

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
4225

43-
enum_declaration_path = declarations.declaration_path(enum)
44-
self.assertTrue(enum.cache.declaration_path == enum_declaration_path)
4526

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')
5029

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
5332

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
6235

36+
enum = cls.enumeration('ENestedPublic')
6337

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
6840

69-
return suite
41+
enum_declaration_path = declarations.declaration_path(enum)
42+
assert enum.cache.declaration_path == enum_declaration_path
7043

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
7148

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
7451

7552

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'

tests/test_argument_without_name.py

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,41 @@
33
# Distributed under the Boost Software License, Version 1.0.
44
# See http://www.boost.org/LICENSE_1_0.txt
55

6-
import unittest
6+
import pytest
77

8-
from . import parser_test_case
8+
from . import autoconfig
99

1010
from pygccxml import parser
1111
from pygccxml import declarations
1212

13+
TEST_FILES = ['test_argument_without_name.hpp']
1314

14-
class Test(parser_test_case.parser_test_case_t):
1515

16-
def __init__(self, *args):
17-
parser_test_case.parser_test_case_t.__init__(self, *args)
18-
self.header = "test_argument_without_name.hpp"
19-
self.config.cflags = "-std=c++11"
16+
@pytest.fixture
17+
def global_ns():
18+
COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE
19+
config = autoconfig.cxx_parsers_cfg.config.clone()
20+
config.cflags = "-std=c++11"
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
2025

21-
def test_argument_without_name(self):
2226

23-
"""
24-
Test passing an object without name to a templated function.
27+
def test_argument_without_name(global_ns):
28+
"""
29+
Test passing an object without name to a templated function.
2530
26-
The test was failing when building the declaration string.
27-
The declaration string will be 'void (*)( & )'. If the passed
28-
object had a name the result would then be 'void (*)(Name & )'.
31+
The test was failing when building the declaration string.
32+
The declaration string will be 'void (*)( & )'. If the passed
33+
object had a name the result would then be 'void (*)(Name & )'.
2934
30-
See bug #55
35+
See bug #55
3136
32-
"""
37+
"""
3338

34-
decls = parser.parse([self.header], self.config)
35-
global_ns = declarations.get_global_namespace(decls)
36-
37-
criteria = declarations.calldef_matcher(name="function")
38-
free_funcs = declarations.matcher.find(criteria, global_ns)
39-
for free_func in free_funcs:
40-
decl_string = free_func.create_decl_string(with_defaults=False)
41-
self.assertEqual(decl_string, "void (*)( & )")
42-
43-
44-
def create_suite():
45-
suite = unittest.TestSuite()
46-
suite.addTest(
47-
unittest.TestLoader().loadTestsFromTestCase(testCaseClass=Test))
48-
return suite
49-
50-
51-
def run_suite():
52-
unittest.TextTestRunner(verbosity=2).run(create_suite())
53-
54-
55-
if __name__ == "__main__":
56-
run_suite()
39+
criteria = declarations.calldef_matcher(name="function")
40+
free_funcs = declarations.matcher.find(criteria, global_ns)
41+
for free_func in free_funcs:
42+
decl_string = free_func.create_decl_string(with_defaults=False)
43+
assert decl_string == "void (*)( & )"

0 commit comments

Comments
 (0)