-
Notifications
You must be signed in to change notification settings - Fork 668
DYN-10248: Fix crash when opening the Python Migration Assistant on an IronPython2 node #17022
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
Merged
+157
−8
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
test/Libraries/DynamoPythonTests/PythonMigrationAssistantViewModelTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| using System; | ||
| using System.IO; | ||
| using Dynamo; | ||
| using Dynamo.Graph.Workspaces; | ||
| using Dynamo.PythonMigration.Differ; | ||
| using Dynamo.PythonMigration.MigrationAssistant; | ||
| using NUnit.Framework; | ||
| using PythonNodeModels; | ||
|
|
||
| namespace DynamoPythonTests | ||
| { | ||
| [TestFixture] | ||
| public class PythonMigrationAssistantViewModelTests : DynamoModelTestBase | ||
| { | ||
| /// <summary> | ||
| /// Regression test: when Python.Runtime is an incompatible version (e.g. pythonnet 2.x loaded | ||
| /// instead of 3.x), Py.CreateScope() throws TypeLoadException because PyModule does not exist | ||
| /// in that assembly. The ViewModel must catch this and show an error state rather than crashing. | ||
| /// </summary> | ||
| [Test] | ||
| public void WhenMigrationThrowsTypeLoadExceptionViewModelShowsErrorState() | ||
| { | ||
| // Arrange | ||
| var pyNode = new PythonNode(); | ||
| var workspace = CurrentDynamoModel.CurrentWorkspace as WorkspaceModel; | ||
| var pathManager = CurrentDynamoModel.PathManager; | ||
|
|
||
| Func<string, string> brokenMigrator = _ => | ||
| throw new TypeLoadException("Could not load type 'Python.Runtime.PyModule' from assembly 'Python.Runtime, Version=2.5.2.12086'"); | ||
|
|
||
| // Act | ||
| PythonMigrationAssistantViewModel viewModel = null; | ||
| Assert.DoesNotThrow(() => | ||
| { | ||
| viewModel = new PythonMigrationAssistantViewModel( | ||
| pyNode, workspace, pathManager, new Version(3, 0), brokenMigrator); | ||
| }); | ||
|
|
||
| // Assert | ||
| Assert.IsNotNull(viewModel); | ||
| Assert.AreEqual(State.Error, viewModel.CurrentViewModel.DiffState); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Verifies that a MissingMethodException (e.g. missing member in incompatible Python.Runtime) | ||
| /// during migration is handled gracefully and shows an error state. | ||
| /// </summary> | ||
zeusongit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [Test] | ||
| public void WhenMigrationThrowsMissingMethodExceptionViewModelShowsErrorState() | ||
| { | ||
| var pyNode = new PythonNode(); | ||
| var workspace = CurrentDynamoModel.CurrentWorkspace as WorkspaceModel; | ||
| var pathManager = CurrentDynamoModel.PathManager; | ||
|
|
||
| Func<string, string> brokenMigrator = _ => | ||
| throw new MissingMethodException("Python.Runtime.Py", "CreateScope"); | ||
|
|
||
| PythonMigrationAssistantViewModel viewModel = null; | ||
| Assert.DoesNotThrow(() => | ||
| { | ||
| viewModel = new PythonMigrationAssistantViewModel( | ||
| pyNode, workspace, pathManager, new Version(3, 0), brokenMigrator); | ||
| }); | ||
|
|
||
| Assert.IsNotNull(viewModel); | ||
| Assert.AreEqual(State.Error, viewModel.CurrentViewModel.DiffState); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Verifies that a FileLoadException (e.g. assembly version conflict) during migration | ||
| /// is handled gracefully and shows an error state. | ||
| /// </summary> | ||
| [Test] | ||
| public void WhenMigrationThrowsFileLoadExceptionViewModelShowsErrorState() | ||
| { | ||
| var pyNode = new PythonNode(); | ||
| var workspace = CurrentDynamoModel.CurrentWorkspace as WorkspaceModel; | ||
| var pathManager = CurrentDynamoModel.PathManager; | ||
|
|
||
| Func<string, string> brokenMigrator = _ => | ||
| throw new FileLoadException("Could not load file or assembly 'Python.Runtime'"); | ||
|
|
||
| PythonMigrationAssistantViewModel viewModel = null; | ||
| Assert.DoesNotThrow(() => | ||
| { | ||
| viewModel = new PythonMigrationAssistantViewModel( | ||
| pyNode, workspace, pathManager, new Version(3, 0), brokenMigrator); | ||
| }); | ||
|
|
||
| Assert.IsNotNull(viewModel); | ||
| Assert.AreEqual(State.Error, viewModel.CurrentViewModel.DiffState); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Verifies that a BadImageFormatException (e.g. 32/64-bit or .NET target mismatch in | ||
| /// Python.Runtime) during migration is handled gracefully and shows an error state. | ||
| /// </summary> | ||
| [Test] | ||
| public void WhenMigrationThrowsBadImageFormatExceptionViewModelShowsErrorState() | ||
| { | ||
| var pyNode = new PythonNode(); | ||
| var workspace = CurrentDynamoModel.CurrentWorkspace as WorkspaceModel; | ||
| var pathManager = CurrentDynamoModel.PathManager; | ||
|
|
||
| Func<string, string> brokenMigrator = _ => | ||
| throw new BadImageFormatException("The format of the file 'Python.Runtime' is invalid."); | ||
|
|
||
| PythonMigrationAssistantViewModel viewModel = null; | ||
| Assert.DoesNotThrow(() => | ||
| { | ||
| viewModel = new PythonMigrationAssistantViewModel( | ||
| pyNode, workspace, pathManager, new Version(3, 0), brokenMigrator); | ||
| }); | ||
|
|
||
| Assert.IsNotNull(viewModel); | ||
| Assert.AreEqual(State.Error, viewModel.CurrentViewModel.DiffState); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.