Exemple #1
0
        public async Task sends_DisplayData_message_on_ValueProduced()
        {
            var scheduler = CreateScheduler();
            var request   = ZeroMQMessage.Create(new ExecuteRequest("display(2+2);"));
            var context   = new JupyterRequestContext(JupyterMessageSender, request);
            await scheduler.Schedule(context);

            await context.Done().Timeout(20.Seconds());

            JupyterMessageSender.PubSubMessages.Should().Contain(r => r is DisplayData);
        }
Exemple #2
0
        public async Task sends_Stream_message_on_StandardOutputValueProduced()
        {
            var scheduler = CreateScheduler();
            var request   = ZeroMQMessage.Create(new ExecuteRequest("Console.WriteLine(2+2);"));
            var context   = new JupyterRequestContext(JupyterMessageSender, request);
            await scheduler.Schedule(context);

            await context.Done().Timeout(20.Seconds());

            JupyterMessageSender.PubSubMessages.Should().Contain(r => r is Stream && r.As <Stream>().Name == Stream.StandardOutput);
        }
        public async Task sends_ExecuteReply_message_when_submission_contains_only_a_directive()
        {
            var scheduler = CreateScheduler();
            var request   = Envelope.Create(new ExecuteRequest("%%csharp"));
            var context   = new JupyterRequestContext(JupyterMessageSender, request, "id");
            await scheduler.Schedule(context);

            await context.Done().Timeout(5.Seconds());

            JupyterMessageSender.ReplyMessages.Should().ContainItemsAssignableTo <ExecuteReplyOk>();
        }
        public async Task sends_ExecuteReply_message_on_ReturnValueProduced()
        {
            var scheduler = CreateScheduler();
            var request   = Envelope.Create(new ExecuteRequest("2+2"));
            var context   = new JupyterRequestContext(JupyterMessageSender, request, "id");
            await scheduler.Schedule(context);

            await context.Done().Timeout(20.Seconds());

            JupyterMessageSender.PubSubMessages.Should().Contain(r => r is ExecuteResult);
        }
        public async Task sends_ExecuteReply_with_error_message_on_when_code_submission_contains_errors()
        {
            var scheduler = CreateScheduler();
            var request   = ZeroMQMessage.Create(new ExecuteRequest("asdes"));
            var context   = new JupyterRequestContext(JupyterMessageSender, request);
            await scheduler.Schedule(context);

            await context.Done().Timeout(5.Seconds());

            JupyterMessageSender.ReplyMessages.Should().ContainItemsAssignableTo <ExecuteReplyError>();
            JupyterMessageSender.PubSubMessages.Should().Contain(e => e is Error);
        }
        public async Task sends_isCompleteReply_with_incomplete_and_indent_if_the_code_is_not_a_complete_submission()
        {
            var scheduler = CreateScheduler();
            var request   = ZeroMQMessage.Create(new IsCompleteRequest("var a = 12"), null);
            var context   = new JupyterRequestContext(JupyterMessageSender, request);

            await scheduler.Schedule(context);

            await context.Done().Timeout(5.Seconds());

            JupyterMessageSender.ReplyMessages.OfType <IsCompleteReply>().Should().ContainSingle(r => r.Status == "incomplete" && r.Indent == "*");
        }
        public async Task sends_ExecuteReply_message_when_submission_contains_only_a_directive()
        {
            var scheduler = CreateScheduler();
            var request   = ZeroMQMessage.Create(new ExecuteRequest("#!csharp"));
            var context   = new JupyterRequestContext(JupyterMessageSender, request);
            await scheduler.Schedule(context);

            await context.Done().Timeout(5.Seconds());

            JupyterMessageSender.ReplyMessages
            .Should()
            .ContainSingle <ExecuteReplyOk>();
        }
        public async Task sends_ExecuteReply_message_on_when_code_submission_is_handled()
        {
            var scheduler = CreateScheduler();
            var request   = ZeroMQMessage.Create(new ExecuteRequest("var a =12;"));
            var context   = new JupyterRequestContext(JupyterMessageSender, request);
            await scheduler.Schedule(context);

            await context.Done().Timeout(5.Seconds());

            JupyterMessageSender.ReplyMessages
            .Should()
            .ContainItemsAssignableTo <ExecuteReplyOk>();
        }
        public async Task sends_ExecuteReply_message_on_when_code_submission_is_handled()
        {
            var scheduler = CreateScheduler();
            var request   = Message.Create(new ExecuteRequest("var a =12;"), null);
            var context   = new JupyterRequestContext(ServerChannel, IoPubChannel, request, "id");
            await scheduler.Schedule(context);

            await context.Done().Timeout(5.Seconds());

            ServerRecordingSocket.DecodedMessages
            .Should().Contain(message =>
                              message.Contains(JupyterMessageContentTypes.ExecuteReply));
        }
