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

Ensure retrieval of closest subject definition #1699

Merged
merged 3 commits into from
Feb 29, 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
3 changes: 1 addition & 2 deletions Bonsai.Configuration/NativeMethods.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;

namespace Bonsai.Configuration
{
Expand Down
1 change: 0 additions & 1 deletion Bonsai.Configuration/ScriptExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NuGet.Configuration;
using NuGet.Packaging;
using NuGet.Versioning;
using System;
using System.Collections.Generic;
Expand Down
8 changes: 8 additions & 0 deletions Bonsai.Editor.Tests/EditorHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ internal static ExpressionBuilderGraph CreateEditorGraph(params string[] values)
return graph.ToInspectableGraph();
}

internal static TBuilder FindExpressionBuilder<TBuilder>(this ExpressionBuilderGraph workflow) where TBuilder : class
{
return (from node in workflow
let builder = node.Value as TBuilder
where builder != null
select builder).FirstOrDefault();
}

internal static GraphNode FindNode(this WorkflowEditor editor, string name)
{
var node = editor.Workflow.First(n => ExpressionBuilder.GetElementDisplayName(n.Value) == name);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<WorkflowBuilder Version="2.8.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
xmlns="https://bonsai-rx.org/2018/workflow">
<Workflow>
<Nodes>
<Expression xsi:type="Combinator">
<Combinator xsi:type="IntProperty">
<Value>8</Value>
</Combinator>
</Expression>
<Expression xsi:type="rx:PublishSubject">
<Name>Values</Name>
</Expression>
<Expression xsi:type="SubscribeSubject">
<Name>Values</Name>
</Expression>
<Expression xsi:type="rx:Defer">
<Workflow>
<Nodes>
<Expression xsi:type="WorkflowInput">
<Name>Source1</Name>
</Expression>
<Expression xsi:type="Multiply">
<Operand xsi:type="IntProperty">
<Value>2</Value>
</Operand>
</Expression>
<Expression xsi:type="rx:PublishSubject">
<Name>Values</Name>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Timer">
<rx:DueTime>PT0S</rx:DueTime>
<rx:Period>PT0S</rx:Period>
</Combinator>
</Expression>
<Expression xsi:type="rx:SelectMany">
<Workflow>
<Nodes>
<Expression xsi:type="WorkflowInput">
<Name>Source1</Name>
</Expression>
<Expression xsi:type="SubscribeSubject">
<Name>Values</Name>
</Expression>
<Expression xsi:type="WorkflowOutput" />
</Nodes>
<Edges>
<Edge From="1" To="2" Label="Source1" />
</Edges>
</Workflow>
</Expression>
<Expression xsi:type="WorkflowOutput" />
</Nodes>
<Edges>
<Edge From="0" To="1" Label="Source1" />
<Edge From="1" To="2" Label="Source1" />
<Edge From="3" To="4" Label="Source1" />
<Edge From="4" To="5" Label="Source1" />
</Edges>
</Workflow>
</Expression>
</Nodes>
<Edges>
<Edge From="0" To="1" Label="Source1" />
<Edge From="2" To="3" Label="Source1" />
</Edges>
</Workflow>
</WorkflowBuilder>
22 changes: 22 additions & 0 deletions Bonsai.Editor.Tests/WorkflowEditorDefinitionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Bonsai.Editor.GraphModel;
using Bonsai.Reactive;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Bonsai.Editor.Tests
{
public partial class WorkflowEditorTests
{
[TestMethod]
public void GetSubjectDefinition_NestedSubscribeSubject_ReturnsClosestDefinition()
{
var workflowBuilder = LoadEmbeddedWorkflow("NestedSubscribeSubjectWithClosestRedefinition.bonsai");
var deferBuilder = workflowBuilder.Workflow.FindExpressionBuilder<Defer>();
Assert.IsNotNull(deferBuilder);
var selectManyBuilder = deferBuilder.Workflow.FindExpressionBuilder<SelectMany>();
Assert.IsNotNull(selectManyBuilder);
var definition = workflowBuilder.GetSubjectDefinition(selectManyBuilder.Workflow, "Values");
Assert.IsNotNull(definition);
Assert.AreSame(deferBuilder.Workflow, definition.Root.Key);
}
}
}
4 changes: 1 addition & 3 deletions Bonsai.Editor.Tests/WorkflowEditorTests.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.IO;
using System.Linq;
using System.Xml;
using Bonsai.Dag;
using Bonsai.Design;
using Bonsai.Editor.GraphModel;
using Bonsai.Expressions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Bonsai.Editor.Tests
{
[TestClass]
public class WorkflowEditorTests
public partial class WorkflowEditorTests
{
static Stream LoadEmbeddedResource(string name)
{
Expand Down
1 change: 0 additions & 1 deletion Bonsai.Editor/ExportHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Bonsai.Editor.GraphModel;
using Bonsai.Editor.GraphView;
Expand Down
2 changes: 1 addition & 1 deletion Bonsai.Editor/GraphModel/WorkflowBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ from element in level
let subjectBuilder = element.Builder as SubjectExpressionBuilder
where subjectBuilder != null && subjectBuilder.Name == name
select new SubjectDefinition(level, subjectBuilder, element.IsReadOnly))
.LastOrDefault();
.FirstOrDefault();
}

return null;
Expand Down
1 change: 0 additions & 1 deletion Bonsai/ScriptExtensionsEnvironment.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Bonsai.Configuration;
using Bonsai.Editor;
using System;
using System.Collections.Generic;
using System.Reflection;

Expand Down
Loading