From 5357ae599813650989116dd46276022c95eea683 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Wed, 11 Oct 2023 22:11:41 +0200 Subject: [PATCH] fix package name, change _parse_connection_name function name, add tests (#126) --- canals/pipeline/connections.py | 2 +- canals/pipeline/pipeline.py | 6 +++--- test/{pipelines => pipeline}/__init__.py | 0 test/{pipelines => pipeline}/integration/__init__.py | 0 .../integration/test_complex_pipeline.py | 0 .../integration/test_double_loop_pipeline.py | 0 .../test_fixed_decision_and_merge_pipeline.py | 0 .../integration/test_fixed_decision_pipeline.py | 0 .../integration/test_fixed_merging_pipeline.py | 0 .../integration/test_linear_pipeline.py | 0 .../integration/test_looping_and_merge_pipeline.py | 0 .../integration/test_looping_pipeline.py | 0 .../integration/test_parallel_branches_pipeline.py | 0 .../test_variable_decision_and_merge_pipeline.py | 0 .../integration/test_variable_decision_pipeline.py | 0 .../integration/test_variable_merging_pipeline.py | 0 test/{pipelines => pipeline}/unit/__init__.py | 0 test/{pipelines => pipeline}/unit/test_connections.py | 9 ++++++++- test/{pipelines => pipeline}/unit/test_draw.py | 0 test/{pipelines => pipeline}/unit/test_pipeline.py | 0 .../unit/test_validation_pipeline_io.py | 0 21 files changed, 12 insertions(+), 5 deletions(-) rename test/{pipelines => pipeline}/__init__.py (100%) rename test/{pipelines => pipeline}/integration/__init__.py (100%) rename test/{pipelines => pipeline}/integration/test_complex_pipeline.py (100%) rename test/{pipelines => pipeline}/integration/test_double_loop_pipeline.py (100%) rename test/{pipelines => pipeline}/integration/test_fixed_decision_and_merge_pipeline.py (100%) rename test/{pipelines => pipeline}/integration/test_fixed_decision_pipeline.py (100%) rename test/{pipelines => pipeline}/integration/test_fixed_merging_pipeline.py (100%) rename test/{pipelines => pipeline}/integration/test_linear_pipeline.py (100%) rename test/{pipelines => pipeline}/integration/test_looping_and_merge_pipeline.py (100%) rename test/{pipelines => pipeline}/integration/test_looping_pipeline.py (100%) rename test/{pipelines => pipeline}/integration/test_parallel_branches_pipeline.py (100%) rename test/{pipelines => pipeline}/integration/test_variable_decision_and_merge_pipeline.py (100%) rename test/{pipelines => pipeline}/integration/test_variable_decision_pipeline.py (100%) rename test/{pipelines => pipeline}/integration/test_variable_merging_pipeline.py (100%) rename test/{pipelines => pipeline}/unit/__init__.py (100%) rename test/{pipelines => pipeline}/unit/test_connections.py (98%) rename test/{pipelines => pipeline}/unit/test_draw.py (100%) rename test/{pipelines => pipeline}/unit/test_pipeline.py (100%) rename test/{pipelines => pipeline}/unit/test_validation_pipeline_io.py (100%) diff --git a/canals/pipeline/connections.py b/canals/pipeline/connections.py index 050a67616d..a1aac5ba56 100644 --- a/canals/pipeline/connections.py +++ b/canals/pipeline/connections.py @@ -15,7 +15,7 @@ logger = logging.getLogger(__name__) -def _parse_connection_name(connection: str) -> Tuple[str, Optional[str]]: +def parse_connection(connection: str) -> Tuple[str, Optional[str]]: """ Returns component-connection pairs from a connect_to/from string """ diff --git a/canals/pipeline/pipeline.py b/canals/pipeline/pipeline.py index 2ebb16f7a6..f03cd86730 100644 --- a/canals/pipeline/pipeline.py +++ b/canals/pipeline/pipeline.py @@ -24,7 +24,7 @@ from canals.pipeline.draw import _draw, _convert_for_debug, RenderingEngines from canals.pipeline.sockets import InputSocket, OutputSocket from canals.pipeline.validation import _validate_pipeline_input -from canals.pipeline.connections import _parse_connection_name, _find_unambiguous_connection +from canals.pipeline.connections import parse_connection, _find_unambiguous_connection from canals.utils import _type_name from canals.serialization import component_to_dict, component_from_dict @@ -249,8 +249,8 @@ def connect(self, connect_from: str, connect_to: str) -> None: not present in the pipeline, or the connections don't match by type, and so on). """ # Edges may be named explicitly by passing 'node_name.edge_name' to connect(). - from_node, from_socket_name = _parse_connection_name(connect_from) - to_node, to_socket_name = _parse_connection_name(connect_to) + from_node, from_socket_name = parse_connection(connect_from) + to_node, to_socket_name = parse_connection(connect_to) # Get the nodes data. try: diff --git a/test/pipelines/__init__.py b/test/pipeline/__init__.py similarity index 100% rename from test/pipelines/__init__.py rename to test/pipeline/__init__.py diff --git a/test/pipelines/integration/__init__.py b/test/pipeline/integration/__init__.py similarity index 100% rename from test/pipelines/integration/__init__.py rename to test/pipeline/integration/__init__.py diff --git a/test/pipelines/integration/test_complex_pipeline.py b/test/pipeline/integration/test_complex_pipeline.py similarity index 100% rename from test/pipelines/integration/test_complex_pipeline.py rename to test/pipeline/integration/test_complex_pipeline.py diff --git a/test/pipelines/integration/test_double_loop_pipeline.py b/test/pipeline/integration/test_double_loop_pipeline.py similarity index 100% rename from test/pipelines/integration/test_double_loop_pipeline.py rename to test/pipeline/integration/test_double_loop_pipeline.py diff --git a/test/pipelines/integration/test_fixed_decision_and_merge_pipeline.py b/test/pipeline/integration/test_fixed_decision_and_merge_pipeline.py similarity index 100% rename from test/pipelines/integration/test_fixed_decision_and_merge_pipeline.py rename to test/pipeline/integration/test_fixed_decision_and_merge_pipeline.py diff --git a/test/pipelines/integration/test_fixed_decision_pipeline.py b/test/pipeline/integration/test_fixed_decision_pipeline.py similarity index 100% rename from test/pipelines/integration/test_fixed_decision_pipeline.py rename to test/pipeline/integration/test_fixed_decision_pipeline.py diff --git a/test/pipelines/integration/test_fixed_merging_pipeline.py b/test/pipeline/integration/test_fixed_merging_pipeline.py similarity index 100% rename from test/pipelines/integration/test_fixed_merging_pipeline.py rename to test/pipeline/integration/test_fixed_merging_pipeline.py diff --git a/test/pipelines/integration/test_linear_pipeline.py b/test/pipeline/integration/test_linear_pipeline.py similarity index 100% rename from test/pipelines/integration/test_linear_pipeline.py rename to test/pipeline/integration/test_linear_pipeline.py diff --git a/test/pipelines/integration/test_looping_and_merge_pipeline.py b/test/pipeline/integration/test_looping_and_merge_pipeline.py similarity index 100% rename from test/pipelines/integration/test_looping_and_merge_pipeline.py rename to test/pipeline/integration/test_looping_and_merge_pipeline.py diff --git a/test/pipelines/integration/test_looping_pipeline.py b/test/pipeline/integration/test_looping_pipeline.py similarity index 100% rename from test/pipelines/integration/test_looping_pipeline.py rename to test/pipeline/integration/test_looping_pipeline.py diff --git a/test/pipelines/integration/test_parallel_branches_pipeline.py b/test/pipeline/integration/test_parallel_branches_pipeline.py similarity index 100% rename from test/pipelines/integration/test_parallel_branches_pipeline.py rename to test/pipeline/integration/test_parallel_branches_pipeline.py diff --git a/test/pipelines/integration/test_variable_decision_and_merge_pipeline.py b/test/pipeline/integration/test_variable_decision_and_merge_pipeline.py similarity index 100% rename from test/pipelines/integration/test_variable_decision_and_merge_pipeline.py rename to test/pipeline/integration/test_variable_decision_and_merge_pipeline.py diff --git a/test/pipelines/integration/test_variable_decision_pipeline.py b/test/pipeline/integration/test_variable_decision_pipeline.py similarity index 100% rename from test/pipelines/integration/test_variable_decision_pipeline.py rename to test/pipeline/integration/test_variable_decision_pipeline.py diff --git a/test/pipelines/integration/test_variable_merging_pipeline.py b/test/pipeline/integration/test_variable_merging_pipeline.py similarity index 100% rename from test/pipelines/integration/test_variable_merging_pipeline.py rename to test/pipeline/integration/test_variable_merging_pipeline.py diff --git a/test/pipelines/unit/__init__.py b/test/pipeline/unit/__init__.py similarity index 100% rename from test/pipelines/unit/__init__.py rename to test/pipeline/unit/__init__.py diff --git a/test/pipelines/unit/test_connections.py b/test/pipeline/unit/test_connections.py similarity index 98% rename from test/pipelines/unit/test_connections.py rename to test/pipeline/unit/test_connections.py index 43a207268e..07b7ffe1bc 100644 --- a/test/pipelines/unit/test_connections.py +++ b/test/pipeline/unit/test_connections.py @@ -8,9 +8,10 @@ import pytest -from canals import Pipeline, component +from canals import Pipeline from canals.errors import PipelineConnectError from canals.testing import factory +from canals.pipeline.connections import parse_connection from sample_components import AddFixedValue @@ -407,3 +408,9 @@ def test_connect_many_connections_possible_no_name_matches(): pipe.add_component("c2", Component2()) with pytest.raises(PipelineConnectError, match=expected_message): pipe.connect("c1", "c2") + + +def test_parse_connection(): + assert parse_connection("foobar") == ("foobar", None) + assert parse_connection("foo.bar") == ("foo", "bar") + assert parse_connection("foo.bar.baz") == ("foo", "bar.baz") diff --git a/test/pipelines/unit/test_draw.py b/test/pipeline/unit/test_draw.py similarity index 100% rename from test/pipelines/unit/test_draw.py rename to test/pipeline/unit/test_draw.py diff --git a/test/pipelines/unit/test_pipeline.py b/test/pipeline/unit/test_pipeline.py similarity index 100% rename from test/pipelines/unit/test_pipeline.py rename to test/pipeline/unit/test_pipeline.py diff --git a/test/pipelines/unit/test_validation_pipeline_io.py b/test/pipeline/unit/test_validation_pipeline_io.py similarity index 100% rename from test/pipelines/unit/test_validation_pipeline_io.py rename to test/pipeline/unit/test_validation_pipeline_io.py