Skip to content

Commit 60300c7

Browse files
committed
Provide executeTests with inputs testing opportunity
1 parent b7ff093 commit 60300c7

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/test/kotlin/org/jetbrains/kotlin/jupyter/test/executeTests.kt

+19-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package org.jetbrains.kotlin.jupyter.test
22

33
import com.beust.klaxon.JsonObject
4-
import org.jetbrains.kotlin.jupyter.JupyterSockets
5-
import org.jetbrains.kotlin.jupyter.Message
6-
import org.jetbrains.kotlin.jupyter.get
7-
import org.jetbrains.kotlin.jupyter.jsonObject
4+
import org.jetbrains.kotlin.jupyter.*
85
import org.junit.Assert
96
import org.junit.Test
107
import org.zeromq.ZMQ
@@ -15,15 +12,27 @@ fun Message.type(): String {
1512

1613
class ExecuteTests : KernelServerTestsBase() {
1714

18-
private fun doExecute(code : String, hasResult: Boolean = true, ioPubChecker : (ZMQ.Socket) -> Unit = {}) : Any? {
15+
private fun doExecute(
16+
code : String,
17+
hasResult: Boolean = true,
18+
ioPubChecker : (ZMQ.Socket) -> Unit = {},
19+
inputs: List<String> = emptyList(),
20+
) : Any? {
1921
val context = ZMQ.context(1)
20-
val shell = context.socket(ZMQ.REQ)
21-
val ioPub = context.socket(ZMQ.SUB)
22+
val shell = ClientSocket(context, JupyterSockets.shell)
23+
val ioPub = ClientSocket(context, JupyterSockets.iopub)
24+
val stdin = ClientSocket(context, JupyterSockets.stdin)
2225
ioPub.subscribe(byteArrayOf())
2326
try {
24-
shell.connect("${config.transport}://*:${config.ports[JupyterSockets.shell.ordinal]}")
25-
ioPub.connect("${config.transport}://*:${config.ports[JupyterSockets.iopub.ordinal]}")
27+
shell.connect()
28+
ioPub.connect()
29+
stdin.connect()
30+
2631
shell.sendMessage("execute_request", content = jsonObject("code" to code))
32+
inputs.forEach {
33+
stdin.sendMessage("input_reply", jsonObject("value" to it))
34+
}
35+
2736
var msg = shell.receiveMessage()
2837
Assert.assertEquals("execute_reply", msg.type())
2938
msg = ioPub.receiveMessage()
@@ -48,6 +57,7 @@ class ExecuteTests : KernelServerTestsBase() {
4857
} finally {
4958
shell.close()
5059
ioPub.close()
60+
stdin.close()
5161
context.term()
5262
}
5363
}

0 commit comments

Comments
 (0)