-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathtest_run_tests_async.py
More file actions
116 lines (85 loc) · 3.96 KB
/
test_run_tests_async.py
File metadata and controls
116 lines (85 loc) · 3.96 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import pytest
from .test_helpers import DummyContext
@pytest.mark.asyncio
async def test_run_tests_async_forwards_params(monkeypatch):
from services.tools.run_tests import run_tests
captured = {}
async def fake_send_with_unity_instance(send_fn, unity_instance, command_type, params, **kwargs):
captured["command_type"] = command_type
captured["params"] = params
return {"success": True, "data": {"job_id": "abc123", "status": "running", "mode": "EditMode"}}
import services.tools.run_tests as mod
monkeypatch.setattr(
mod.unity_transport, "send_with_unity_instance", fake_send_with_unity_instance)
resp = await run_tests(
DummyContext(),
mode="EditMode",
test_names="MyNamespace.MyTests.TestA",
include_details=True,
)
assert captured["command_type"] == "run_tests"
assert captured["params"]["mode"] == "EditMode"
assert captured["params"]["testNames"] == ["MyNamespace.MyTests.TestA"]
assert captured["params"]["includeDetails"] is True
assert resp.success is True
assert resp.data is not None
assert resp.data.job_id == "abc123"
@pytest.mark.asyncio
async def test_run_tests_forwards_init_timeout(monkeypatch):
from services.tools.run_tests import run_tests
captured = {}
async def fake_send_with_unity_instance(send_fn, unity_instance, command_type, params, **kwargs):
captured["params"] = params
return {"success": True, "data": {"job_id": "abc123", "status": "running", "mode": "PlayMode"}}
import services.tools.run_tests as mod
monkeypatch.setattr(
mod.unity_transport, "send_with_unity_instance", fake_send_with_unity_instance)
resp = await run_tests(
DummyContext(),
mode="PlayMode",
init_timeout=120000,
)
assert captured["params"]["initTimeout"] == 120000
assert resp.success is True
@pytest.mark.asyncio
async def test_run_tests_omits_init_timeout_when_none(monkeypatch):
from services.tools.run_tests import run_tests
captured = {}
async def fake_send_with_unity_instance(send_fn, unity_instance, command_type, params, **kwargs):
captured["params"] = params
return {"success": True, "data": {"job_id": "abc123", "status": "running", "mode": "EditMode"}}
import services.tools.run_tests as mod
monkeypatch.setattr(
mod.unity_transport, "send_with_unity_instance", fake_send_with_unity_instance)
resp = await run_tests(DummyContext(), mode="EditMode")
assert "initTimeout" not in captured["params"]
assert resp.success is True
@pytest.mark.asyncio
async def test_run_tests_rejects_negative_init_timeout():
from services.tools.run_tests import run_tests
resp = await run_tests(DummyContext(), mode="EditMode", init_timeout=-1)
assert resp.success is False
assert "init_timeout" in resp.error
@pytest.mark.asyncio
async def test_run_tests_rejects_zero_init_timeout():
from services.tools.run_tests import run_tests
resp = await run_tests(DummyContext(), mode="EditMode", init_timeout=0)
assert resp.success is False
assert "init_timeout" in resp.error
@pytest.mark.asyncio
async def test_get_test_job_forwards_job_id(monkeypatch):
from services.tools.run_tests import get_test_job
captured = {}
async def fake_send_with_unity_instance(send_fn, unity_instance, command_type, params, **kwargs):
captured["command_type"] = command_type
captured["params"] = params
return {"success": True, "data": {"job_id": params["job_id"], "status": "running", "mode": "EditMode"}}
import services.tools.run_tests as mod
monkeypatch.setattr(
mod.unity_transport, "send_with_unity_instance", fake_send_with_unity_instance)
resp = await get_test_job(DummyContext(), job_id="job-1")
assert captured["command_type"] == "get_test_job"
assert captured["params"]["job_id"] == "job-1"
assert resp.success is True
assert resp.data is not None
assert resp.data.job_id == "job-1"