Skip to content

Commit c8c7b83

Browse files
committed
bugfix
1 parent f74dbd4 commit c8c7b83

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

.github/workflows/release.yml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
run: |
2424
python -m pip install --upgrade pip
2525
pip install setuptools wheel twine poetry
26+
poetry lock --no-update
2627
poetry install
2728
2829
- name: Get the version from the tag

hmdriver2/_xpath.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __call__(self, xpath: str) -> '_XMLElement':
1919

2020
hierarchy: Dict = self._d.dump_hierarchy()
2121
if not hierarchy:
22-
raise XmlElementNotFoundError(f"xpath: {xpath} not found")
22+
raise RuntimeError("hierarchy is empty")
2323

2424
xml = _XPath._json2xml(hierarchy)
2525
result = xml.xpath(xpath)

hmdriver2/driver.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def set_display_rotation(self, rotation: DisplayRotation):
174174
Sets the display rotation to the specified orientation.
175175
176176
Args:
177-
rotation (DisplayRotation): The desired display rotation. This should be an instance of the DisplayRotation enum.
177+
rotation (DisplayRotation): display rotation.
178178
"""
179179
api = "Driver.setDisplayRotation"
180180
self._invoke(api, args=[rotation.value])
@@ -300,7 +300,8 @@ def swipe(self, x1, y1, x2, y2, speed=2000):
300300
y1 (float): The start Y coordinate as a percentage or absolute value.
301301
x2 (float): The end X coordinate as a percentage or absolute value.
302302
y2 (float): The end Y coordinate as a percentage or absolute value.
303-
speed (int, optional): The swipe speed in pixels per second. Default is 2000. Range: 200-40000. If not within the range, set to default value of 2000.
303+
speed (int, optional): The swipe speed in pixels per second. Default is 2000. Range: 200-40000,
304+
If not within the range, set to default value of 2000.
304305
"""
305306

306307
point1 = self._to_abs_pos(x1, y1)

hmdriver2/hdc.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def _execute_command(cmdargs: Union[str, List[str]]) -> CommandResult:
2929
error = error.decode('utf-8')
3030
exit_code = process.returncode
3131

32-
if output.lower().__contains__('error:'):
32+
if 'error:' in output.lower() or '[fail]:' in output.lower():
3333
return CommandResult("", output, -1)
3434

3535
return CommandResult(output, error, exit_code)
@@ -111,7 +111,8 @@ def uninstall(self, bundlename: str):
111111
return result
112112

113113
def install(self, apkpath: str):
114-
result = _execute_command(f"hdc -t {self.serial} install '{apkpath}'")
114+
quoted_path = shlex.quote(apkpath)
115+
result = _execute_command(f"hdc -t {self.serial} install {quoted_path}")
115116
if result.exit_code != 0:
116117
raise HdcError("HDC install error", result.error)
117118
return result
@@ -254,7 +255,7 @@ def dump_hierarchy(self) -> Dict:
254255
self.recv_file(_tmp_path, path)
255256

256257
try:
257-
with open(path, 'r') as file:
258+
with open(path, 'r', encoding='utf8') as file:
258259
data = json.load(file)
259260
except Exception as e:
260261
logger.error(f"Error loading JSON file: {e}")

0 commit comments

Comments
 (0)