-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathconftest.py
49 lines (37 loc) · 1.2 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import json
import subprocess
from pathlib import Path
import pytest
from websockets import serve # type: ignore
from ypy_websocket import WebsocketServer
# workaround until these PRs are merged:
# - https://github.com/yjs/y-websocket/pull/104
def update_json_file(path: Path, d: dict):
with open(path, "rb") as f:
package_json = json.load(f)
package_json.update(d)
with open(path, "w") as f:
json.dump(package_json, f, indent=2)
here = Path(__file__).parent
d = {"type": "module"}
update_json_file(here.parent / "node_modules/y-websocket/package.json", d)
@pytest.fixture
async def yws_server(request):
try:
kwargs = request.param
except Exception:
kwargs = {}
websocket_server = WebsocketServer(**kwargs)
try:
async with websocket_server, serve(websocket_server.serve, "localhost", 1234):
yield websocket_server
except Exception:
pass
@pytest.fixture
def yjs_client(request):
client_id = request.param
p = subprocess.Popen(f"yarn node {here / 'yjs_client_'}{client_id}.js", shell=True)
yield p
p.kill()