66from py2puml .domain .umlclass import UmlClass , UmlAttribute
77from py2puml .domain .umlrelation import UmlRelation , RelType
88from py2puml .inspection .inspectmodule import inspect_module
9- from py2puml .parsing .astvisitors import ConstructorVisitor
10- from py2puml .parsing .moduleresolver import ModuleResolver
11- from py2puml .parsing .parseclassconstructor import parse_class_constructor
129
1310from tests .asserts .attribute import assert_attribute
1411from tests .asserts .relation import assert_relation
12+ from tests .asserts .method import assert_method
1513
1614
1715def test_inspect_module_should_find_static_and_instance_attributes ():
@@ -70,6 +68,7 @@ def test_inspect_module_should_find_static_and_instance_attributes():
7068 RelType .COMPOSITION
7169 )
7270
71+
7372def test_inspect_module_should_find_abstract_class ():
7473 domain_items_by_fqn : Dict [str , UmlItem ] = {}
7574 domain_relations : List [UmlRelation ] = []
@@ -91,6 +90,7 @@ def test_inspect_module_should_find_abstract_class():
9190 assert domain_relations [0 ].source_fqn == 'tests.modules.withabstract.ClassTemplate'
9291 assert domain_relations [0 ].target_fqn == 'tests.modules.withabstract.ConcreteClass'
9392
93+
9494def test_inspect_module_parse_class_constructor_should_not_process_inherited_constructor ():
9595 domain_items_by_fqn : Dict [str , UmlItem ] = {}
9696 domain_relations : List [UmlRelation ] = []
@@ -127,6 +127,7 @@ def test_inspect_module_parse_class_constructor_should_not_process_inherited_con
127127 unit_attribute = metric_origin_umlitem .attributes [0 ]
128128 assert_attribute (unit_attribute , 'unit' , 'str' , expected_staticity = True )
129129
130+
130131def test_inspect_module_should_unwrap_decorated_constructor ():
131132 domain_items_by_fqn : Dict [str , UmlItem ] = {}
132133 domain_relations : List [UmlRelation ] = []
@@ -148,3 +149,33 @@ def test_inspect_module_should_unwrap_decorated_constructor():
148149 # PointDecoratedWithoutWrapping UmlClass
149150 point_without_wrapping_umlitem : UmlClass = domain_items_by_fqn ['tests.modules.withwrappedconstructor.PointDecoratedWithoutWrapping' ]
150151 assert len (point_without_wrapping_umlitem .attributes ) == 0 , 'the attributes of the original constructor could not be found, the constructor was not wrapped by the decorator'
152+
153+
154+ def test_inspect_module_should_find_methods ():
155+ """ Test that methods are detected including static methods
156+
157+ This test case assumes that the methods will be sorted by type as follow:
158+ 1a - instance methods (special methods aka "dunder")
159+ 1b - all other instance methods
160+ 2 - static methods """
161+
162+ domain_items_by_fqn : Dict [str , UmlItem ] = {}
163+ domain_relations : List [UmlRelation ] = []
164+ inspect_module (
165+ import_module ('tests.modules.withmethods.withmethods' ),
166+ 'tests.modules.withmethods.withmethods' ,
167+ domain_items_by_fqn , domain_relations
168+ )
169+
170+ # Coordinates UmlClass
171+ coordinates_umlitem : UmlClass = domain_items_by_fqn ['tests.modules.withmethods.withmethods.Coordinates' ]
172+ assert len (coordinates_umlitem .methods ) == 0
173+
174+ # Point UmlClass
175+ point_umlitem : UmlClass = domain_items_by_fqn ['tests.modules.withmethods.withmethods.Point' ]
176+ assert len (point_umlitem .methods ) == 3
177+
178+ assert point_umlitem .methods [0 ].name == '__init__' # 1a - Instance method (special)
179+ assert point_umlitem .methods [1 ].name == 'get_coordinates' # 1b - Instance method (regular)
180+ assert point_umlitem .methods [2 ].name == 'from_values' # 2 - Static method
181+ # FIXME: use 'assert_method' once UmlMethod restructured
0 commit comments