33# Distributed under the Boost Software License, Version 1.0.
44# See http://www.boost.org/LICENSE_1_0.txt
55
6- import sys
7- import unittest
86import inspect
97
108from pygccxml import declarations
119
1210
13- class Test (unittest .TestCase ):
11+ def test_types_hashes ():
12+ """
13+ Test if all the type_t instances implement a hash method.
1414
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.
1817
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.
2121
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+ """
2523
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
2732
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
3233
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.
4137
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.
4540
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.
4844
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
5251
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 ()))
5952
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.
6356
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.
6659
67- """
68- self . assertIsNotNone ( hash (declarations .type_qualifiers_t ()))
60+ """
61+ assert hash (declarations .type_qualifiers_t ()) is not None
6962
7063
7164def _create_type_t_mockup (member_type ):
@@ -91,18 +84,3 @@ def __init__(self):
9184
9285 def build_decl_string (self , with_defaults = False ):
9386 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