Skip to content

Commit

Permalink
support empty groups (#115)
Browse files Browse the repository at this point in the history
* support empty groups

* bump version test

* add url
  • Loading branch information
PythonFZ authored Oct 18, 2024
1 parent 48636f4 commit c4e841c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
[tool.poetry]
name = "znflow"
version = "0.2.1"
version = "0.2.2"
description = "A general purpose framework for building and running computational graphs."
authors = ["zincwarecode <[email protected]>"]
license = "Apache-2.0"
readme = "README.md"

[tool.poetry.urls]
repository = "https://github.com/zincware/znflow"

[tool.poetry.dependencies]
python = ">=3.9,<4.0"
networkx = "^3"
Expand Down
21 changes: 21 additions & 0 deletions tests/test_graph_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,24 @@ def test_grp_nodes():
assert grp.nodes == [n1, n2]
assert grp.uuids == [n1.uuid, n2.uuid]
assert grp.names == ("grp1",)


def test_empty_grps():
graph = znflow.DiGraph()

with graph.group("grp1") as grp1:
pass
with graph.group("grp2") as grp2:
pass

assert len(grp1) == 0
assert len(grp2) == 0
assert grp1.uuids == []
assert grp2.uuids == []

assert grp1.names == ("grp1",)
assert grp2.names == ("grp2",)

assert len(graph.groups) == 2
assert grp1.names in graph.groups
assert grp2.names in graph.groups
2 changes: 1 addition & 1 deletion tests/test_znflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

def test_version():
"""Test the version."""
assert znflow.__version__ == "0.2.1"
assert znflow.__version__ == "0.2.2"
2 changes: 1 addition & 1 deletion znflow/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ def group(self, *names: str) -> typing.Generator[Group, None, None]:
group = self.groups.get(names, Group(names=names, uuids=[], graph=self))

def finalize_group():
self.groups[group.names] = group
for node_uuid in self.nodes:
if node_uuid not in existing_nodes:
self.groups[group.names] = group
group.uuids.append(node_uuid)

try:
Expand Down

0 comments on commit c4e841c

Please sign in to comment.