-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1515b07
commit effb835
Showing
8 changed files
with
143 additions
and
106 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
src/dotnet-repl.Tests/Notebooks/NotebookAutomationTests.cs
This file contains 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,65 @@ | ||
using System; | ||
using System.CommandLine.IO; | ||
using System.CommandLine.Parsing; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using dotnet_repl.Tests.Utility; | ||
using FluentAssertions; | ||
using Pocket; | ||
using Spectre.Console; | ||
using Xunit; | ||
|
||
namespace dotnet_repl.Tests.Notebooks; | ||
|
||
public class NotebookAutomationTests : IDisposable | ||
{ | ||
private readonly IAnsiConsole _ansiConsole; | ||
|
||
private readonly StringWriter _writer; | ||
|
||
public NotebookAutomationTests() | ||
{ | ||
_ansiConsole = AnsiConsole.Create(new AnsiConsoleSettings | ||
{ | ||
Ansi = AnsiSupport.Yes, | ||
Interactive = InteractionSupport.Yes, | ||
Out = new AnsiConsoleOutput(_writer = new StringWriter()) | ||
}); | ||
} | ||
|
||
public void Dispose() => _writer.Dispose(); | ||
|
||
[Fact] | ||
public async Task When_an_ipynb_is_run_and_no_error_is_produced_then_the_exit_code_is_0() | ||
{ | ||
using var disposables = new CompositeDisposable(); | ||
var directory = Path.GetDirectoryName(PathUtility.PathToCurrentSourceFile()); | ||
|
||
var parser = CommandLineParser.Create(_ansiConsole, registerForDisposal: d => disposables.Add(d)); | ||
|
||
var console = new TestConsole(); | ||
var result = await parser.InvokeAsync($"--notebook \"{directory}/succeed.ipynb\" --exit-after-run", console); | ||
|
||
var output = _writer.ToString(); | ||
console.Error.ToString().Should().BeEmpty(); | ||
result.Should().Be(0); | ||
output.Should().Contain("Success!"); | ||
} | ||
|
||
[Fact] | ||
public async Task When_an_ipynb_is_run_and_an_error_is_produced_from_a_cell_then_the_exit_code_is_1() | ||
{ | ||
using var disposables = new CompositeDisposable(); | ||
var directory = Path.GetDirectoryName(PathUtility.PathToCurrentSourceFile()); | ||
|
||
var parser = CommandLineParser.Create(_ansiConsole, registerForDisposal: d => disposables.Add(d)); | ||
|
||
var console = new TestConsole(); | ||
var result = await parser.InvokeAsync($"--notebook \"{directory}/fail.ipynb\" --exit-after-run", console); | ||
|
||
var output = _writer.ToString(); | ||
console.Error.ToString().Should().BeEmpty(); | ||
result.Should().Be(1); | ||
output.Should().Contain("Oops!"); | ||
} | ||
} |
This file contains 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,51 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Here is a Markdown heading\n", | ||
"\n", | ||
"And here is some text." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": { | ||
"dotnet_interactive": { | ||
"language": "csharp" | ||
} | ||
}, | ||
"source": [ | ||
"throw new Exception(\"Oops!\");" | ||
], | ||
"outputs": [ | ||
{ | ||
"output_type": "error", | ||
"ename": "", | ||
"evalue": "System.Exception: oops!\r\n at Submission#2.<<Initialize>>d__0.MoveNext()\r\n--- End of stack trace from previous location ---\r\n at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)", | ||
"traceback": [ | ||
null | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": ".NET (C#)", | ||
"language": "C#", | ||
"name": ".net-csharp" | ||
}, | ||
"language_info": { | ||
"file_extension": ".cs", | ||
"mimetype": "text/x-csharp", | ||
"name": "C#", | ||
"pygments_lexer": "csharp", | ||
"version": "8.0" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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