Skip to content

Commit

Permalink
[OPT-780] test improvements, connector strategy refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
smaneroiriusrisk committed Apr 27, 2023
1 parent 8c551b9 commit 384ae92
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ def __subclasshook__(cls, subclass):
or NotImplemented)

@abc.abstractmethod
def create_connector(self, shape: Shape, **kwargs) -> Optional[DiagramConnector]:
def create_connector(self, shape: Shape, components=None) -> Optional[DiagramConnector]:
"""creates the OTM Dataflow from the vsdx shape"""
raise NotImplementedError
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CreateConnectorByConnects(CreateConnectorStrategy):
Strategy to create a connector from the shape connects
"""

def create_connector(self, shape: Shape, **kwargs) -> Optional[DiagramConnector]:
def create_connector(self, shape: Shape, components=None) -> Optional[DiagramConnector]:
connected_shapes = shape.connects
if not self.are_two_different_shapes(connected_shapes):
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ def __init__(self):
self.tolerance = 0.09
self.representer: SimpleComponentRepresenter() = SimpleComponentRepresenter()

def create_connector(self, shape: Shape, **kwargs) -> Optional[DiagramConnector]:
def create_connector(self, shape: Shape, components=None) -> Optional[DiagramConnector]:
if not shape.begin_x or not shape.begin_y or not shape.end_x or not shape.end_y:
return None
begin_line = Point(shape.begin_x, shape.begin_y)
end_line = Point(shape.end_x, shape.end_y)
if not begin_line or not end_line:
return None

components = kwargs.get('components')
if not components:
return None
origin = self.__match_component(begin_line, components)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from unittest.mock import MagicMock, Mock

from pytest import mark
from pytest import mark, param

from slp_visio.slp_visio.load.strategies.connector.impl.create_connector_by_line_coordinates import \
CreateConnectorByLineCoordinates
Expand All @@ -15,19 +15,31 @@ def mock_component(_id, pos):


class TestCreateConnectorByLineCoordinates:

@mark.parametrize('line,start,end', [
(['1040', '-560', '1290', '-560'], ['960', '-600', '80', '80'], ['1290', '-590', '60', '60']),
([1040, -560, 1290, -560], [960, -600, 80, 80], [1290, -590, 60, 60]),
(['1.04', '-0.56', '1.290', '-0.56'], ['0.96', '-0.6', '0.08', '0.08'], ['1.290', '-0.590', '0.06', '0.06']),
([1.04, -0.56, 1.290, -0.56], [0.96, -0.6, 0.08, 0.08], [1.290, -0.590, 0.06, 0.06]),
([1.04 + 0.09, -0.56, 1.290, -0.56], [0.96, -0.6, 0.08, 0.08], [1.290, -0.590, 0.06, 0.06]),
([0.96 - 0.09, -0.56, 1.290, -0.56], [0.96, -0.6, 0.08, 0.08], [1.290, -0.590, 0.06, 0.06]),
([1.04, -0.6 + 0.08 + 0.09, 1.290, -0.56], [0.96, -0.6, 0.08, 0.08], [1.290, -0.590, 0.06, 0.06]),
([1.04, -0.56, 1.29 - 0.09, -0.56], [0.96, -0.6, 0.08, 0.08], [1.290, -0.590, 0.06, 0.06]),
([1.04, -0.56, 1.29 + 0.06 + 0.09, -0.56], [0.96, -0.6, 0.08, 0.08], [1.290, -0.590, 0.06, 0.06]),
([1.04, -0.56, 1.29, -0.59 - 0.09], [0.96, -0.6, 0.08, 0.08], [1.290, -0.590, 0.06, 0.06]),
([1.04, -0.56, 1.29, -0.59 + 0.06 + 0.09], [0.96, -0.6, 0.08, 0.08], [1.290, -0.590, 0.06, 0.06]),
param(['1040', '-560', '1290', '-560'], ['960', '-600', '80', '80'], ['1290', '-590', '60', '60'],
id="perfect_match,strings,big_scale"),
param([1040, -560, 1290, -560], [960, -600, 80, 80], [1290, -590, 60, 60],
id="perfect_match,big_scale"),
param(['1.04', '-0.56', '1.29', '-0.56'], ['0.96', '-0.6', '0.08', '0.08'], ['1.29', '-0.59', '0.06', '0.06'],
id="perfect_match,strings"),
param([1.04, -0.56, 1.29, -0.56], [0.96, -0.6, 0.08, 0.08], [1.29, -0.59, 0.06, 0.06],
id="perfect_match"),
param([1.04 + 0.09, -0.56, 1.29, -0.56], [0.96, -0.6, 0.08, 0.08], [1.29, -0.59, 0.06, 0.06],
id="start connected by right tolerance, end connected"),
param([0.96 - 0.09, -0.56, 1.29, -0.56], [0.96, -0.6, 0.08, 0.08], [1.29, -0.59, 0.06, 0.06],
id="start connected by left tolerance, end connected"),
param([1.04, -0.6 - 0.09, 1.29, -0.56], [0.96, -0.6, 0.08, 0.08], [1.29, -0.59, 0.06, 0.06],
id="start connected by top tolerance, end connected"),
param([1.04, -0.6 + 0.08 + 0.09, 1.29, -0.56], [0.96, -0.6, 0.08, 0.08], [1.29, -0.59, 0.06, 0.06],
id="start connected by bottom tolerance, end connected"),
param([1.04, -0.56, 1.29 - 0.09, -0.56], [0.96, -0.6, 0.08, 0.08], [1.29, -0.59, 0.06, 0.06],
id="start connected, end connected by left tolerance"),
param([1.04, -0.56, 1.29 + 0.06 + 0.09, -0.56], [0.96, -0.6, 0.08, 0.08], [1.29, -0.59, 0.06, 0.06],
id="start connected, end connected by right tolerance"),
param([1.04, -0.56, 1.29, -0.59 - 0.09], [0.96, -0.6, 0.08, 0.08], [1.29, -0.59, 0.06, 0.06],
id="start connected, end connected by top tolerance"),
param([1.04, -0.56, 1.29, -0.59 + 0.06 + 0.09], [0.96, -0.6, 0.08, 0.08], [1.29, -0.59, 0.06, 0.06],
id="start connected, end connected by bottom tolerance"),
])
def test_create_connector_with_line_touching_component(self, line, start, end):
# GIVEN a visio connector shape
Expand All @@ -47,16 +59,24 @@ def test_create_connector_with_line_touching_component(self, line, start, end):
assert diagram_connector.to_id == 333
assert not diagram_connector.bidirectional


@mark.parametrize('line,start,end', [
([1.04 + 0.09 + 0.006, -0.56, 1.290, -0.56], [0.96, -0.6, 0.08, 0.08], [1.290, -0.590, 0.06, 0.06]),
([1.04 + 0.09 + 0.006, -0.56, 1.290, -0.56], [0.96, -0.6, 0.08, 0.08], [1.290, -0.590, 0.06, 0.06]),
([1.04 + 0.09 + 0.006, -0.56, 1.290, -0.56], [0.96, -0.6, 0.08, 0.08], [1.290, -0.590, 0.06, 0.06]),
([0.96 - 0.09 - 0.006, -0.56, 1.290, -0.56], [0.96, -0.6, 0.08, 0.08], [1.290, -0.590, 0.06, 0.06]),
([1.04, -0.6 + 0.08 + 0.09 + 0.006, 1.290, -0.56], [0.96, -0.6, 0.08, 0.08], [1.290, -0.590, 0.06, 0.06]),
([1.04, -0.56, 1.29 - 0.09 - 0.006, -0.56], [0.96, -0.6, 0.08, 0.08], [1.290, -0.590, 0.06, 0.06]),
([1.04, -0.56, 1.29 + 0.06 + 0.09 + 0.006, -0.56], [0.96, -0.6, 0.08, 0.08], [1.290, -0.590, 0.06, 0.06]),
([1.04, -0.56, 1.29, -0.59 - 0.09 - 0.006], [0.96, -0.6, 0.08, 0.08], [1.290, -0.590, 0.06, 0.06]),
([1.04, -0.56, 1.29, -0.59 + 0.06 + 0.09 + 0.006], [0.96, -0.6, 0.08, 0.08], [1.290, -0.590, 0.06, 0.06]),
param([1.04 + 0.09 + 0.006, -0.56, 1.29, -0.56], [0.96, -0.6, 0.08, 0.08], [1.29, -0.59, 0.06, 0.06],
id="start not connected by right intolerance, end connected"),
param([0.96 - 0.09 - 0.006, -0.56, 1.29, -0.56], [0.96, -0.6, 0.08, 0.08], [1.29, -0.59, 0.06, 0.06],
id="start not connected by left intolerance, end connected"),
param([1.04, -0.6 + 0.08 + 0.09 + 0.006, 1.29, -0.56], [0.96, -0.6, 0.08, 0.08], [1.29, -0.59, 0.06, 0.06],
id="start not connected by bottom intolerance, end connected"),
param([1.04, -0.6 - 0.09 - 0.006, 1.29, -0.56], [0.96, -0.6, 0.08, 0.08], [1.29, -0.59, 0.06, 0.06],
id="start not connected by top intolerance, end connected", ),
param([1.04, -0.56, 1.29 - 0.09 - 0.006, -0.56], [0.96, -0.6, 0.08, 0.08], [1.29, -0.59, 0.06, 0.06],
id="start connected, end not connected by left intolerance"),
param([1.04, -0.56, 1.29 + 0.06 + 0.09 + 0.006, -0.56], [0.96, -0.6, 0.08, 0.08], [1.29, -0.59, 0.06, 0.06],
id="start connected, end not connected by right intolerance"),
param([1.04, -0.56, 1.29, -0.59 - 0.09 - 0.006], [0.96, -0.6, 0.08, 0.08], [1.29, -0.59, 0.06, 0.06],
id="start connected, end not connected by top intolerance"),
param([1.04, -0.56, 1.29, -0.59 + 0.06 + 0.09 + 0.006], [0.96, -0.6, 0.08, 0.08], [1.29, -0.59, 0.06, 0.06],
id="start connected, end not connected by bottom intolerance"),
])
def test_create_connector_with_line_not_touching(self, line, start, end):
# GIVEN a visio connector shape
Expand Down

0 comments on commit 384ae92

Please sign in to comment.