Skip to content

Commit 34d0bca

Browse files
committed
test(binding): 添加 Controller.resolution 属性的单元测试
1 parent 7fae994 commit 34d0bca

2 files changed

Lines changed: 29 additions & 8 deletions

File tree

test/agent/agent_child_test.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,17 @@ def analyze(
110110

111111
# 测试 get_node_data (Context 级别)
112112
node_data = new_ctx.get_node_data(argv.node_name)
113-
print(f" ctx.get_node_data keys: {list(node_data.keys()) if node_data else None}")
113+
print(
114+
f" ctx.get_node_data keys: {list(node_data.keys()) if node_data else None}"
115+
)
114116

115117
# 测试 anchor API
116118
new_ctx.set_anchor("test_anchor", "TaskA")
117119
anchor_result = new_ctx.get_anchor("test_anchor")
118120
print(f" anchor_result: {anchor_result}")
119-
assert anchor_result == "TaskA", f"anchor should be 'TaskA', got {anchor_result}"
121+
assert (
122+
anchor_result == "TaskA"
123+
), f"anchor should be 'TaskA', got {anchor_result}"
120124

121125
# 测试 hit count API
122126
hit_count = new_ctx.get_hit_count(argv.node_name)
@@ -218,6 +222,12 @@ def run(
218222
cached_image = controller.cached_image
219223
print(f" cached_image shape: {cached_image.shape}")
220224

225+
# 测试 resolution (需要在首次截图后才能获取有效值)
226+
resolution = controller.resolution
227+
print(f" resolution: {resolution}")
228+
assert isinstance(resolution, tuple), "resolution should be a tuple"
229+
assert len(resolution) == 2, "resolution should have 2 elements"
230+
221231
# 测试基本输入操作
222232
controller.post_click(191, 98).wait()
223233
controller.post_swipe(100, 200, 300, 400, 100).wait()
@@ -250,7 +260,9 @@ def run(
250260
task_detail = task_job.get()
251261

252262
if task_detail:
253-
print(f" task_detail: entry={task_detail.entry}, status={task_detail.status}")
263+
print(
264+
f" task_detail: entry={task_detail.entry}, status={task_detail.status}"
265+
)
254266

255267
# 测试 get_task_detail
256268
fetched_task_detail = tasker.get_task_detail(task_detail.task_id)
@@ -262,13 +274,13 @@ def run(
262274
if task_detail.nodes:
263275
node = task_detail.nodes[0]
264276
node_detail = tasker.get_node_detail(node.node_id)
265-
print(
266-
f" get_node_detail: {node_detail.name if node_detail else None}"
267-
)
277+
print(f" get_node_detail: {node_detail.name if node_detail else None}")
268278

269279
# 测试 get_recognition_detail
270280
if node.recognition:
271-
reco_detail = tasker.get_recognition_detail(node.recognition.reco_id)
281+
reco_detail = tasker.get_recognition_detail(
282+
node.recognition.reco_id
283+
)
272284
print(
273285
f" get_recognition_detail: {reco_detail.name if reco_detail else None}"
274286
)

test/python/binding_test.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ def run(
190190
cached_image = controller.cached_image
191191
connected = controller.connected
192192
uuid = controller.uuid
193-
print(f" connected: {connected}, uuid: {uuid}")
193+
resolution = controller.resolution
194+
print(f" connected: {connected}, uuid: {uuid}, resolution: {resolution}")
194195

195196
global runned
196197
runned = True
@@ -335,6 +336,14 @@ def test_controller_api():
335336
cached = dbg_controller.cached_image
336337
print(f" cached_image shape: {cached.shape}")
337338

339+
# 测试 resolution (需要在首次截图后才能获取有效值)
340+
resolution = dbg_controller.resolution
341+
print(f" resolution: {resolution}")
342+
assert isinstance(resolution, tuple), "resolution should be a tuple"
343+
assert len(resolution) == 2, "resolution should have 2 elements"
344+
assert isinstance(resolution[0], int), "resolution width should be int"
345+
assert isinstance(resolution[1], int), "resolution height should be int"
346+
338347
# 测试输入操作
339348
dbg_controller.post_click(100, 100).wait()
340349
dbg_controller.post_swipe(100, 100, 200, 200, 100).wait()

0 commit comments

Comments
 (0)