File tree Expand file tree Collapse file tree 3 files changed +66
-1
lines changed Expand file tree Collapse file tree 3 files changed +66
-1
lines changed Original file line number Diff line number Diff line change 77from .yblob import YBlob as YBlob
88from .yfile import YFile as YFile
99from .ynotebook import YNotebook as YNotebook
10+ from .ystdin import add_stdin as add_stdin
1011from .yunicode import YUnicode as YUnicode
1112
1213# See compatibility note on `group` keyword in
Original file line number Diff line number Diff line change 1+ from pycrdt import Map , Text
2+
3+
4+ def add_stdin (cell : Map , prompt : str = "" , password : bool = False ) -> None :
5+ """
6+ Adds an stdin Map in the cell outputs.
7+
8+ Schema:
9+
10+ .. code-block:: json
11+
12+ {
13+ "state": Map[
14+ "pending": bool,
15+ "password": bool
16+ ],
17+ "prompt": str,
18+ "input": Text
19+ }
20+ """
21+ stdin = Map (
22+ {
23+ "output_type" : "stdin" ,
24+ "state" : {
25+ "pending" : True ,
26+ "password" : password ,
27+ },
28+ "prompt" : prompt ,
29+ "input" : Text (),
30+ }
31+ )
32+ outputs = cell .get ("outputs" )
33+ outputs .append (stdin )
Original file line number Diff line number Diff line change 11# Copyright (c) Jupyter Development Team.
22# Distributed under the terms of the Modified BSD License.
33
4- from jupyter_ydoc import YBlob
4+ from jupyter_ydoc import YBlob , YNotebook , add_stdin
55
66
77def test_yblob ():
@@ -22,3 +22,34 @@ def callback(topic, event):
2222 assert topic == "source"
2323 assert event .keys ["bytes" ]["oldValue" ] == b"012"
2424 assert event .keys ["bytes" ]["newValue" ] == b"345"
25+
26+
27+ def test_stdin ():
28+ ynotebook = YNotebook ()
29+ ynotebook .append_cell (
30+ {
31+ "cell_type" : "code" ,
32+ "source" : "" ,
33+ }
34+ )
35+ ycell = ynotebook .ycells [0 ]
36+ add_stdin (ycell )
37+ cell = ycell .to_py ()
38+ # cell ID is random, ignore that
39+ del cell ["id" ]
40+ assert cell == {
41+ "outputs" : [
42+ {
43+ "output_type" : "stdin" ,
44+ "input" : "" ,
45+ "prompt" : "" ,
46+ "state" : {
47+ "password" : False ,
48+ "pending" : True ,
49+ },
50+ }
51+ ],
52+ "source" : "" ,
53+ "metadata" : {},
54+ "cell_type" : "code" ,
55+ }
You can’t perform that action at this time.
0 commit comments