-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathtest_duplex.py
48 lines (37 loc) · 1.37 KB
/
test_duplex.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
import pytest
from pathlib import Path
from blendtorch import btt
BLENDDIR = Path(__file__).parent / "blender"
#@pytest.mark.background
def test_duplex():
launch_args = dict(
scene="",
script=BLENDDIR / "duplex.blend.py",
num_instances=2,
named_sockets=["CTRL"],
background=True,
)
with btt.BlenderLauncher(**launch_args) as bl:
addresses = bl.launch_info.addresses["CTRL"]
duplex = [btt.DuplexChannel(addr, lingerms=5000) for addr in addresses]
mids = [d.send(msg=f"hello {i}") for i, d in enumerate(duplex)]
def rcv_twice(d):
return [
d.recv(timeoutms=5000),
d.recv(timeoutms=5000),
]
msgs = [rcv_twice(d) for d in duplex]
assert len(msgs) == 2
assert len(msgs[0]) == 2
assert msgs[0][0]["echo"]["msg"] == "hello 0"
assert msgs[0][0]["echo"]["btid"] is None
assert msgs[0][0]["echo"]["btmid"] == mids[0]
assert msgs[0][0]["btid"] == 0
assert msgs[0][1]["msg"] == "end"
assert msgs[0][1]["btid"] == 0
assert msgs[1][0]["echo"]["msg"] == "hello 1"
assert msgs[1][0]["echo"]["btid"] is None
assert msgs[1][0]["echo"]["btmid"] == mids[1]
assert msgs[1][0]["btid"] == 1
assert msgs[1][1]["msg"] == "end"
assert msgs[1][1]["btid"] == 1