Skip to content

Refactor connection base#455

Open
ahobeost wants to merge 25 commits intomasterfrom
RefactorConnectionBase
Open

Refactor connection base#455
ahobeost wants to merge 25 commits intomasterfrom
RefactorConnectionBase

Conversation

@ahobeost
Copy link
Copy Markdown
Contributor

@ahobeost ahobeost commented May 25, 2023

During code review, we noticed most of the niceConn functionality was massively duplicated code.
This refactoring is especially needed, because this behavior has been very buggy in the past.

  • Further adjust niceConn to have a factory based on the port sides.
  • Assess testability of new polymorphic classes
  • Add tests for each polymorphic class

ahobeost and others added 25 commits May 25, 2023 14:13
Trying to exclude abstract methods and not implemented cases from the coverage reports
…d some dataclass implementation to use __post_init__
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Jun 7, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

No Coverage information No Coverage information
1.6% 1.6% Duplication

return _tp.cast(_dpc.DoublePipeConnection, mock)


def createSimpleSPConnectionMock(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahobeost: make testStorage use this mock and the dp version as well



class FakeSegmentItem(_fc.StrictMockBase):
def __init__(self, startNode, endNode, connection, **kwargs):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to own module

yEndCoordsExpected=[15.666, 15.666, 100.0],
)

def _runNiceConnWithTests( # pylint: disable = too-many-arguments, too-many-locals
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

helper class would fix the too-many-locals issue

patchString="NiceConnectorBothZero",
connectorType=_gnc.NiceConnectorBothZero,
addItemCount=1,
fromPortSide=0,
Copy link
Copy Markdown
Contributor Author

@ahobeost ahobeost Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use clear variables for the port sides, here:
left=0, right=1, top=2, bottom=3 <- may not be correct!
with enums!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then, the tests could be called "bothLeft" etc.

fullPatchString = "trnsysGUI.connection.getNiceConnector." + patchString + "._addGraphicsItems"
with _m.patch(fullPatchString, return_value=None) as mockMethod:
if patchString == "NiceConnectorFromAbove":
connectorType(dpConnection, segmentItemFactory, rad, fromSide=fromPortSide).createNiceConn()
Copy link
Copy Markdown
Contributor Author

@ahobeost ahobeost Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get Connector first, use method after.

if a:
    return x
if b:
    return y

def _runNiceConn(
connectorType, dpConnection, patchString, rad, segmentItemFactory, fromPortSide=None, operation="subtract"
):
fullPatchString = "trnsysGUI.connection.getNiceConnector." + patchString + "._addGraphicsItems"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we patch the object directly, without using strings?
Does the spy still exist then?

toPortSide=2,
nrOfNewItems=9,
nSegsExpected=5,
xStartCoordsExpected=[0.0, 30.0, 30.0, 130.0, 130.0],
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coords = [(xStartNode, yStartNode), (x1, y1), (x2, y2), ..., (xEndNode, yEndNode) ]

@zuckerruebe zuckerruebe moved this from 🏗 In progress to 📋 Backlog in pytrnsys Kanban Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 📋 Backlog

Development

Successfully merging this pull request may close these issues.

2 participants