Skip to content

Commit 5bbafbe

Browse files
committed
test relocated
1 parent 52b17ee commit 5bbafbe

File tree

2 files changed

+84
-62
lines changed

2 files changed

+84
-62
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using CoreNodeModels;
2+
using Dynamo.Tests;
3+
using Dynamo.Utilities;
4+
using Newtonsoft.Json.Linq;
5+
using NUnit.Framework;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.IO;
9+
using System.Linq;
10+
11+
namespace DynamoCoreWpfTests
12+
{
13+
[TestFixture]
14+
public class PythonMigrationViewExtensionTests : DynamoTestUIBase
15+
{
16+
protected override void GetLibrariesToPreload(List<string> libraries)
17+
{
18+
libraries.Add("VMDataBridge.dll");
19+
libraries.Add("DSCoreNodes.dll");
20+
base.GetLibrariesToPreload(libraries);
21+
}
22+
23+
/// <summary>
24+
/// Confirms that nested custom nodes containing CPython3 Python nodes
25+
/// are migrated to PythonNet3 and produce expected results.
26+
/// </summary>
27+
[Test]
28+
public void NestedCPythonCustomNodesAreAutoMigratedToPythonNet3()
29+
{
30+
Assert.IsTrue(
31+
View.viewExtensionManager.ViewExtensions.Any(e => e != null && e.Name == "Python Migration"),
32+
"Python Migration view extension is not loaded.");
33+
34+
// Load custom node definitions into the manager first
35+
var pythonDir = Path.Combine(GetTestDirectory(ExecutingDirectory), "core", "python");
36+
var childPath = Path.Combine(pythonDir, "CNWithCPython_Child.dyf");
37+
var parentPath = Path.Combine(pythonDir, "CNWithCPython_Parent.dyf");
38+
var graphPath = Path.Combine(pythonDir, "WithNestedCPythonCustomNodes.dyn");
39+
var expectedValue = "20";
40+
41+
Assert.IsTrue(File.Exists(childPath), "Missing test file: " + childPath);
42+
Assert.IsTrue(File.Exists(parentPath), "Missing test file: " + parentPath);
43+
Assert.IsTrue(File.Exists(graphPath), "Missing test file: " + graphPath);
44+
45+
// Assert that both custom nodes are containing CPython3 python nodes before they are loaded
46+
AssertDyfContainsPythonNodesWithEngine(childPath, "CPython3");
47+
AssertDyfContainsPythonNodesWithEngine(parentPath, "CPython3");
48+
49+
Assert.IsTrue(ViewModel.Model.CustomNodeManager.AddUninitializedCustomNode(childPath, true, out _));
50+
Assert.IsTrue(ViewModel.Model.CustomNodeManager.AddUninitializedCustomNode(parentPath, true, out _));
51+
52+
// Open graph and run
53+
Open(graphPath);
54+
Run();
55+
56+
// Assert watch value is expected
57+
var watch = Model.CurrentWorkspace.NodeFromWorkspace<Watch>("8a7664fa-6764-42a1-b3ed-d9e7535819df");
58+
Assert.IsNotNull(watch);
59+
Assert.AreEqual(expectedValue, watch.CachedValue?.ToString());
60+
}
61+
62+
/// <summary>
63+
/// Helper method to assert that a .dyf file contains at least one Python node of a given engine type.
64+
/// </summary>
65+
private static void AssertDyfContainsPythonNodesWithEngine(string dyfPath, string expectedEngine)
66+
{
67+
Assert.IsTrue(File.Exists(dyfPath), "Missing .dyf file: " + dyfPath);
68+
69+
var root = JObject.Parse(File.ReadAllText(dyfPath));
70+
var nodes = root["Nodes"] as JArray;
71+
Assert.IsNotNull(nodes, "Invalid .dyf JSON: missing 'Nodes' array in " + dyfPath);
72+
73+
bool match = nodes
74+
.OfType<JObject>()
75+
.Where(n => (n.Value<string>("ConcreteType") ?? string.Empty)
76+
.StartsWith("PythonNodeModels", StringComparison.Ordinal))
77+
.Select(n => n.Value<string>("Engine") ?? n.Value<string>("EngineName"))
78+
.Any(engine => string.Equals(engine, expectedEngine, StringComparison.Ordinal));
79+
80+
Assert.IsTrue(match, $"Expected at least one Python node with engine '{expectedEngine}' in '{Path.GetFileName(dyfPath)}'.");
81+
}
82+
}
83+
}
84+

