1
1
package org.jetbrains.kotlin.jupyter.test
2
2
3
3
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.*
8
5
import org.junit.Assert
9
6
import org.junit.Test
10
7
import org.zeromq.ZMQ
@@ -15,15 +12,27 @@ fun Message.type(): String {
15
12
16
13
class ExecuteTests : KernelServerTestsBase () {
17
14
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? {
19
21
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)
22
25
ioPub.subscribe(byteArrayOf())
23
26
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
+
26
31
shell.sendMessage(" execute_request" , content = jsonObject(" code" to code))
32
+ inputs.forEach {
33
+ stdin.sendMessage(" input_reply" , jsonObject(" value" to it))
34
+ }
35
+
27
36
var msg = shell.receiveMessage()
28
37
Assert .assertEquals(" execute_reply" , msg.type())
29
38
msg = ioPub.receiveMessage()
@@ -48,6 +57,7 @@ class ExecuteTests : KernelServerTestsBase() {
48
57
} finally {
49
58
shell.close()
50
59
ioPub.close()
60
+ stdin.close()
51
61
context.term()
52
62
}
53
63
}
0 commit comments