Exemple #10
0
        public async Task sends_isCompleteReply_with_complete_if_the_code_is_a_complete_submission()
        {
            var scheduler = CreateScheduler();
            var request   = Envelope
                            .Create(new IsCompleteRequest("var a = 12;"), null);
            var context = new JupyterRequestContext(JupyterMessageSender, request, "id");

            await scheduler.Schedule(context);

            await context.Done().Timeout(5.Seconds());

            JupyterMessageSender.ReplyMessages.OfType <IsCompleteReply>().Should().ContainSingle(r => r.Status == "complete");
        }
        public async Task sends_DisplayData_message_with_json_when_json_mimetype_is_requested()
        {
            var scheduler = CreateScheduler();
            var request   = ZeroMQMessage.Create(new ExecuteRequest(@"display(2+2,""application/json"");"));
            var context   = new JupyterRequestContext(JupyterMessageSender, request);
            await scheduler.Schedule(context);

            await context.Done().Timeout(20.Seconds());

            JupyterMessageSender.PubSubMessages
            .Should()
            .ContainSingle <DisplayData>(r => r.Data["application/json"] is JToken token && token.Type == JTokenType.Integer);
        }
        public async Task does_not_send_ExecuteResult_message_when_evaluating_display_value(Language language)
        {
            var scheduler = CreateScheduler();

            SetKernelLanguage(language);
            var request = ZeroMQMessage.Create(new ExecuteRequest("display(2+2)"));
            var context = new JupyterRequestContext(JupyterMessageSender, request);
            await scheduler.Schedule(context);

            await context.Done().Timeout(20.Seconds());

            JupyterMessageSender.PubSubMessages.Should().NotContain(r => r is ExecuteResult);
        }
        public async Task send_completeReply_on_CompleteRequest()
        {
            var scheduler = CreateScheduler();
            var request   = ZeroMQMessage.Create(new CompleteRequest("System.Console.", 15));
            var context   = new JupyterRequestContext(JupyterMessageSender, request);

            await scheduler.Schedule(context);

            await context.Done().Timeout(5.Seconds());

            JupyterMessageSender.ReplyMessages
            .Should()
            .ContainSingle(r => r is CompleteReply);
        }
        public async Task sends_InterruptReply()
        {
            var scheduler = CreateScheduler();
            var request   = ZeroMQMessage.Create(new InterruptRequest(), null);
            var context   = new JupyterRequestContext(JupyterMessageSender, request);

            await scheduler.Schedule(context);

            await context.Done().Timeout(5.Seconds());

            JupyterMessageSender.ReplyMessages
            .Should()
            .ContainSingle(r => r is InterruptReply);
        }
        public async Task sends_ExecuteInput_when_ExecuteRequest_is_handled()
        {
            var scheduler = CreateScheduler();
            var request   = ZeroMQMessage.Create(new ExecuteRequest("var a =12;"));
            var context   = new JupyterRequestContext(JupyterMessageSender, request);
            await scheduler.Schedule(context);

            await context.Done().Timeout(5.Seconds());

            JupyterMessageSender.PubSubMessages.Should()
            .ContainItemsAssignableTo <ExecuteInput>();

            JupyterMessageSender.PubSubMessages.OfType <ExecuteInput>().Should().Contain(r => r.Code == "var a =12;");
        }
        public void cell_language_can_be_pulled_from_metadata_when_present()
        {
            var metaData = new Dictionary <string, object>
            {
                { "dotnet_interactive", new InputCellMetadata("fsharp") }
            };
            var request  = ZeroMQMessage.Create(new IsCompleteRequest("1+1"), metaData: metaData);
            var context  = new JupyterRequestContext(JupyterMessageSender, request);
            var language = context.GetLanguage();

            language
            .Should()
            .Be("fsharp");
        }
        public async Task send_completeReply_on_CompleteRequest()
        {
            var scheduler = CreateScheduler();
            var request   = Message.Create(new CompleteRequest("System.Console.", 15), null);
            var context   = new JupyterRequestContext(ServerChannel, IoPubChannel, request, "id");

            await scheduler.Schedule(context);

            await context.Done().Timeout(5.Seconds());

            ServerRecordingSocket.DecodedMessages
            .Should()
            .Contain(message =>
                     message.Contains(JupyterMessageContentTypes.CompleteReply));
        }
        public async Task sends_InputRequest_message_when_submission_requests_user_password_in_csharp(string code, string prompt)
        {
            var scheduler = CreateScheduler();
            var request   = ZeroMQMessage.Create(new ExecuteRequest(code));
            var context   = new JupyterRequestContext(JupyterMessageSender, request);
            await scheduler.Schedule(context);

            await context.Done().Timeout(20.Seconds());

            JupyterMessageSender.RequestMessages.Should().Contain(r => r.Prompt == prompt && r.Password);
            JupyterMessageSender.PubSubMessages
            .OfType <ExecuteResult>()
            .Should()
            .Contain(dp => dp.Data["text/html"] as string == $"{typeof(PasswordString).FullName}");
        }
        public async Task password_input_should_not_appear_in_diagnostic_logs()
        {
            var log = new System.Text.StringBuilder();

            using var _ = LogEvents.Subscribe(e => log.Append(e.ToLogString()));

            var scheduler = CreateScheduler();
            var request   = ZeroMQMessage.Create(new ExecuteRequest("password(\"Password:\")"));
            var context   = new JupyterRequestContext(JupyterMessageSender, request);
            await scheduler.Schedule(context);

            await context.Done().Timeout(20.Seconds());

            log.ToString().Should().NotContain("secret");
        }
        public async Task sends_InputRequest_message_when_submission_requests_user_input_in_csharp(string code, string prompt, string expectedDisplayValue)
        {
            var scheduler = CreateScheduler();
            var request   = ZeroMQMessage.Create(new ExecuteRequest(code));
            var context   = new JupyterRequestContext(JupyterMessageSender, request);
            await scheduler.Schedule(context);

            await context.Done().Timeout(20.Seconds());

            JupyterMessageSender.RequestMessages.Should().Contain(r => r.Prompt == prompt && r.Password == false);
            JupyterMessageSender.PubSubMessages
            .OfType <ExecuteResult>()
            .Should()
            .Contain(dp => dp.Data["text/plain"] as string == expectedDisplayValue);
        }
