Skip to content

Commit

Permalink
Fix bijective transformation of seq name into ID
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinAV committed Feb 13, 2024
1 parent 33a2717 commit 8a20a13
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions taipy/core/sequence/_sequence_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def _breakdown_sequence_id(cls, sequence_id: str) -> Tuple[str, str]:
sequence_name, scenario_id = sequence_id.split(Scenario._ID_PREFIX)
scenario_id = f"{Scenario._ID_PREFIX}{scenario_id}"
sequence_name = sequence_name.split(Sequence._ID_PREFIX)[1].strip("_")
sequence_name = sequence_name.replace("TPSPACE", " ")
return sequence_name, scenario_id
except (ValueError, IndexError):
cls._logger.error(f"SequenceId {sequence_id} is invalid.")
Expand Down
2 changes: 1 addition & 1 deletion taipy/core/sequence/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(

@staticmethod
def _new_id(sequence_name: str, scenario_id) -> SequenceId:
seq_id = sequence_name.replace(" ", "_")
seq_id = sequence_name.replace(" ", "TPSPACE")
return SequenceId(Sequence._SEPARATOR.join([Sequence._ID_PREFIX, _validate_id(seq_id), scenario_id]))

def __hash__(self):
Expand Down
10 changes: 5 additions & 5 deletions tests/core/scenario/test_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def test_add_rename_and_remove_sequences():
sequence_1 = Sequence({"name": "seq_1"}, [task_1], SequenceId(f"SEQUENCE_seq_1_{scenario.id}"))
sequence_2 = Sequence({"name": "seq_2"}, [task_1, task_2], SequenceId(f"SEQUENCE_seq_2_{scenario.id}"))
new_seq_2 = Sequence({"name": "seq_2"}, [task_1, task_2], SequenceId(f"SEQUENCE_new_seq_2_{scenario.id}"))
sequence_3 = Sequence({"name": "seq_3"}, [task_1, task_5, task_3], SequenceId(f"SEQUENCE_seq_3_{scenario.id}"))
seq_3 = Sequence({"name": "seq 3"}, [task_1, task_5, task_3], SequenceId(f"SEQUENCE_seqTPSPACE3_{scenario.id}"))

task_manager = _TaskManagerFactory._build_manager()
data_manager = _DataManagerFactory._build_manager()
Expand All @@ -412,7 +412,7 @@ def test_add_rename_and_remove_sequences():
assert scenario.sequences == {"seq_2": sequence_2}

scenario.add_sequences({"seq_1": [task_1], "seq 3": [task_1, task_5, task_3]})
assert scenario.sequences == {"seq_2": sequence_2, "seq_1": sequence_1, "seq 3": sequence_3}
assert scenario.sequences == {"seq_2": sequence_2, "seq_1": sequence_1, "seq 3": seq_3}

scenario.remove_sequences(["seq_2", "seq 3"])
assert scenario.sequences == {"seq_1": sequence_1}
Expand All @@ -421,13 +421,13 @@ def test_add_rename_and_remove_sequences():
assert scenario.sequences == {"seq_1": sequence_1, "seq_2": sequence_2}

scenario.add_sequence("seq 3", [task_1.id, task_5.id, task_3.id])
assert scenario.sequences == {"seq_1": sequence_1, "seq_2": sequence_2, "seq 3": sequence_3}
assert scenario.sequences == {"seq_1": sequence_1, "seq_2": sequence_2, "seq 3": seq_3}

scenario.remove_sequence("seq_1")
assert scenario.sequences == {"seq_2": sequence_2, "seq 3": sequence_3}
assert scenario.sequences == {"seq_2": sequence_2, "seq 3": seq_3}

scenario.rename_sequence("seq_2", "new_seq_2")
assert scenario.sequences == {"new_seq_2": new_seq_2, "seq 3": sequence_3}
assert scenario.sequences == {"new_seq_2": new_seq_2, "seq 3": seq_3}


def test_update_sequence(data_node):
Expand Down

0 comments on commit 8a20a13

Please sign in to comment.