From 993430da97ead2e84c7582d2856a4aca56c79379 Mon Sep 17 00:00:00 2001 From: Fabien Roger Date: Sat, 8 Jan 2022 17:56:09 +0100 Subject: [PATCH 1/2] :beetle: Fix socket missing bug --- pyflow/scene/from_ipynb_conversion.py | 35 +++++++++++++++------------ 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/pyflow/scene/from_ipynb_conversion.py b/pyflow/scene/from_ipynb_conversion.py index a6d17781..34f986c8 100644 --- a/pyflow/scene/from_ipynb_conversion.py +++ b/pyflow/scene/from_ipynb_conversion.py @@ -169,22 +169,27 @@ def get_edges_data(blocks_data: OrderedDict) -> OrderedDict: if len(blocks_data) > 0: greatest_block_id = blocks_data[-1]["id"] - for i in range(1, len(code_blocks)): - socket_id_out = greatest_block_id + 2 * i + 2 - socket_id_in = greatest_block_id + 2 * i + 1 - code_blocks[i - 1]["sockets"].append( - get_output_socket_data(socket_id_out, code_blocks[i - 1]["width"]) - ) - code_blocks[i]["sockets"].append(get_input_socket_data(socket_id_in)) - edges_data.append( - get_edge_data( - i, - code_blocks[i - 1]["id"], - socket_id_out, - code_blocks[i]["id"], - socket_id_in, + last_socket_id_out: int = -1 + for i, block in enumerate(code_blocks): + socket_id_out: int = greatest_block_id + 2 * i + 2 + socket_id_in: int = greatest_block_id + 2 * i + 1 + + block["sockets"].append(get_output_socket_data(socket_id_out, block["width"])) + block["sockets"].append(get_input_socket_data(socket_id_in)) + + if i >= 1: + edges_data.append( + get_edge_data( + i, + code_blocks[i - 1]["id"], + last_socket_id_out, + code_blocks[i]["id"], + socket_id_in, + ) ) - ) + + last_socket_id_out = socket_id_out + return edges_data From f85de679416f71f002201630c9226ac497a53947 Mon Sep 17 00:00:00 2001 From: Fabien Roger Date: Sun, 9 Jan 2022 22:35:52 +0100 Subject: [PATCH 2/2] :umbrella: Add unit tests for sockets from ipynb --- tests/unit/scene/test_ipynb_conversion.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/unit/scene/test_ipynb_conversion.py b/tests/unit/scene/test_ipynb_conversion.py index 0b3fa71c..fd6c2df5 100644 --- a/tests/unit/scene/test_ipynb_conversion.py +++ b/tests/unit/scene/test_ipynb_conversion.py @@ -3,7 +3,7 @@ """Unit tests for the conversion from and to ipynb.""" -from typing import OrderedDict +from typing import List, OrderedDict from pytest_mock import MockerFixture import pytest_check as check import json @@ -71,7 +71,7 @@ def check_conversion_coherence(ipynb_data: OrderedDict, ipyg_data: OrderedDict): 2. the right amount of code blocks and edges 3. blocks and sockets with unique ids 4. edges with existing ids - 5. code blocks that always have a source + 5. code blocks that always have a source and two sockets 6. markdown blocks that always have text """ @@ -109,10 +109,17 @@ def check_conversion_coherence(ipynb_data: OrderedDict, ipyg_data: OrderedDict): check.equal(edge["source"]["socket"] in socket_id_set, True) check.equal(edge["destination"]["socket"] in socket_id_set, True) - # code blocks always have a source and markdown blocks always have a text + # code blocks always have a source and two sockets + # markdown blocks always have a text for block in ipyg_data["blocks"]: if block["block_type"] == BLOCK_TYPE_TO_NAME["code"]: - check.equal("source" in block and type(block["source"]) == str, True) + check.equal("source" in block, True) + check.equal(type(block["source"]), str) + + check.equal("sockets" in block, True) + check.equal(type(block["sockets"]), list) + check.equal(len(block["sockets"]), 2) + if block["block_type"] == BLOCK_TYPE_TO_NAME["markdown"]: check.equal("text" in block and type(block["text"]) == str, True)