11
2- from typing import Dict , List
2+ from typing import Dict , List , Tuple
33from importlib import import_module
44
5+ from pytest import fixture
6+
57from py2puml .domain .umlitem import UmlItem
68from py2puml .domain .umlclass import UmlClass , UmlAttribute
79from py2puml .domain .umlrelation import UmlRelation , RelType
1416from tests .asserts .relation import assert_relation
1517
1618
17- def test_inspect_module_should_find_static_and_instance_attributes ():
18- domain_items_by_fqn : Dict [str , UmlItem ] = {}
19- domain_relations : List [UmlRelation ] = []
19+ @fixture (scope = 'function' )
20+ def domain_items_by_fqn () -> Dict [str , UmlItem ]:
21+ return {}
22+
23+ @fixture (scope = 'function' )
24+ def domain_relations () -> List [UmlRelation ]:
25+ return []
26+
27+ def test_inspect_module_should_find_static_and_instance_attributes (
28+ domain_items_by_fqn : Dict [str , UmlItem ], domain_relations : List [UmlRelation ]
29+ ):
2030 inspect_module (
2131 import_module ('tests.modules.withconstructor' ),
2232 'tests.modules.withconstructor' ,
@@ -70,9 +80,9 @@ def test_inspect_module_should_find_static_and_instance_attributes():
7080 RelType .COMPOSITION
7181 )
7282
73- def test_inspect_module_should_find_abstract_class ():
74- domain_items_by_fqn : Dict [str , UmlItem ] = {}
75- domain_relations : List [ UmlRelation ] = []
83+ def test_inspect_module_should_find_abstract_class (
84+ domain_items_by_fqn : Dict [str , UmlItem ], domain_relations : List [ UmlRelation ]
85+ ):
7686 inspect_module (
7787 import_module ('tests.modules.withabstract' ),
7888 'tests.modules.withabstract' ,
@@ -91,9 +101,9 @@ def test_inspect_module_should_find_abstract_class():
91101 assert domain_relations [0 ].source_fqn == 'tests.modules.withabstract.ClassTemplate'
92102 assert domain_relations [0 ].target_fqn == 'tests.modules.withabstract.ConcreteClass'
93103
94- def test_inspect_module_parse_class_constructor_should_not_process_inherited_constructor ():
95- domain_items_by_fqn : Dict [str , UmlItem ] = {}
96- domain_relations : List [ UmlRelation ] = []
104+ def test_inspect_module_parse_class_constructor_should_not_process_inherited_constructor (
105+ domain_items_by_fqn : Dict [str , UmlItem ], domain_relations : List [ UmlRelation ]
106+ ):
97107 # inspects the two sub-modules
98108 inspect_module (
99109 import_module ('tests.modules.withinheritedconstructor.point' ),
@@ -127,9 +137,9 @@ def test_inspect_module_parse_class_constructor_should_not_process_inherited_con
127137 unit_attribute = metric_origin_umlitem .attributes [0 ]
128138 assert_attribute (unit_attribute , 'unit' , 'str' , expected_staticity = True )
129139
130- def test_inspect_module_should_unwrap_decorated_constructor ():
131- domain_items_by_fqn : Dict [str , UmlItem ] = {}
132- domain_relations : List [ UmlRelation ] = []
140+ def test_inspect_module_should_unwrap_decorated_constructor (
141+ domain_items_by_fqn : Dict [str , UmlItem ], domain_relations : List [ UmlRelation ]
142+ ):
133143 inspect_module (
134144 import_module ('tests.modules.withwrappedconstructor' ),
135145 'tests.modules.withwrappedconstructor' ,
@@ -148,3 +158,26 @@ def test_inspect_module_should_unwrap_decorated_constructor():
148158 # PointDecoratedWithoutWrapping UmlClass
149159 point_without_wrapping_umlitem : UmlClass = domain_items_by_fqn ['tests.modules.withwrappedconstructor.PointDecoratedWithoutWrapping' ]
150160 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'
161+
162+ def test_inspect_module_should_handle_compound_types_with_numbers_in_their_name (
163+ domain_items_by_fqn : Dict [str , UmlItem ], domain_relations : List [UmlRelation ]
164+ ):
165+ fqdn = 'tests.modules.withcompoundtypewithdigits'
166+ inspect_module (
167+ import_module (fqdn ), fqdn ,
168+ domain_items_by_fqn , domain_relations
169+ )
170+
171+ assert len (domain_items_by_fqn ) == 2 , 'two classes must be inspected'
172+
173+ # IPv6 UmlClass
174+ ipv6_umlitem : UmlClass = domain_items_by_fqn [f'{ fqdn } .IPv6' ]
175+ assert len (ipv6_umlitem .attributes ) == 1 , '1 attributes of IPv6 must be inspected'
176+ address_attribute = ipv6_umlitem .attributes [0 ]
177+ assert_attribute (address_attribute , 'address' , 'str' , expected_staticity = False )
178+
179+ # Multicast UmlClass
180+ multicast_umlitem : UmlClass = domain_items_by_fqn [f'{ fqdn } .Multicast' ]
181+ assert len (multicast_umlitem .attributes ) == 1 , '1 attributes of Multicast must be inspected'
182+ address_attribute = multicast_umlitem .attributes [0 ]
183+ assert_attribute (address_attribute , 'addresses' , 'List[IPv6]' , expected_staticity = False )
0 commit comments