Skip to content

Commit c0c3f7d

Browse files
committed
Add test to make sure that all declaration_t objects implement a hash != None
1 parent d3f6e8b commit c0c3f7d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

unittests/test_hash.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ def test_types_hashes(self):
3232
type_mockup = _create_type_t_mockup(member_type)
3333
self.assertIsNotNone(hash(type_mockup))
3434

35+
def test_declarations_hashes(self):
36+
"""
37+
Test if all the declaration_t instances implement a hash method.
38+
39+
The hash is part of the public API, as there are multiple tools
40+
that rely on it to compare declaration_t instances.
41+
42+
The best way to test this is to instanciate dummy declaration_t objects
43+
for each class that subclasses declaration_t, and check that the hash
44+
of these objects is not None.
45+
46+
"""
47+
members = inspect.getmembers(declarations, inspect.isclass)
48+
for member in members:
49+
member_type = member[1]
50+
if issubclass(member_type, declarations.declaration_t):
51+
self.assertIsNotNone(hash(member_type()))
52+
3553

3654
def _create_type_t_mockup(member_type):
3755
nbr_parameters = len(inspect.signature(member_type).parameters)

0 commit comments

Comments
 (0)