Exemple #21
0
        public async Task does_display_MathString_values_on_ReturnValueProduced(Language language, string code, string expectedDisplayValue)
        {
            var scheduler = CreateScheduler();

            SetKernelLanguage(language);
            var request = ZeroMQMessage.Create(new ExecuteRequest(code));
            var context = new JupyterRequestContext(JupyterMessageSender, request);
            await scheduler.Schedule(context);

            await context.Done().Timeout(20.Seconds());

            JupyterMessageSender.PubSubMessages
            .OfType <ExecuteResult>()
            .Should()
            .Contain(dp => dp.Data["text/latex"] as string == expectedDisplayValue);
        }
Exemple #22
0
        public async Task does_not_expose_stacktrace_when_code_submission_contains_errors()
        {
            var scheduler = CreateScheduler();
            var request   = ZeroMQMessage.Create(new ExecuteRequest("asdes asdasd"));
            var context   = new JupyterRequestContext(JupyterMessageSender, request);
            await scheduler.Schedule(context);

            await context.Done().Timeout(5.Seconds());

            JupyterMessageSender.PubSubMessages.Should()
            .ContainSingle <Stream>()
            .Which
            .Text
            .Should()
            .ContainAll("(1,13): error CS1002:", ";");
        }
        public async Task sends_InterruptReply()
        {
            var scheduler = CreateScheduler();
            var request   = Message.Create(new InterruptRequest(), null);
            var context   = new JupyterRequestContext(ServerChannel, IoPubChannel, request);

            await scheduler.Schedule(context);

            await context.Done().Timeout(5.Seconds());

            ServerRecordingSocket.DecodedMessages
            .SingleOrDefault(message =>
                             message.Contains(JupyterMessageContentTypes.InterruptReply))
            .Should()
            .NotBeNullOrWhiteSpace();
        }
        public async Task does_not_expose_stacktrace_when_code_submission_contains_errors()
        {
            var scheduler = CreateScheduler();
            var request   = ZeroMQMessage.Create(new ExecuteRequest("asdes asdasd"));
            var context   = new JupyterRequestContext(JupyterMessageSender, request);
            await scheduler.Schedule(context);

            await context.Done().Timeout(5.Seconds());

            JupyterMessageSender.PubSubMessages.Should()
            .ContainSingle(e => e is Error)
            .Which.As <Error>()
            .Traceback
            .Should()
            .BeEquivalentTo("(1,13): error CS1002: ; expected");
        }
        public async Task sends_ExecuteReply_message_on_ReturnValueProduced()
        {
            var scheduler = CreateScheduler();
            var request   = Message.Create(new ExecuteRequest("2+2"), null);
            var context   = new JupyterRequestContext(ServerChannel, IoPubChannel, request, "id");
            await scheduler.Schedule(context);

            await context.Done().Timeout(5.Seconds());

            ServerRecordingSocket.DecodedMessages
            .Should().Contain(message =>
                              message.Contains(JupyterMessageContentTypes.ExecuteReply));

            IoRecordingSocket.DecodedMessages
            .Should().Contain(message =>
                              message.Contains(JupyterMessageContentTypes.ExecuteResult));
        }
        public async Task sends_DisplayData_message_on_ValueProduced()
        {
            var scheduler = CreateScheduler();
            var request   = Message.Create(new ExecuteRequest("Console.WriteLine(2+2);"), null);
            var context   = new JupyterRequestContext(ServerChannel, IoPubChannel, request, "id");
            await scheduler.Schedule(context);

            await context.Done().Timeout(10.Seconds());

            ServerRecordingSocket.DecodedMessages
            .Should().Contain(message =>
                              message.Contains(JupyterMessageContentTypes.ExecuteReply));

            IoRecordingSocket.DecodedMessages
            .Should().Contain(message =>
                              message.Contains(JupyterMessageContentTypes.DisplayData));
        }
        public async Task sends_InputRequest_message_when_submission_requests_user_password_in_powershell(string code, string prompt)
        {
            SetKernelLanguage(Language.PowerShell);

            var scheduler = CreateScheduler();
            var request   = ZeroMQMessage.Create(new ExecuteRequest(code));
            var context   = new JupyterRequestContext(JupyterMessageSender, request);
            await scheduler.Schedule(context);

            await context.Done().Timeout(20.Seconds());

            JupyterMessageSender.RequestMessages.Should().Contain(r => r.Prompt == prompt && r.Password == true);
            JupyterMessageSender.PubSubMessages
            .OfType <Stream>()
            .Should()
            .Contain(s => s.Name == Stream.StandardOutput && s.Text == $"System.Security.SecureString{Environment.NewLine}");
        }
        public async Task shows_diagnostics_on_erroneous_input(Language language, string expected)
        {
            var scheduler = CreateScheduler();

            SetKernelLanguage(language);
            var request = ZeroMQMessage.Create(new ExecuteRequest("1+!"));
            var context = new JupyterRequestContext(JupyterMessageSender, request);
            await scheduler.Schedule(context);

            await context.Done().Timeout(5.Seconds());

            JupyterMessageSender.PubSubMessages.Should()
            .ContainSingle <Stream>()
            .Which
            .Text
            .Should()
            .Contain(expected);
        }
        public async Task sends_ExecuteReply_with_error_message_on_when_code_submission_contains_errors()
        {
            var scheduler = CreateScheduler();
            var request   = Message.Create(new ExecuteRequest("asdes"), null);
            var context   = new JupyterRequestContext(ServerChannel, IoPubChannel, request, "id");
            await scheduler.Schedule(context);

            await context.Done().Timeout(5.Seconds());

            ServerRecordingSocket.DecodedMessages
            .Should()
            .Contain(message => message.Contains(JupyterMessageContentTypes.ExecuteReply))
            .And
            .Contain(message => message.Contains($"\"status\":\"{StatusValues.Error}\""));

            IoRecordingSocket.DecodedMessages
            .Should().Contain(message =>
                              message.Contains(JupyterMessageContentTypes.Stream));
        }
        public async Task sends_ExecuteReply_message_on_ReturnValueProduced()
        {
            var scheduler = CreateScheduler();
            var request   = ZeroMQMessage.Create(new ExecuteRequest("2+2"));
            var context   = new JupyterRequestContext(JupyterMessageSender, request);
            await scheduler.Schedule(context);

            await context.Done().Timeout(20.Seconds());

            using var _ = new AssertionScope();

            JupyterMessageSender.PubSubMessages
            .Should()
            .ContainSingle <ExecuteResult>()
            .Which
            .Data
            .Should()
            .ContainSingle(d => d.Key.Equals("text/html") && d.Value.Equals("<div class=\"dni-plaintext\">4</div>"));
        }