Skip to content

Commit e1ae725

Browse files
committed
Fix documentation, Change version and Changelog
1 parent 7826035 commit e1ae725

6 files changed

Lines changed: 57 additions & 27 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Changelogs
22

33
## Version 1.2.2
4-
(Released : April 30, 2021) : tag 1.2.2
4+
(Released : May 06, 2021) : tag 1.2.2
55
* Improve forking mechanism to match with sub_graph
66
* Improve fork/sub_graph documentation
77
* Forward kwargs on standard visitor to be able to use BaseVisitor constructor

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ This feature may be used as a fork mechanism (as seen above). It is easier to ma
228228

229229
Usage Example:
230230

231-
```python
232231
```python
233232
# id0
234233
# |

freexgraph/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
# SOFTWARE.
2323

24-
__version__ = "1.2.1"
24+
__version__ = "1.2.2"

freexgraph/freexgraph.py

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,6 @@ def accept(self, visitor: AnyVisitor) -> bool:
154154
"""Utility to simplify code"""
155155

156156

157-
def _remove_duplicated_node(nodes: List[FreExNode]) -> List[FreExNode]:
158-
"""return a copy of provided the list without duplicates, a duplicate is defined by its id"""
159-
filtered_list = []
160-
for n in nodes:
161-
found = False
162-
for in_list in filtered_list:
163-
if n.id == in_list.id:
164-
found = True
165-
if not found:
166-
filtered_list.append(n)
167-
return filtered_list
168-
169-
170157
class FreExGraph:
171158
"""Execution Graph main class"""
172159

@@ -182,8 +169,6 @@ def __init__(self):
182169
@staticmethod
183170
def _make_node_id_with_fork(node_id: str, fork_id: str) -> str:
184171
"""make a unique id for the new fork"""
185-
if node_id == root_node:
186-
return node_id
187172
return f"{node_id}::{fork_id}"
188173

189174
def add_nodes(self, nodes: List[AnyFreExNode]) -> None:
@@ -339,21 +324,25 @@ def fork_from_node(
339324
id will be appended with the fork_id set on the forked_node. For this reason it is required to have a fork_id
340325
set on the forked_node.
341326
342-
> It is the user responsibility to ensure that those id doesn't collide.
343-
344327
If the provided join_node doesn't exist, an exception is thrown.
345328
If a join node is provided, all node from the provided one until the join node is encountered are duplicated. if
346329
the join node is not encountered, duplicate node until leaf
347330
331+
warning:
332+
It is the user responsibility to ensure that those id doesn't collide.
333+
348334
side_note:
349335
':' is used as a separator for the id and the fork_id to ensure a unique name. This is the reason why '::'
350336
is reserved and cannot be used.
351337
338+
raise Assertion failure:
339+
* if the node defined by forked_node.id doesn't exist in the graph.
340+
* if the forked_node doesn't contains a fork_id.
341+
* if a join_node is provided but does not exist.
342+
352343
:param forked_node: node to replace the fork one, its fork_id field has to be set
353-
:param join_id: node to stop duplication (used for map_reduce)
354-
:exception: Assertion failure in case that the node defined by forked_node.id doesn't exist in the graph or is a
355-
GraphNode, or if the forked_node doesn't contains a fork_id. Assertion failure if a join_node is provided but
356-
does not exist or that the join_node is not linking all last node to be forked.
344+
:param join_id: node to stop duplication (used for map_reduce) if encountered
345+
357346
"""
358347
assert self._graph.has_node(
359348
forked_node.id
@@ -365,10 +354,9 @@ def fork_from_node(
365354
join_id
366355
), f"Error fork of node {forked_node.id} with join_id {join_id}: join_id node doesn't exist in graph "
367356

368-
join_node_list = [join_id] if join_id else []
369357
sub_graph, removed_parents = self.sub_graph(
370358
from_node_id=forked_node.id,
371-
to_nodes_id=join_node_list,
359+
to_nodes_id=[join_id] if join_id else [],
372360
return_removed_parents=True,
373361
)
374362
sub_graph._graph.remove_node(root_node)

recipe.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
python38.pkgs.buildPythonPackage rec {
55
pname = "freexgraph";
6-
version = "1.2.1";
6+
version = "1.2.2";
77

88
src = if (builtins.isNull use_revision || use_revision == "") then
99
nix-gitignore.gitignoreSource [ ".git" ] ./.

test/fork_test.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,46 @@ def test_fork_with_join_unlinked_with_join_2(node_test_class, visitor_test):
191191

192192
visitor_test.visit(execution_graph.root)
193193
assert len(visitor_test.visited) == 18
194+
195+
196+
def test_fork_without_fork_id(node_test_class, visitor_test):
197+
execution_graph = make_fork_graph(node_test_class)
198+
visitor_test.visit(execution_graph.root)
199+
200+
with pytest.raises(AssertionError) as e:
201+
execution_graph.fork_from_node(
202+
node_test_class(id1, fork_id=None), join_id=id_join
203+
)
204+
assert f"Error fork of node {id1}: doesn't have fork_id" == e
205+
206+
207+
def test_fork_with_inexistant_join_id(node_test_class, visitor_test):
208+
execution_graph = make_fork_graph(node_test_class)
209+
visitor_test.visit(execution_graph.root)
210+
211+
join_not_exist = "ThisDoesntExistAtAll"
212+
213+
with pytest.raises(AssertionError) as e:
214+
execution_graph.fork_from_node(
215+
node_test_class(id1, fork_id="chocobo"), join_id=join_not_exist
216+
)
217+
assert (
218+
f"Error fork of node {id1} with join_id {join_not_exist}: join_id node doesn't exist in graph "
219+
== e
220+
)
221+
222+
223+
def test_fork_with_inexistant_node(node_test_class, visitor_test):
224+
execution_graph = make_fork_graph(node_test_class)
225+
visitor_test.visit(execution_graph.root)
226+
227+
id_not_exist = "ThisDoesntExistAtAll"
228+
229+
with pytest.raises(AssertionError) as e:
230+
execution_graph.fork_from_node(
231+
node_test_class(id_not_exist, fork_id="chocobo"), join_id=id_join
232+
)
233+
assert (
234+
f"Error fork of node {id_not_exist}, node to fork has to be in the execution graph"
235+
== e
236+
)

0 commit comments

Comments
 (0)