@@ -7,6 +7,7 @@ import org.jetbrains.kotlin.jupyter.get
7
7
import org.jetbrains.kotlin.jupyter.jsonObject
8
8
import org.junit.jupiter.api.Assertions.assertEquals
9
9
import org.junit.jupiter.api.Assertions.assertNull
10
+ import org.junit.jupiter.api.Assertions.assertTrue
10
11
import org.junit.jupiter.api.Test
11
12
import org.junit.jupiter.api.Timeout
12
13
import org.zeromq.ZMQ
@@ -24,6 +25,7 @@ class ExecuteTests : KernelServerTestsBase() {
24
25
hasResult : Boolean = true,
25
26
ioPubChecker : (ZMQ .Socket ) -> Unit = {},
26
27
inputs : List <String > = emptyList(),
28
+ allowStdin : Boolean = true,
27
29
): Any? {
28
30
val context = ZMQ .context(1 )
29
31
val shell = ClientSocket (context, JupyterSockets .shell)
@@ -35,7 +37,7 @@ class ExecuteTests : KernelServerTestsBase() {
35
37
ioPub.connect()
36
38
stdin.connect()
37
39
38
- shell.sendMessage(" execute_request" , content = jsonObject(" code" to code))
40
+ shell.sendMessage(" execute_request" , content = jsonObject(" code" to code, " allow_stdin " to allowStdin ))
39
41
inputs.forEach {
40
42
stdin.sendMessage(" input_reply" , jsonObject(" value" to it))
41
43
}
@@ -69,6 +71,19 @@ class ExecuteTests : KernelServerTestsBase() {
69
71
}
70
72
}
71
73
74
+ private fun testWithNoStdin (code : String ) {
75
+ doExecute(
76
+ code,
77
+ hasResult = false ,
78
+ allowStdin = false ,
79
+ ioPubChecker = {
80
+ val msg = it.receiveMessage()
81
+ assertEquals(" stream" , msg.type())
82
+ assertTrue((msg.content!! [" text" ] as String ).startsWith(" java.io.IOException: Input from stdin is unsupported by the client" ))
83
+ }
84
+ )
85
+ }
86
+
72
87
@Test
73
88
fun testExecute () {
74
89
val res = doExecute(" 2+2" ) as JsonObject
@@ -153,4 +168,14 @@ class ExecuteTests : KernelServerTestsBase() {
153
168
val res = doExecute(code, inputs = listOf (" 42" ))
154
169
assertEquals(jsonObject(" text/plain" to " 42" ), res)
155
170
}
171
+
172
+ @Test
173
+ fun testReadLineWithNoStdin () {
174
+ testWithNoStdin(" readLine() ?: \" blah\" " )
175
+ }
176
+
177
+ @Test
178
+ fun testStdinReadWithNoStdin () {
179
+ testWithNoStdin(" System.`in`.read()" )
180
+ }
156
181
}
0 commit comments