Skip to content

Commit de998c1

Browse files
committed
Add test cases for subclasses.
1 parent ff60ef5 commit de998c1

File tree

5 files changed

+58
-21
lines changed

5 files changed

+58
-21
lines changed

tests/data/with_methods.puml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
@startuml
2-
class tests.modules.withmethods.withmethods.Coordinates {
3-
x: float
4-
y: float
5-
}
62
class tests.modules.withmethods.withmethods.Point {
73
PI: float {static}
4+
origin: Point {static}
85
coordinates: Coordinates
96
day_unit: TimeUnit
107
hour_unit: TimeUnit
118
time_resolution: Tuple[str, TimeUnit]
129
x: int
1310
y: str
14-
void __init__(x: int, y: str, unit: str, u: float, z: List[int])
15-
(float, float) get_coordinates()
16-
{static} Point from_values(x: int, y: str, u: float, z: List[int])
11+
{static} from_values(x: int, y: str, u: float, z: List[int]) -> Point
12+
get_coordinates() -> Tuple(float, float)
13+
__init__(x: int, y: str, unit: str, u: float, z: List[int])
14+
}
15+
class tests.modules.withmethods.withinheritedmethods.ThreeDimensionalPoint {
16+
z: float
17+
__init__(x: int, y: str, z: float)
18+
move(offset: int)
19+
check_positive() -> bool
20+
}
21+
class tests.modules.withmethods.withmethods.Coordinates {
22+
x: float
23+
y: float
1724
}
1825
tests.modules.withmethods.withmethods.Point *-- tests.modules.withmethods.withmethods.Coordinates
26+
tests.modules.withmethods.withmethods.Point <|-- tests.modules.withmethods.withinheritedmethods.ThreeDimensionalPoint
1927
@enduml
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from .withmethods import Point
2+
3+
4+
class ThreeDimensionalPoint(Point):
5+
6+
def __init__(self, x: int, y: str, z: float):
7+
super().__init__(x=x, y=y)
8+
self.z = z
9+
10+
def move(self, offset: int):
11+
self.x += offset
12+
13+
def check_positive(self) -> bool:
14+
return self.x > 0

tests/modules/withmethods/withmethods.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@ class Point:
1717
origin = Coordinates(0, 0)
1818

1919
@staticmethod
20-
def from_values(x: int, y: str, u: float, z: List[int]) -> 'Point':
21-
return Point(x, y, u, z)
20+
def from_values(x: int, y: str, u: float) -> 'Point':
21+
return Point(x, y, u)
2222

2323
def get_coordinates(self):
2424
return self.x, self.y
2525

26-
def __init__(self, x: int, y: str, unit: str, u: float, z: List[int]):
26+
def __init__(self, x: int, y: str):
2727
self.coordinates: Coordinates = Coordinates(x, float(y))
28-
# al the different imports of TimeUnit must be handled and result in the same 'short type' to display
2928
self.day_unit: withenum.TimeUnit = withenum.TimeUnit.DAYS
3029
self.hour_unit: modules.withenum.TimeUnit = modules.withenum.TimeUnit.HOURS
3130
self.time_resolution: Tuple[str, withenum.TimeUnit] = 'minute', TimeUnit.MINUTE

tests/py2puml/inspection/test_inspectclass.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,7 @@ def test_inspect_module_should_unwrap_decorated_constructor():
152152

153153

154154
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 """
155+
""" Test that methods are detected including static methods """
161156

162157
domain_items_by_fqn: Dict[str, UmlItem] = {}
163158
domain_relations: List[UmlRelation] = []
@@ -175,7 +170,28 @@ def test_inspect_module_should_find_methods():
175170
point_umlitem: UmlClass = domain_items_by_fqn['tests.modules.withmethods.withmethods.Point']
176171
assert len(point_umlitem.methods) == 3
177172

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
173+
assert point_umlitem.methods[0].name == 'from_values'
174+
assert point_umlitem.methods[1].name == 'get_coordinates'
175+
assert point_umlitem.methods[2].name == '__init__'
176+
# FIXME: use 'assert_method' once UmlMethod restructured
177+
178+
179+
def test_inspect_module_inherited_methods():
180+
""" Test that inherited methods are not included in subclasses """
181+
182+
domain_items_by_fqn: Dict[str, UmlItem] = {}
183+
domain_relations: List[UmlRelation] = []
184+
inspect_module(
185+
import_module('tests.modules.withmethods.withinheritedmethods'),
186+
'tests.modules.withmethods.withinheritedmethods',
187+
domain_items_by_fqn, domain_relations
188+
)
189+
190+
# ThreeDimensionalCoordinates UmlClass
191+
coordinates_3d_umlitem: UmlClass = domain_items_by_fqn['tests.modules.withmethods.withinheritedmethods.ThreeDimensionalPoint']
192+
assert len(coordinates_3d_umlitem.methods) == 3
193+
194+
assert coordinates_3d_umlitem.methods[0].name == '__init__'
195+
assert coordinates_3d_umlitem.methods[1].name == 'move'
196+
assert coordinates_3d_umlitem.methods[2].name == 'check_positive'
181197
# FIXME: use 'assert_method' once UmlMethod restructured

tests/py2puml/test_py2puml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_py2puml_with_subdomain():
2929

3030

3131
def test_py2puml_with_methods():
32-
""" Test py2puml with a class containing methods """
32+
""" Test py2puml with classes containing methods """
3333
with open(DATA_DIR / 'with_methods.puml', 'r', encoding='utf-8') as fref:
3434
expected_data = fref.read()
3535
puml_content = py2puml.py2puml('tests/modules/withmethods', 'tests.modules.withmethods')

0 commit comments

Comments
 (0)