From 5409880a65a677a2bed6513241ebe3cab2e25f89 Mon Sep 17 00:00:00 2001 From: Jakub Rotkiewicz Date: Fri, 20 Dec 2024 07:58:46 -0800 Subject: [PATCH] enable aconfig flags: fix lint and formatting (#94) Bug: 372300895 --- avatar/__init__.py | 22 ++++++----------- avatar/metrics/interceptors.py | 3 +-- avatar/metrics/trace.py | 45 +++++++++++++++++++++------------- avatar/metrics/trace_pb2.pyi | 1 + pyproject.toml | 2 +- 5 files changed, 38 insertions(+), 35 deletions(-) diff --git a/avatar/__init__.py b/avatar/__init__.py index 1f639ea..b1e118d 100644 --- a/avatar/__init__.py +++ b/avatar/__init__.py @@ -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. @@ -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) diff --git a/avatar/metrics/interceptors.py b/avatar/metrics/interceptors.py index 3ac7da1..019a4a2 100644 --- a/avatar/metrics/interceptors.py +++ b/avatar/metrics/interceptors.py @@ -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] diff --git a/avatar/metrics/trace.py b/avatar/metrics/trace.py index 86bc21a..96caa6f 100644 --- a/avatar/metrics/trace.py +++ b/avatar/metrics/trace.py @@ -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): @@ -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], ) @@ -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], ) @@ -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], ) diff --git a/avatar/metrics/trace_pb2.pyi b/avatar/metrics/trace_pb2.pyi index fcfac67..009da07 100644 --- a/avatar/metrics/trace_pb2.pyi +++ b/avatar/metrics/trace_pb2.pyi @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 75665fb..ab89e0f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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",