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 sys
7
- import unittest
8
6
import inspect
9
7
10
8
from pygccxml import declarations
11
9
12
10
13
- class Test (unittest .TestCase ):
11
+ def test_types_hashes ():
12
+ """
13
+ Test if all the type_t instances implement a hash method.
14
14
15
- def test_types_hashes (self ):
16
- """
17
- Test if all the type_t instances implement a hash method.
15
+ The hash is part of the public API, as there are multiple tools
16
+ that rely on it to compare type_t instances.
18
17
19
- The hash is part of the public API, as there are multiple tools
20
- that rely on it to compare type_t instances.
18
+ The best way to test this is to instanciate dummy type_t objects
19
+ for each class that subclasses type_t, and check that the hash of
20
+ these objects is not None.
21
21
22
- The best way to test this is to instanciate dummy type_t objects
23
- for each class that subclasses type_t, and check that the hash of
24
- these objects is not None.
22
+ """
25
23
26
- """
24
+ members = inspect .getmembers (declarations , inspect .isclass )
25
+ for member in members :
26
+ member_type = member [1 ]
27
+ is_type_t_subclass = issubclass (member_type , declarations .type_t )
28
+ is_not_type_t = member_type != declarations .type_t
29
+ if is_type_t_subclass and is_not_type_t :
30
+ type_mockup = _create_type_t_mockup (member_type )
31
+ assert hash (type_mockup ) is not None
27
32
28
- if sys .version_info [:2 ] == (2 , 7 ):
29
- # _create_type_t_mockup calls inspect.signature, which does not
30
- # exist for legacy Python
31
- return
32
33
33
- members = inspect .getmembers (declarations , inspect .isclass )
34
- for member in members :
35
- member_type = member [1 ]
36
- is_type_t_subclass = issubclass (member_type , declarations .type_t )
37
- is_not_type_t = member_type != declarations .type_t
38
- if is_type_t_subclass and is_not_type_t :
39
- type_mockup = _create_type_t_mockup (member_type )
40
- self .assertIsNotNone (hash (type_mockup ))
34
+ def test_declarations_hashes ():
35
+ """
36
+ Test if all the declaration_t instances implement a hash method.
41
37
42
- def test_declarations_hashes (self ):
43
- """
44
- Test if all the declaration_t instances implement a hash method.
38
+ The hash is part of the public API, as there are multiple tools
39
+ that rely on it to compare declaration_t instances.
45
40
46
- The hash is part of the public API, as there are multiple tools
47
- that rely on it to compare declaration_t instances.
41
+ The best way to test this is to instanciate dummy declaration_t objects
42
+ for each class that subclasses declaration_t, and check that the hash
43
+ of these objects is not None.
48
44
49
- The best way to test this is to instanciate dummy declaration_t objects
50
- for each class that subclasses declaration_t, and check that the hash
51
- of these objects is not None.
45
+ """
46
+ members = inspect .getmembers (declarations , inspect .isclass )
47
+ for member in members :
48
+ member_type = member [1 ]
49
+ if issubclass (member_type , declarations .declaration_t ):
50
+ assert hash (member_type ()) is not None
52
51
53
- """
54
- members = inspect .getmembers (declarations , inspect .isclass )
55
- for member in members :
56
- member_type = member [1 ]
57
- if issubclass (member_type , declarations .declaration_t ):
58
- self .assertIsNotNone (hash (member_type ()))
59
52
60
- def test_type_qualifiers_t_hash (self ):
61
- """
62
- Test if the type_qualifiers_t instance implements a hash method.
53
+ def test_type_qualifiers_t_hash ():
54
+ """
55
+ Test if the type_qualifiers_t instance implements a hash method.
63
56
64
- The hash is part of the public API, as there are multiple tools
65
- that rely on it to compare type_qualifiers_t instances.
57
+ The hash is part of the public API, as there are multiple tools
58
+ that rely on it to compare type_qualifiers_t instances.
66
59
67
- """
68
- self . assertIsNotNone ( hash (declarations .type_qualifiers_t ()))
60
+ """
61
+ assert hash (declarations .type_qualifiers_t ()) is not None
69
62
70
63
71
64
def _create_type_t_mockup (member_type ):
@@ -91,18 +84,3 @@ def __init__(self):
91
84
92
85
def build_decl_string (self , with_defaults = False ):
93
86
return self ._decl_string
94
-
95
-
96
- def create_suite ():
97
- suite = unittest .TestSuite ()
98
- suite .addTest (
99
- unittest .TestLoader ().loadTestsFromTestCase (testCaseClass = Test ))
100
- return suite
101
-
102
-
103
- def run_suite ():
104
- unittest .TextTestRunner (verbosity = 2 ).run (create_suite ())
105
-
106
-
107
- if __name__ == "__main__" :
108
- run_suite ()
0 commit comments