test/DynamoCoreWpf3Tests/PythonNodeCustomizationTests.cs

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -955,67 +955,5 @@ public void OnlyUniqueEnginesAddedToUI2()
955955
var menu = nodeView.MainContextMenu.Items.Cast<MenuItem>().First(x => (x.Header as string) == PythonNodeModels.Properties.Resources.PythonNodeContextMenuEngineSwitcher);
956956
Assert.AreEqual(2, menu.Items.Count);
957957
}
958-
959-
/// <summary>
960-
/// Confirms that nested custom nodes containing CPython3 Python nodes
961-
/// are migrated to PythonNet3 and produce expected results.
962-
/// </summary>
963-
[Test]
964-
public void NestedCPythonCustomNodesAreAutoMigratedToPythonNet3()
965-
{
966-
Assert.IsTrue(
967-
View.viewExtensionManager.ViewExtensions.Any(e => e != null && e.Name == "Python Migration"),
968-
"Python Migration view extension is not loaded.");
969-
970-
// Load custom node definitions into the manager first
971-
var pythonDir = Path.Combine(GetTestDirectory(ExecutingDirectory), "core", "python");
972-
var childPath = Path.Combine(pythonDir, "CNWithCPython_Child.dyf");
973-
var parentPath = Path.Combine(pythonDir, "CNWithCPython_Parent.dyf");
974-
var graphPath = Path.Combine(pythonDir, "WithNestedCPythonCustomNodes.dyn");
975-
var expectedValue = "20";
976-
977-
Assert.IsTrue(File.Exists(childPath), "Missing test file: " + childPath);
978-
Assert.IsTrue(File.Exists(parentPath), "Missing test file: " + parentPath);
979-
Assert.IsTrue(File.Exists(graphPath), "Missing test file: " + graphPath);
980-
981-
// Assert that both custom nodes are containing CPython3 python nodes before they are loaded
982-
AssertDyfContainsPythonNodesWithEngine(childPath, "CPython3");
983-
AssertDyfContainsPythonNodesWithEngine(parentPath, "CPython3");
984-
985-
Assert.IsTrue(ViewModel.Model.CustomNodeManager.AddUninitializedCustomNode(childPath, true, out _));
986-
Assert.IsTrue(ViewModel.Model.CustomNodeManager.AddUninitializedCustomNode(parentPath, true, out _));
987-
988-
// Open graph and run
989-
Open(graphPath);
990-
Run();
991-
992-
// Assert watch value is expected
993-
var watch = Model.CurrentWorkspace.NodeFromWorkspace<Watch>("8a7664fa-6764-42a1-b3ed-d9e7535819df");
994-
Assert.IsNotNull(watch);
995-
Assert.AreEqual(expectedValue, watch.CachedValue?.ToString());
996-
}
997-
998-
/// <summary>
999-
/// Helper method to assert that a .dyf file contains at least one Python node of a given engine type.
1000-
/// </summary>
1001-
/// <param name="dyfPath"></param>
1002-
/// <param name="expectedEngine"></param>
1003-
private static void AssertDyfContainsPythonNodesWithEngine(string dyfPath, string expectedEngine)
1004-
{
1005-
Assert.IsTrue(File.Exists(dyfPath), "Missing .dyf file: " + dyfPath);
1006-
1007-
var root = JObject.Parse(File.ReadAllText(dyfPath));
1008-
var nodes = root["Nodes"] as JArray;
1009-
Assert.IsNotNull(nodes, "Invalid .dyf JSON: missing 'Nodes' array in " + dyfPath);
1010-
1011-
bool match = nodes
1012-
.OfType<JObject>()
1013-
.Where(n => (n.Value<string>("ConcreteType") ?? string.Empty)
1014-
.StartsWith("PythonNodeModels", StringComparison.Ordinal))
1015-
.Select(n => n.Value<string>("Engine") ?? n.Value<string>("EngineName"))
1016-
.Any(engine => string.Equals(engine, expectedEngine, StringComparison.Ordinal));
1017-
1018-
Assert.IsTrue(match, $"Expected at least one Python node with engine '{expectedEngine}' in '{Path.GetFileName(dyfPath)}'.");
1019-
}
1020958
}
1021959
}

0 commit comments

Comments
 (0)