Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

☔ Add unit tests to ipynb conversion #117

Merged
merged 6 commits into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions opencodeblocks/graphics/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ def createNewMdiChild(self, filename: str = None):
ocb_widget = OCBWidget()
if filename is not None:
ocb_widget.scene.load(filename)
ocb_widget.savepath = filename
if filename.split(".")[-1] == "ipyg":
ocb_widget.savepath = filename
return self.mdiArea.addSubWindow(ocb_widget)

def onFileNew(self):
Expand Down Expand Up @@ -374,7 +375,6 @@ def oneFileSaveAsJupyter(self) -> bool:
)
if filename == "":
return False
current_window.savepath = filename
current_window.saveAsJupyter()
self.statusbar.showMessage(
f"Successfully saved ipygraph as jupter notebook at {current_window.savepath}",
Expand Down
12 changes: 9 additions & 3 deletions opencodeblocks/scene/from_ipynb_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def get_blocks_data(data: OrderedDict) -> List[OrderedDict]:

next_block_x_pos: float = 0
next_block_y_pos: float = 0
next_block_id = 0

for cell in data["cells"]:
if "cell_type" not in cell or cell["cell_type"] not in ["code", "markdown"]:
Expand All @@ -62,7 +63,7 @@ def get_blocks_data(data: OrderedDict) -> List[OrderedDict]:
block_height: float = text_height + MARGIN_Y

block_data = {
"id": len(blocks_data),
"id": next_block_id,
"block_type": BLOCK_TYPE_TO_NAME[block_type],
"width": block_width,
"height": block_height,
Expand Down Expand Up @@ -93,6 +94,7 @@ def get_blocks_data(data: OrderedDict) -> List[OrderedDict]:
next_block_y_pos += block_height + MARGIN_BETWEEN_BLOCKS_Y

blocks_data.append(block_data)
next_block_id += 1

adujst_markdown_blocks_width(blocks_data)

Expand Down Expand Up @@ -144,9 +146,13 @@ def get_edges_data(blocks_data: OrderedDict) -> OrderedDict:
]
edges_data: List[OrderedDict] = []

greatest_block_id: int = 0
if len(blocks_data) > 0:
greatest_block_id = blocks_data[-1]["id"]

for i in range(1, len(code_blocks)):
socket_id_out = len(blocks_data) + 2 * i
socket_id_in = len(blocks_data) + 2 * i + 1
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"])
)
Expand Down
Loading