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

enable aconfig flags: fix lint and formatting #94

Merged
merged 2 commits into from
Dec 20, 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
22 changes: 7 additions & 15 deletions avatar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ def normalize(a: Any) -> Any:
return wrapper


def enableFlag(flag):
""" Enable aconfig flag.
def enableFlag(flag: str) -> Callable[..., Any]:
"""Enable aconfig flag.

Requires that the test class declares a devices: Optional[PandoraDevices] attribute.

Expand All @@ -220,28 +220,20 @@ def enableFlag(flag):
TypeError: when the provided flag argument is not a string
"""

def decorator(func):

def decorator(func: Callable[..., Any]) -> Callable[..., Any]:
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
def wrapper(self: base_test.BaseTestClass, *args: Any, **kwargs: Any) -> Any:
devices = getattr(self, 'devices', None)

if not devices:
raise AttributeError(
"Attribute 'devices' not found in test class or is None")
raise AttributeError("Attribute 'devices' not found in test class or is None")

if not isinstance(devices, PandoraDevices):
raise TypeError(
"devices attribute must be of a PandoraDevices type")

if not isinstance(flag, str):
raise TypeError("flag must be a string")
raise TypeError("devices attribute must be of a PandoraDevices type")

for server in devices._servers:
if isinstance(server, pandora_server.AndroidPandoraServer):
server.device.adb.shell(
['device_config override bluetooth', flag,
'true']) # type: ignore
server.device.adb.shell(['device_config override bluetooth', flag, 'true']) # type: ignore
break
return func(self, *args, **kwargs)

Expand Down
3 changes: 1 addition & 2 deletions avatar/metrics/interceptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ def aio_interceptors(device: PandoraClient) -> Sequence[grpc.aio.ClientIntercept


class UnaryOutcome(Protocol, Generic[_T_co]):
def result(self) -> _T_co:
...
def result(self) -> _T_co: ...


class UnaryUnaryInterceptor(grpc.UnaryUnaryClientInterceptor): # type: ignore[misc]
Expand Down
45 changes: 28 additions & 17 deletions avatar/metrics/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ def setup_test(self: BaseTestClass) -> None:


class AsTrace(Protocol):
def as_trace(self) -> TracePacket:
...
def as_trace(self) -> TracePacket: ...


class Callsite(AsTrace):
Expand Down Expand Up @@ -156,11 +155,15 @@ def as_trace(self) -> TracePacket:
name=self.name,
type=TrackEvent.Type.TYPE_SLICE_BEGIN,
track_uuid=devices_id[self.device],
debug_annotations=None
if self.message is None
else [
DebugAnnotation(name=self.message.__class__.__name__, dict_entries=debug_message(self.message)[1])
],
debug_annotations=(
None
if self.message is None
else [
DebugAnnotation(
name=self.message.__class__.__name__, dict_entries=debug_message(self.message)[1]
)
]
),
),
trusted_packet_sequence_id=devices_process_id[self.device],
)
Expand All @@ -184,11 +187,15 @@ def as_trace(self) -> TracePacket:
name=self.callsite.name,
type=TrackEvent.Type.TYPE_INSTANT,
track_uuid=devices_id[self.callsite.device],
debug_annotations=None
if self.message is None
else [
DebugAnnotation(name=self.message.__class__.__name__, dict_entries=debug_message(self.message)[1])
],
debug_annotations=(
None
if self.message is None
else [
DebugAnnotation(
name=self.message.__class__.__name__, dict_entries=debug_message(self.message)[1]
)
]
),
),
trusted_packet_sequence_id=devices_process_id[self.callsite.device],
)
Expand Down Expand Up @@ -228,11 +235,15 @@ def as_trace(self) -> TracePacket:
name=self.callsite.name,
type=TrackEvent.Type.TYPE_SLICE_END,
track_uuid=devices_id[self.callsite.device],
debug_annotations=None
if self.message is None
else [
DebugAnnotation(name=self.message.__class__.__name__, dict_entries=debug_message(self.message)[1])
],
debug_annotations=(
None
if self.message is None
else [
DebugAnnotation(
name=self.message.__class__.__name__, dict_entries=debug_message(self.message)[1]
)
]
),
),
trusted_packet_sequence_id=devices_process_id[self.callsite.device],
)
Expand Down
1 change: 1 addition & 0 deletions avatar/metrics/trace_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class TrackEvent(_message.Message):
TYPE_SLICE_END: _ClassVar[TrackEvent.Type]
TYPE_INSTANT: _ClassVar[TrackEvent.Type]
TYPE_COUNTER: _ClassVar[TrackEvent.Type]

TYPE_UNSPECIFIED: TrackEvent.Type
TYPE_SLICE_BEGIN: TrackEvent.Type
TYPE_SLICE_END: TrackEvent.Type
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dev = [
"grpcio-tools>=1.62.1",
"pyright==1.1.298",
"mypy==1.5.1",
"black==23.7.0",
"black==24.10.0",
"isort==5.12.0",
"types-psutil==5.9.5.16",
"types-setuptools==68.1.0.1",
Expand Down
Loading