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 support for sorting test workflows #1964

Merged
merged 2 commits into from
Aug 30, 2024
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
7 changes: 7 additions & 0 deletions Bonsai.Core.Tests/TestWorkflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ public TestWorkflow AppendSubject<TSubjectBuilder>(string name)
return Append(subjectBuilder);
}

public TestWorkflow TopologicalSort()
{
var workflow = new ExpressionBuilderGraph();
workflow.InsertRange(0, Workflow.TopologicalSort());
return new TestWorkflow(workflow, Cursor);
}

public ExpressionBuilderGraph ToInspectableGraph()
{
return Workflow.ToInspectableGraph();
Expand Down
9 changes: 2 additions & 7 deletions Bonsai.Editor.Tests/WorkflowEditorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ static string ToString(IEnumerable<T> sequence)
ExpressionBuilderGraph workflow = null,
MockGraphView graphView = null)
{
if (workflow != null)
{
// Workflows must be topologically sorted to ensure all editor operations are reversible
workflow.InsertRange(0, workflow.TopologicalSort());
}

graphView ??= new MockGraphView(workflow);
var editor = new WorkflowEditor(graphView.ServiceProvider, graphView);
editor.UpdateLayout.Subscribe(graphView.UpdateGraphLayout);
Expand Down Expand Up @@ -236,7 +230,7 @@ public void ReplaceGraphNode_SingleInputWithVisualizerMapping_GroupWorkflowHasSi
.AppendBranch(source => source
.AppendSubject<Reactive.PublishSubject>("P")
.AddArguments(source.Append(new VisualizerMappingBuilder())))
.Workflow
.TopologicalSort()
.ToInspectableGraph();

var (editor, assertIsReversible) = CreateMockEditor(workflow);
Expand All @@ -252,6 +246,7 @@ public void ReplaceGraphNode_SingleInputWithVisualizerMapping_GroupWorkflowHasSi
var groupBuilder = ExpressionBuilder.Unwrap(groupNode?.Value) as GroupWorkflowBuilder;
Assert.IsInstanceOfType(groupBuilder, typeof(GroupWorkflowBuilder));
Assert.AreEqual(expected: 2, groupBuilder.Workflow.Count);
Assert.IsInstanceOfType(ExpressionBuilder.Unwrap(groupBuilder.Workflow[0].Value), typeof(WorkflowInputBuilder));
Assert.IsInstanceOfType(ExpressionBuilder.Unwrap(groupBuilder.Workflow[1].Value), typeof(WorkflowOutputBuilder));
assertIsReversible();
}
Expand Down