File tree Expand file tree Collapse file tree 5 files changed +100
-2
lines changed Expand file tree Collapse file tree 5 files changed +100
-2
lines changed Original file line number Diff line number Diff line change @@ -753,6 +753,9 @@ export class YCodeCell
753753 set outputs ( v : Array < nbformat . IOutput > ) {
754754 this . setOutputs ( v ) ;
755755 }
756+ get youtputs ( ) : Y . Array < any > {
757+ return this . _youtputs ;
758+ }
756759
757760 /**
758761 * Execution, display, or stream outputs.
Original file line number Diff line number Diff line change @@ -43,6 +43,10 @@ async def yws_server(request):
4343@pytest .fixture
4444def yjs_client (request ):
4545 client_id = request .param
46- p = subprocess .Popen (f"yarn node { here / 'yjs_client_' } { client_id } .js", shell = True )
46+ p = subprocess .Popen ([ " node" , f" { here / 'yjs_client_' } { client_id } .js"] )
4747 yield p
48- p .kill ()
48+ p .terminate ()
49+ try :
50+ p .wait (timeout = 10 )
51+ except Exception :
52+ p .kill ()
Original file line number Diff line number Diff line change 1+ {
2+ "cells" : [
3+ {
4+ "cell_type" : " code" ,
5+ "execution_count" : 1 ,
6+ "id" : " 4166c837-41c7-4ada-b86e-fd9a7720a409" ,
7+ "metadata" : {},
8+ "outputs" : [
9+ {
10+ "name" : " stdout" ,
11+ "output_type" : " stream" ,
12+ "text" : [
13+ " Hello,"
14+ ]
15+ }
16+ ],
17+ "source" : [
18+ " print(\" Hello,\" , end=\"\" )"
19+ ]
20+ }
21+ ],
22+ "metadata" : {
23+ "kernelspec" : {
24+ "display_name" : " Python 3 (ipykernel)" ,
25+ "language" : " python" ,
26+ "name" : " python3"
27+ },
28+ "language_info" : {
29+ "codemirror_mode" : {
30+ "name" : " ipython" ,
31+ "version" : 3
32+ },
33+ "file_extension" : " .py" ,
34+ "mimetype" : " text/x-python" ,
35+ "name" : " python" ,
36+ "nbconvert_exporter" : " python" ,
37+ "pygments_lexer" : " ipython3" ,
38+ "version" : " 3.12.3"
39+ }
40+ },
41+ "nbformat" : 4 ,
42+ "nbformat_minor" : 5
43+ }
Original file line number Diff line number Diff line change @@ -74,6 +74,31 @@ async def test_ypy_yjs_0(yws_server, yjs_client):
7474 assert ytest .source == nb
7575
7676
77+ @pytest .mark .asyncio
78+ @pytest .mark .parametrize ("yjs_client" , "1" , indirect = True )
79+ async def test_ypy_yjs_1 (yws_server , yjs_client ):
80+ ydoc = Doc ()
81+ ynotebook = YNotebook (ydoc )
82+ nb = stringify_source (json .loads ((files_dir / "nb1.ipynb" ).read_text ()))
83+ ynotebook .source = nb
84+ async with connect ("ws://localhost:1234/my-roomname" ) as websocket , WebsocketProvider (
85+ ydoc , websocket
86+ ):
87+ output_text = ynotebook .ycells [0 ]["outputs" ][0 ]["text" ]
88+ assert output_text .to_py () == ["Hello," ]
89+ event = Event ()
90+
91+ def callback (_event ):
92+ event .set ()
93+
94+ output_text .observe (callback )
95+
96+ with move_on_after (10 ):
97+ await event .wait ()
98+
99+ assert output_text .to_py () == ["Hello," , " World!" ]
100+
101+
77102def test_plotly_renderer ():
78103 """This test checks in particular that the type cast is not breaking the data."""
79104 ydoc = Doc ()
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) Jupyter Development Team.
3+ * Distributed under the terms of the Modified BSD License.
4+ */
5+
6+ import { YNotebook } from '@jupyter/ydoc'
7+ import { WebsocketProvider } from 'y-websocket'
8+ import ws from 'ws'
9+
10+ const notebook = new YNotebook ( )
11+
12+ const wsProvider = new WebsocketProvider (
13+ 'ws://localhost:1234' , 'my-roomname' ,
14+ notebook . ydoc ,
15+ { WebSocketPolyfill : ws }
16+ )
17+
18+ wsProvider . on ( 'sync' , ( isSynced ) => {
19+ const cell = notebook . getCell ( 0 )
20+ const youtput = cell . youtputs . get ( 0 )
21+ const text = youtput . get ( 'text' )
22+ text . insert ( 1 , [ ' World!' ] )
23+ } )
You can’t perform that action at this time.
0 commit comments