Skip to content

Commit 6c0dbd6

Browse files
grayfox88lucsorel
authored andcommitted
Add test cases for subclasses.
1 parent 3531cad commit 6c0dbd6

File tree

5 files changed

+60
-10
lines changed

5 files changed

+60
-10
lines changed

py2puml/asserts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def assert_py2puml_is_stringio(domain_path: str, domain_module: str, expected_co
2020
def assert_multilines(actual_multilines: List[str], expected_multilines: Iterable[str]):
2121
line_index = 0
2222
for line_index, (actual_line, expected_line) in enumerate(zip(actual_multilines, expected_multilines)):
23-
# print(actual_line)
23+
# print(actual_line[:-1])
2424
assert actual_line == expected_line, f'actual and expected contents have changed at line {line_index + 1}: {actual_line=}, {expected_line=}'
2525

2626
assert line_index + 1 == len(actual_multilines), f'actual and expected diagrams have {line_index + 1} lines'
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/puml_files/with_methods.puml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
@startuml tests.modules.withmethods
2-
namespace tests.modules.withmethods.withmethods {}
3-
class tests.modules.withmethods.withmethods.Coordinates {
4-
x: float
5-
y: float
2+
namespace tests.modules.withmethods {
3+
namespace withmethods {}
4+
namespace withinheritedmethods {}
65
}
76
class tests.modules.withmethods.withmethods.Point {
87
PI: float {static}
@@ -12,9 +11,21 @@ class tests.modules.withmethods.withmethods.Point {
1211
time_resolution: Tuple[str, TimeUnit]
1312
x: int
1413
y: str
15-
from_values(x: int, y: str, u: float, z: List[int]) -> 'Point'
14+
from_values(x: int, y: str, u: float) -> 'Point'
15+
get_coordinates(self)
16+
}
17+
class tests.modules.withmethods.withinheritedmethods.ThreeDimensionalPoint {
18+
z: float
19+
check_positive(self) -> bool
20+
from_values(x: int, y: str, u: float) -> 'Point'
1621
get_coordinates(self)
22+
move(self, offset: int)
23+
}
24+
class tests.modules.withmethods.withmethods.Coordinates {
25+
x: float
26+
y: float
1727
}
1828
tests.modules.withmethods.withmethods.Point *-- tests.modules.withmethods.withmethods.Coordinates
29+
tests.modules.withmethods.withmethods.Point <|-- tests.modules.withmethods.withinheritedmethods.ThreeDimensionalPoint
1930
footer Generated by //py2puml//
2031
@enduml

tests/py2puml/inspection/test_inspectclass.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,29 @@ def test_inspect_module_should_find_methods(
200200
assert point_umlitem.methods[0].name == 'from_values' # 2 - Static method
201201
assert point_umlitem.methods[1].name == 'get_coordinates' # 1b - Instance method (regular)
202202
# FIXME: use 'assert_method' once UmlMethod restructured
203+
204+
205+
def test_inspect_module_inherited_methods(
206+
domain_items_by_fqn: Dict[str, UmlItem], domain_relations: List[UmlRelation]
207+
):
208+
'''
209+
Test that inherited methods are not included in subclasses
210+
'''
211+
212+
inspect_module(
213+
import_module('tests.modules.withmethods.withinheritedmethods'),
214+
'tests.modules.withmethods.withinheritedmethods',
215+
domain_items_by_fqn, domain_relations
216+
)
217+
218+
# ThreeDimensionalCoordinates UmlClass
219+
coordinates_3d_umlitem: UmlClass = domain_items_by_fqn['tests.modules.withmethods.withinheritedmethods.ThreeDimensionalPoint']
220+
221+
# FIXME inherited methods should not be mentionned
222+
assert len(coordinates_3d_umlitem.methods) == 4
223+
224+
assert coordinates_3d_umlitem.methods[0].name == 'check_positive'
225+
assert coordinates_3d_umlitem.methods[1].name == 'from_values' # inherited method
226+
assert coordinates_3d_umlitem.methods[2].name == 'get_coordinates' # inherited method
227+
assert coordinates_3d_umlitem.methods[3].name == 'move'
228+
# FIXME: use 'assert_method' once UmlMethod restructured

0 commit comments

Comments
 (0)