Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add codecov, fix coveragerc #106

Merged
merged 4 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
[run]
branch = true
omit =
tests/*
test_real_device/*
docs/*
setup.py
build_wheel.py


[report]
# Regexes for lines to exclude from consideration
; Regexes for lines to exclude from consideration
exclude_also =
# Don't complain about missing debug-only code:
"def __repr__",
"if self\\.debug",
; Don't complain about missing debug-only code:
def __repr__
if self\.debug

# Don't complain if tests don't hit defensive assertion code:
"raise AssertionError",
"raise NotImplementedError",
; Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError

# Don't complain if non-runnable code isn't run:
"if 0:",
"if __name__ == .__main__.:",
; Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:

# Don't complain about abstract methods, they aren't run:
"@(abc\\.)?abstractmethod",
; Don't complain about abstract methods, they aren't run:
@(abc\.)?abstractmethod

ignore_errors = true
omit =
"tests/*",
"docs/*"
ignore_errors = True
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# adbutils
[![PyPI](https://img.shields.io/pypi/v/adbutils.svg?color=blue)](https://pypi.org/project/adbutils/#history)
[![codecov](https://codecov.io/gh/openatx/adbutils/graph/badge.svg?token=OuGOMZUkmi)](https://codecov.io/gh/openatx/adbutils)

Python adb library for adb service (Only support Python3.6+)
Python adb library for adb service (Only support Python3.6+), Recommend 3.8+

**Table of Contents**

Expand Down Expand Up @@ -522,7 +523,7 @@ gh-md-toc --insert README.md
# Thanks
- [swind pure-python-adb](https://github.com/Swind/pure-python-adb)
- [openstf/adbkit](https://github.com/openstf/adbkit)
- [ADB Source Code](https://github.com/aosp-mirror/platform_system_core/blob/master/adb)
- [ADB Source Code](https://android.googlesource.com/platform/system/core/+/android-4.4_r1/adb/adb.c)
- ADB Protocols [OVERVIEW.TXT](https://cs.android.com/android/platform/superproject/+/master:packages/modules/adb/OVERVIEW.TXT) [SERVICES.TXT](https://cs.android.com/android/platform/superproject/+/master:packages/modules/adb/SERVICES.TXT) [SYNC.TXT](https://cs.android.com/android/platform/superproject/+/master:packages/modules/adb/SYNC.TXT)
- [Awesome ADB](https://github.com/mzlogin/awesome-adb)
- [JakeWharton/pidcat](https://github.com/JakeWharton/pidcat)
Expand Down
4 changes: 2 additions & 2 deletions adbutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
if not serial:
ds = self.device_list()
if len(ds) == 0:
raise RuntimeError("Can't find any android device/emulator")
raise AdbError("Can't find any android device/emulator")

Check warning on line 79 in adbutils/__init__.py

View check run for this annotation

Codecov / codecov/patch

adbutils/__init__.py#L79

Added line #L79 was not covered by tests
if len(ds) > 1:
raise RuntimeError(
raise AdbError(

Check warning on line 81 in adbutils/__init__.py

View check run for this annotation

Codecov / codecov/patch

adbutils/__init__.py#L81

Added line #L81 was not covered by tests
"more than one device/emulator, please specify the serial number"
)
return ds[0]
Expand Down
19 changes: 11 additions & 8 deletions adbutils/_adb.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
from deprecation import deprecated

from adbutils._utils import adb_path
from adbutils.errors import AdbError, AdbTimeout
from adbutils.errors import AdbConnectionError, AdbError, AdbTimeout

from adbutils._proto import *
from adbutils._utils import list2cmdline
from adbutils._version import __version__

_OKAY = "OKAY"
Expand All @@ -30,15 +29,15 @@
""" Returns if server is running """
s = socket.socket()
try:
s.settimeout(.1)
s.connect((host, port))
return True
except socket.error as e:
except (socket.timeout, socket.error) as e:
return False
finally:
s.close()



class AdbConnection(object):
def __init__(self, host: str, port: int):
self.__host = host
Expand All @@ -52,16 +51,20 @@
adb_port = self.__port
s = socket.socket()
try:
s.settimeout(.1) # prevent socket hang
s.connect((adb_host, adb_port))
s.settimeout(None)
return s
except:
s.close()
raise
except socket.timeout as e:
raise AdbTimeout("connect to adb server timeout")
except socket.error as e:
raise AdbConnectionError("connect to adb server failed: %s" % e)

Check warning on line 61 in adbutils/_adb.py

View check run for this annotation

Codecov / codecov/patch

adbutils/_adb.py#L59-L61

Added lines #L59 - L61 were not covered by tests


def _safe_connect(self):
try:
return self._create_socket()
except ConnectionRefusedError:
except AdbConnectionError:

Check warning on line 67 in adbutils/_adb.py

View check run for this annotation

Codecov / codecov/patch

adbutils/_adb.py#L67

Added line #L67 was not covered by tests
subprocess.run([adb_path(), "start-server"], timeout=20.0) # 20s should enough for adb start
return self._create_socket()

Expand Down
6 changes: 3 additions & 3 deletions adbutils/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
elif self._serial:
c.send_command(f"host-serial:{self._serial}:{command}")
else:
raise RuntimeError
raise RuntimeError("should not reach here")

Check warning on line 100 in adbutils/_device.py

View check run for this annotation

Codecov / codecov/patch

adbutils/_device.py#L100

Added line #L100 was not covered by tests
c.check_okay()
else:
if self._transport_id:
Expand All @@ -108,7 +108,7 @@
# so here use host:transport
c.send_command(f"host:transport:{self._serial}")
else:
raise RuntimeError
raise RuntimeError("should not reach here")

Check warning on line 111 in adbutils/_device.py

View check run for this annotation

Codecov / codecov/patch

adbutils/_device.py#L111

Added line #L111 was not covered by tests
c.check_okay()
return c

Expand Down Expand Up @@ -575,7 +575,7 @@
chunk_size = struct.unpack("<I", c.read(4))[0]
chunk = c.read(chunk_size)
if len(chunk) != chunk_size:
raise RuntimeError("read chunk missing")
raise AdbError("read chunk missing")

Check warning on line 578 in adbutils/_device.py

View check run for this annotation

Codecov / codecov/patch

adbutils/_device.py#L578

Added line #L578 was not covered by tests
yield chunk
else:
raise AdbError("Invalid sync cmd", cmd)
Expand Down
2 changes: 1 addition & 1 deletion adbutils/_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

__all__ = [
"Network", "DeviceEvent", "ForwardItem", "ReverseItem", "FileInfo",
"WindowSize", "RunningAppInfo", "ShellReturn", "AdbDeviceInfo"
"WindowSize", "RunningAppInfo", "ShellReturn", "AdbDeviceInfo", "AppInfo"
]

import enum
Expand Down
10 changes: 6 additions & 4 deletions adbutils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
import typing
import pathlib

import whichcraft
from shutil import which
from apkutils2.axml.axmlparser import AXML
from apkutils2.manifest import Manifest

from adbutils.errors import AdbError


MB = 1024 * 1024

Expand Down Expand Up @@ -52,7 +54,7 @@
port = random.randint(10000, 20000)
if not is_port_in_use(port):
return port
raise RuntimeError("No free port found")
raise AdbError("No free port found")

Check warning on line 57 in adbutils/_utils.py

View check run for this annotation

Codecov / codecov/patch

adbutils/_utils.py#L57

Added line #L57 was not covered by tests


def list2cmdline(args: typing.Union[list, tuple]):
Expand Down Expand Up @@ -93,7 +95,7 @@
return os.getenv("ADBUTILS_ADB_PATH")

# 1. find in $PATH
exe = whichcraft.which("adb")
exe = which("adb")

Check warning on line 98 in adbutils/_utils.py

View check run for this annotation

Codecov / codecov/patch

adbutils/_utils.py#L98

Added line #L98 was not covered by tests
if exe and _is_valid_exe(exe):
return exe

Expand All @@ -103,7 +105,7 @@
if os.path.isfile(exe) and _is_valid_exe(exe):
return exe

raise RuntimeError("No adb exe could be found. Install adb on your system")
raise AdbError("No adb exe could be found. Install adb on your system")

Check warning on line 108 in adbutils/_utils.py

View check run for this annotation

Codecov / codecov/patch

adbutils/_utils.py#L108

Added line #L108 was not covered by tests


def _popen_kwargs(prevent_sigint=False):
Expand Down
4 changes: 4 additions & 0 deletions adbutils/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class AdbTimeout(AdbError):
""" timeout when communicate to adb-server """


class AdbConnectionError(AdbError):
""" connection error """


class AdbInstallError(AdbError):
def __init__(self, output: str):
"""
Expand Down
1 change: 0 additions & 1 deletion adbutils/pidcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import argparse
import sys
import re
import subprocess
from subprocess import PIPE

import adbutils
Expand Down
58 changes: 0 additions & 58 deletions adbutils/server/__init__.py

This file was deleted.

2 changes: 2 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
codecov:
token: 59cb8341-87db-45bd-b828-e8ae19cd4062
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
whichcraft
requests
deprecation>=2.0.6,<3.0
retry>=0.9
Expand Down
Loading
Loading