Skip to content

Commit

Permalink
refactoring and a couple small automation bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsequitur committed Aug 24, 2022
1 parent 3b31267 commit 6dc4f45
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
},
"outputs": [
{
"ename": "System.Exception: oops!\r\n at Submission#3.<<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)",
"evalue": "Error",
"ename": "Error",
"evalue": "System.Exception: oops!\r\n at Submission#3.<<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)",
"output_type": "error",
"traceback": [
" at Submission#3.<<Initialize>>d__0.MoveNext()",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
using Automation;
using dotnet_repl.Tests.Utility;
using FluentAssertions;
using Microsoft.DotNet.Interactive.CSharp;
using Microsoft.DotNet.Interactive.Documents;
using Microsoft.DotNet.Interactive.Documents.Jupyter;
using Microsoft.DotNet.Interactive.Formatting;
using Pocket;
using Spectre.Console;
using TRexLib;
using Xunit;

namespace dotnet_repl.Tests.Automation;

public class NotebookAutomationTests : IDisposable
public class NotebookRunnerTests : IDisposable
{
private readonly CompositeDisposable _disposables = new();
private readonly StringWriter _writer;
Expand All @@ -30,7 +33,7 @@ public class NotebookAutomationTests : IDisposable
.UsingExtension("json")
.SetInteractive(Debugger.IsAttached);

public NotebookAutomationTests()
public NotebookRunnerTests()
{
var ansiConsole = AnsiConsole.Create(new AnsiConsoleSettings
{
Expand Down Expand Up @@ -90,6 +93,29 @@ public async Task Notebook_runner_produces_expected_output()
this.Assent(resultContent, _assentConfiguration);
}

[Fact]
public async Task ASCII_escape_sequences_do_not_cause_XML_parse_problems()
{
using var kernel = new CSharpKernel();

var runner = new NotebookRunner(kernel);

var inputDoc = new InteractiveDocument
{
new InteractiveDocumentElement("123.Display(\"unknown/MIMEtype\");", "csharp")
};
var outputDoc = await runner.RunNotebookAsync(inputDoc);

var xml = outputDoc.ToTestOutputDocumentXml();

TestOutputDocumentParser.Parse(xml);



// TODO (ASCII_escape_sequences_do_not_cause_XML_parse_problems) write test
throw new NotImplementedException();
}

private void NormalizeMetadata(InteractiveDocument document)
{
foreach (var element in document.Elements)
Expand Down
10 changes: 2 additions & 8 deletions src/dotnet-repl.Tests/ReplInteractionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@

namespace dotnet_repl.Tests;

[CollectionDefinition("Do not parallelize", DisableParallelization = true)]
public class SerialTestCollectionDefinition
{

}

[LogToPocketLogger(@"c:\temp\dotnet-repl.test.log")]
[Xunit.Collection("Do not parallelize")]
[Collection("Do not parallelize")]
public abstract class ReplInteractionTests : IDisposable
{
private readonly CompositeDisposable _disposables;
Expand Down Expand Up @@ -47,7 +41,7 @@ protected ReplInteractionTests(ITestOutputHelper output)
AnsiConsole,
In);

Repl.Start();
var _ = Repl.StartAsync();

_disposables = new CompositeDisposable
{
Expand Down
11 changes: 11 additions & 0 deletions src/dotnet-repl.Tests/SerialTestCollectionDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Xunit;

namespace dotnet_repl.Tests;

[CollectionDefinition("Do not parallelize", DisableParallelization = true)]
public class SerialTestCollectionDefinition
{
}
11 changes: 5 additions & 6 deletions src/dotnet-repl/Automation/NotebookRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,13 @@ private DisplayElement CreateDisplayOutputElement(DisplayEvent displayedValuePro
v => (object)v.Value));

private ErrorElement CreateErrorOutputElement(ErrorProduced errorProduced) =>
new("Error",
errorProduced.Message,
Array.Empty<string>());
new(errorName: "Error",
errorValue: errorProduced.Message);

private ErrorElement CreateErrorOutputElement(CommandFailed failed) =>
new("Error",
failed.Message,
failed.Exception switch
new(errorName: "Error",
errorValue: failed.Message,
stackTrace: failed.Exception switch
{
{ } ex => (ex.StackTrace ?? "").SplitIntoLines(),
_ => Array.Empty<string>()
Expand Down
4 changes: 1 addition & 3 deletions src/dotnet-repl/CommandLineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
using Automation;
using Microsoft.DotNet.Interactive.Documents;
using Microsoft.DotNet.Interactive.Documents.Jupyter;
using Microsoft.DotNet.Interactive.Formatting;
using Pocket;
using Spectre.Console;
using Formatter = Microsoft.DotNet.Interactive.Formatting.Formatter;

namespace dotnet_repl;

Expand Down Expand Up @@ -187,7 +185,7 @@ await repl.RunAsync(

case OutputFormat.trx:
{
var output = resultNotebook.ToTrxString();
var output = resultNotebook.ToTestOutputDocumentXml();

if (options.OutputPath is null)
{
Expand Down
13 changes: 10 additions & 3 deletions src/dotnet-repl/Trx.cs → src/dotnet-repl/DocumentConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

namespace dotnet_repl;

internal static class Trx
public static class DocumentConverter
{
internal static string ToTrxString(this InteractiveDocument resultNotebook)
public static List<TestResult> ToTestOutputDocument(InteractiveDocument resultNotebook)
{
var testResults = new List<TestResult>();

Expand Down Expand Up @@ -70,9 +70,16 @@ internal static string ToTrxString(this InteractiveDocument resultNotebook)
testResults.Add(testResult);
}

return testResults;
}

public static string ToTestOutputDocumentXml(this InteractiveDocument resultNotebook)
{
var testResults = ToTestOutputDocument(resultNotebook);

using var writer = new StringWriter();

var testOutputWriter = new TestOutputFileWriter(writer);
var testOutputWriter = new TestOutputDocumentWriter(writer);

testOutputWriter.Write(new TestResultSet(testResults));

Expand Down
9 changes: 8 additions & 1 deletion src/dotnet-repl/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{
"profiles": {
"dotnet-repl": {
"WSL": {
"commandName": "WSL2",
"distributionName": ""
},
"run and exit, .trx": {
"commandName": "Project",
"commandLineArgs": "--notebook \"C:\\dev\\interactive\\samples\\Notebooks\\csharp\\Samples\\DataFrame-Getting Started.ipynb\" --output-format trx --output-path c:\\temp\\automation\\DataFrame-output.trx --exit-after-run"
},
"REPL": {
"commandName": "Project"
}
}
}
2 changes: 1 addition & 1 deletion src/dotnet-repl/Repl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public Repl(

private LineEditorServiceProvider? LineEditorProvider { get; }

public async Task Start()
public async Task StartAsync()
{
var ready = ReadyForInput.Replay();
var _ = Task.Run(() => RunAsync(_ => { }));
Expand Down

0 comments on commit 6dc4f45

Please sign in to comment.