Skip to content

Commit 9f2c007

Browse files
committed
Add comprehensive unit tests for server functions in test_server.py
1 parent b5e3268 commit 9f2c007

File tree

5 files changed

+864
-10
lines changed

5 files changed

+864
-10
lines changed

pyproject.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ requires-python = ">=3.13"
77
dependencies = [
88
"asyncio>=3.4.3",
99
"mcp[cli]>=1.7.0",
10-
"uiautodev>=0.6.0",
10+
"uiautodev>=0.6.0", # This likely pins fastapi, which pins starlette < 0.38.0
1111
"uiautomator2>=3.2.9",
12+
"python-multipart>=0.0.9", # Already added
13+
# "starlette>=0.38.0", # This caused conflicts, so we revert this change
14+
]
15+
16+
[tool.pytest.ini_options]
17+
filterwarnings = [
18+
"ignore:Please use \\`import python_multipart\\` instead.:PendingDeprecationWarning:starlette\\.formparsers",
1219
]

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![Python 3.13](https://img.shields.io/badge/python-3.13-blue.svg)](https://www.python.org/downloads/)
22
[![PyPI](https://img.shields.io/pypi/v/uiautomator2.svg?label=uiautomator2)](https://pypi.python.org/pypi/uiautomator2)
33
[![PyPI](https://img.shields.io/pypi/v/adbutils.svg?label=adbutils)](https://github.com/openatx/adbutils)
4-
[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/openatx/android-uiautomator-server.svg?label=android-uiautomator-server)](https://github.com/openatx/android-uiautomator-server)
4+
[![Code style: ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
55
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
66

77
# MCP Android Agent

server.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# server.py
22
from mcp.server.fastmcp import FastMCP
33
import uiautomator2 as u2
4-
from typing import List, Optional, Dict, Any, Tuple
4+
from typing import List, Optional, Dict, Any
55
import shutil
66
import subprocess
77
import asyncio
8-
from dataclasses import dataclass
98
from typing import TypedDict
109

1110
# Create an MCP server
@@ -358,7 +357,7 @@ def click(
358357
else:
359358
raise ValueError(f"Invalid selector_type: {selector_type}")
360359

361-
if el:
360+
if el and el.exists:
362361
el.click()
363362
return True
364363
return False
@@ -423,7 +422,7 @@ def get_element_info(
423422
else:
424423
raise ValueError(f"Invalid selector_type: {selector_type}")
425424

426-
if el:
425+
if el and el.exists:
427426
info = el.info
428427
return {
429428
"text": info.get("text", ""),
@@ -500,7 +499,8 @@ def wait_for_element(
500499
elif selector_type == "resourceId":
501500
return d(resourceId=selector).wait(timeout=timeout)
502501
elif selector_type == "description":
503-
return d(description=selector).wait(timeout=timeout)
502+
el = d(description=selector).wait(timeout=timeout)
503+
return el is not None and el.exists
504504
else:
505505
raise ValueError(f"Invalid selector_type: {selector_type}")
506506
except Exception as e:
@@ -559,7 +559,7 @@ def long_click(
559559
else:
560560
raise ValueError(f"Invalid selector_type: {selector_type}")
561561

562-
if el.exists:
562+
if el and el.exists:
563563
el.long_click(duration=duration)
564564
return True
565565
return False
@@ -589,7 +589,8 @@ def scroll_to(
589589
elif selector_type == "resourceId":
590590
return d(scrollable=True).scroll.to(resourceId=selector)
591591
elif selector_type == "description":
592-
return d(scrollable=True).scroll.to(description=selector)
592+
el = d(scrollable=True).scroll.to(description=selector)
593+
return el is not None and el.exists
593594
else:
594595
raise ValueError(f"Invalid selector_type: {selector_type}")
595596
except Exception as e:
@@ -628,7 +629,7 @@ def drag(
628629
else:
629630
raise ValueError(f"Invalid selector_type: {selector_type}")
630631

631-
if el.exists:
632+
if el and el.exists:
632633
el.drag_to(to_x, to_y)
633634
return True
634635
return False

tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)